fix(lightrag): 修复只有实体没有关系的chunk处理逻辑
- 只有实体没有关系时,继续处理,而不是直接return - 当只有实体而没有关系的图片在高阶查询关系时会返回空,这里优化返回,当没有关系时降级为local查询
This commit is contained in:
parent
11d8440393
commit
58c0f94346
1 changed files with 15 additions and 6 deletions
|
|
@ -412,15 +412,17 @@ async def extract_entities(
|
|||
):
|
||||
all_relationships_data.append(await result)
|
||||
|
||||
if not len(all_entities_data):
|
||||
logger.warning("Didn't extract any entities, maybe your LLM is not working")
|
||||
return None
|
||||
if not len(all_relationships_data):
|
||||
if not len(all_entities_data) and not len(all_relationships_data):
|
||||
logger.warning(
|
||||
"Didn't extract any relationships, maybe your LLM is not working"
|
||||
"Didn't extract any entities or relationships, maybe your LLM is not working"
|
||||
)
|
||||
return None
|
||||
|
||||
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 entity_vdb is not None:
|
||||
data_for_vdb = {
|
||||
compute_mdhash_id(dp["entity_name"], prefix="ent-"): {
|
||||
|
|
@ -630,6 +632,13 @@ async def _build_query_context(
|
|||
text_chunks_db,
|
||||
query_param,
|
||||
)
|
||||
if (
|
||||
hl_entities_context == ""
|
||||
and hl_relations_context == ""
|
||||
and hl_text_units_context == ""
|
||||
):
|
||||
logger.warn("No high level context found. Switching to local mode.")
|
||||
query_param.mode = "local"
|
||||
if query_param.mode == "hybrid":
|
||||
entities_context, relations_context, text_units_context = combine_contexts(
|
||||
[hl_entities_context, ll_entities_context],
|
||||
|
|
@ -865,7 +874,7 @@ async def _get_edge_data(
|
|||
results = await relationships_vdb.query(keywords, top_k=query_param.top_k)
|
||||
|
||||
if not len(results):
|
||||
return None
|
||||
return "", "", ""
|
||||
|
||||
edge_datas = await asyncio.gather(
|
||||
*[knowledge_graph_inst.get_edge(r["src_id"], r["tgt_id"]) for r in results]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue