Skip to content

Commit

Permalink
Merge pull request #900 from YanSte/cleanup-3
Browse files Browse the repository at this point in the history
Database Cleanup
  • Loading branch information
YanSte authored Feb 20, 2025
2 parents 679096b + c4562f7 commit 0d4c580
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/test_faiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def main():
),
vector_storage="FaissVectorDBStorage",
vector_db_storage_cls_kwargs={
"cosine_better_than_threshold": 0.3 # Your desired threshold
"cosine_better_than_threshold": 0.2 # Your desired threshold
},
)

Expand Down
2 changes: 1 addition & 1 deletion lightrag/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam

__version__ = "1.1.7"
__version__ = "1.1.10"
__author__ = "Zirui Guo"
__url__ = "https://github.com/HKUDS/LightRAG"
3 changes: 2 additions & 1 deletion lightrag/kg/networkx_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

if not pm.is_installed("networkx"):
pm.install("networkx")

if not pm.is_installed("graspologic"):
pm.install("graspologic")

from graspologic import embed
import networkx as nx
from graspologic import embed


@final
Expand Down
11 changes: 2 additions & 9 deletions lightrag/lightrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class LightRAG:
"""Maximum number of concurrent embedding function calls."""

embedding_cache_config: dict[str, Any] = field(
default={
default_factory=lambda: {
"enabled": False,
"similarity_threshold": 0.95,
"use_llm_check": False,
Expand Down Expand Up @@ -727,21 +727,14 @@ async def batch(

async def _process_entity_relation_graph(self, chunk: dict[str, Any]) -> None:
try:
new_kg = await extract_entities(
await extract_entities(
chunk,
knowledge_graph_inst=self.chunk_entity_relation_graph,
entity_vdb=self.entities_vdb,
relationships_vdb=self.relationships_vdb,
llm_response_cache=self.llm_response_cache,
global_config=asdict(self),
)
if new_kg is None:
logger.info("No new entities or relationships extracted.")
else:
async with self._entity_lock:
logger.info("New entities or relationships extracted.")
self.chunk_entity_relation_graph = new_kg

except Exception as e:
logger.error("Failed to extract entities and relationships")
raise e
Expand Down
24 changes: 12 additions & 12 deletions lightrag/operate.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async def extract_entities(
relationships_vdb: BaseVectorStorage,
global_config: dict[str, str],
llm_response_cache: BaseKVStorage | None = None,
) -> BaseGraphStorage | None:
) -> None:
use_llm_func: callable = global_config["llm_model_func"]
entity_extract_max_gleaning = global_config["entity_extract_max_gleaning"]
enable_llm_cache_for_entity_extract: bool = global_config[
Expand Down Expand Up @@ -522,16 +522,18 @@ async def _process_single_content(chunk_key_dp: tuple[str, TextChunkSchema]):
]
)

if not len(all_entities_data) and not len(all_relationships_data):
logger.warning(
"Didn't extract any entities and relationships, maybe your LLM is not working"
)
return None
if not (all_entities_data or all_relationships_data):
logger.info("Didn't extract any entities and relationships.")
return

if not len(all_entities_data):
logger.warning("Didn't extract any entities")
if not len(all_relationships_data):
logger.warning("Didn't extract any relationships")
if not all_entities_data:
logger.info("Didn't extract any entities")
if not all_relationships_data:
logger.info("Didn't extract any relationships")

logger.info(
f"New entities or relationships extracted, entities:{all_entities_data}, relationships:{all_relationships_data}"
)

if entity_vdb is not None:
data_for_vdb = {
Expand Down Expand Up @@ -560,8 +562,6 @@ async def _process_single_content(chunk_key_dp: tuple[str, TextChunkSchema]):
}
await relationships_vdb.upsert(data_for_vdb)

return knowledge_graph_inst


async def kg_query(
query: str,
Expand Down

0 comments on commit 0d4c580

Please sign in to comment.