Skip to content

Commit

Permalink
chore: add warning for no new entities (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
gusye1234 committed Aug 21, 2024
1 parent acf66de commit 0db1d5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion nano_graphrag/_op.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import json
import re
from typing import Union
from collections import Counter, defaultdict

from openai import AsyncOpenAI
Expand Down Expand Up @@ -223,7 +224,7 @@ async def extract_entities(
knwoledge_graph_inst: BaseGraphStorage,
entity_vdb: BaseVectorStorage,
global_config: dict,
) -> BaseGraphStorage:
) -> Union[BaseGraphStorage, None]:
use_llm_func: callable = global_config["best_model_func"]
entity_extract_max_gleaning = global_config["entity_extract_max_gleaning"]

Expand Down Expand Up @@ -325,6 +326,9 @@ async def _process_single_content(chunk_key_dp: tuple[str, TextChunkSchema]):
for k, v in maybe_edges.items()
]
)
if not len(all_entities_data):
logger.warning("Didn't extract any entities, maybe your LLM is not working")
return None
if entity_vdb is not None:
data_for_vdb = {
compute_mdhash_id(dp["entity_name"], prefix="ent-"): {
Expand Down
3 changes: 3 additions & 0 deletions nano_graphrag/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def __post_init__(self):

async def upsert(self, data: dict[str, dict]):
logger.info(f"Inserting {len(data)} vectors to {self.namespace}")
if not len(data):
logger.warning("You insert an empty data to vector DB")
return []
list_data = [
{
"__id__": k,
Expand Down
7 changes: 5 additions & 2 deletions nano_graphrag/graphrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,16 @@ async def ainsert(self, string_or_strings):

# ---------- extract/summary entity and upsert to graph
logger.info("[Entity Extraction]...")
self.chunk_entity_relation_graph = await extract_entities(
maybe_new_kg = await extract_entities(
inserting_chunks,
knwoledge_graph_inst=self.chunk_entity_relation_graph,
entity_vdb=self.entities_vdb,
global_config=asdict(self),
)

if maybe_new_kg is None:
logger.warning("No new entities found")
return
self.chunk_entity_relation_graph = maybe_new_kg
# ---------- update clusterings of graph
logger.info("[Community Report]...")
await self.chunk_entity_relation_graph.clustering(
Expand Down

0 comments on commit 0db1d5b

Please sign in to comment.