Skip to content

Commit

Permalink
Merge pull request #318 from zzzcccxx/main
Browse files Browse the repository at this point in the history
fix: 修改了local search中的relation_counts计数规则
  • Loading branch information
LarFii authored Nov 22, 2024
2 parents b267f30 + 116e1d2 commit 8b4da85
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lightrag/operate.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,24 +578,20 @@ async def _find_most_related_text_unit_from_entities(
all_text_units_lookup = {}
for index, (this_text_units, this_edges) in enumerate(zip(text_units, edges)):
for c_id in this_text_units:
if c_id in all_text_units_lookup:
continue
relation_counts = 0
if this_edges: # Add check for None edges
if c_id not in all_text_units_lookup:
all_text_units_lookup[c_id] = {
"data": await text_chunks_db.get_by_id(c_id),
"order": index,
"relation_counts": 0,
}

if this_edges:
for e in this_edges:
if (
e[1] in all_one_hop_text_units_lookup
and c_id in all_one_hop_text_units_lookup[e[1]]
):
relation_counts += 1

chunk_data = await text_chunks_db.get_by_id(c_id)
if chunk_data is not None and "content" in chunk_data: # Add content check
all_text_units_lookup[c_id] = {
"data": chunk_data,
"order": index,
"relation_counts": relation_counts,
}
all_text_units_lookup[c_id]["relation_counts"] += 1

# Filter out None values and ensure data has content
all_text_units = [
Expand Down

0 comments on commit 8b4da85

Please sign in to comment.