From 116e1d20a9142c673bf70e15d430652a4a75be57 Mon Sep 17 00:00:00 2001 From: zzzcccxx <865637742@qq.com> Date: Thu, 21 Nov 2024 14:35:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86relation=5Fcounts?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lightrag/operate.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lightrag/operate.py b/lightrag/operate.py index eb600c4b..cf236633 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -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 = [