LarFii commited on
Commit
a8fb50f
·
1 Parent(s): 3c33e51

fix cache bug

Browse files
Files changed (3) hide show
  1. lightrag/__init__.py +1 -1
  2. lightrag/operate.py +18 -6
  3. lightrag/utils.py +12 -6
lightrag/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
  from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam
2
 
3
- __version__ = "1.0.0"
4
  __author__ = "Zirui Guo"
5
  __url__ = "https://github.com/HKUDS/LightRAG"
 
1
  from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam
2
 
3
+ __version__ = "1.0.1"
4
  __author__ = "Zirui Guo"
5
  __url__ = "https://github.com/HKUDS/LightRAG"
lightrag/operate.py CHANGED
@@ -630,10 +630,16 @@ async def _find_most_related_edges_from_entities(
630
  all_related_edges = await asyncio.gather(
631
  *[knowledge_graph_inst.get_node_edges(dp["entity_name"]) for dp in node_datas]
632
  )
633
- all_edges = set()
 
 
634
  for this_edges in all_related_edges:
635
- all_edges.update([tuple(sorted(e)) for e in this_edges])
636
- all_edges = list(all_edges)
 
 
 
 
637
  all_edges_pack = await asyncio.gather(
638
  *[knowledge_graph_inst.get_edge(e[0], e[1]) for e in all_edges]
639
  )
@@ -833,10 +839,16 @@ async def _find_most_related_entities_from_relationships(
833
  query_param: QueryParam,
834
  knowledge_graph_inst: BaseGraphStorage,
835
  ):
836
- entity_names = set()
 
 
837
  for e in edge_datas:
838
- entity_names.add(e["src_id"])
839
- entity_names.add(e["tgt_id"])
 
 
 
 
840
 
841
  node_datas = await asyncio.gather(
842
  *[knowledge_graph_inst.get_node(entity_name) for entity_name in entity_names]
 
630
  all_related_edges = await asyncio.gather(
631
  *[knowledge_graph_inst.get_node_edges(dp["entity_name"]) for dp in node_datas]
632
  )
633
+ all_edges = []
634
+ seen = set()
635
+
636
  for this_edges in all_related_edges:
637
+ for e in this_edges:
638
+ sorted_edge = tuple(sorted(e))
639
+ if sorted_edge not in seen:
640
+ seen.add(sorted_edge)
641
+ all_edges.append(sorted_edge)
642
+
643
  all_edges_pack = await asyncio.gather(
644
  *[knowledge_graph_inst.get_edge(e[0], e[1]) for e in all_edges]
645
  )
 
839
  query_param: QueryParam,
840
  knowledge_graph_inst: BaseGraphStorage,
841
  ):
842
+ entity_names = []
843
+ seen = set()
844
+
845
  for e in edge_datas:
846
+ if e["src_id"] not in seen:
847
+ entity_names.append(e["src_id"])
848
+ seen.add(e["src_id"])
849
+ if e["tgt_id"] not in seen:
850
+ entity_names.append(e["tgt_id"])
851
+ seen.add(e["tgt_id"])
852
 
853
  node_datas = await asyncio.gather(
854
  *[knowledge_graph_inst.get_node(entity_name) for entity_name in entity_names]
lightrag/utils.py CHANGED
@@ -274,13 +274,19 @@ def process_combine_contexts(hl, ll):
274
  if list_ll:
275
  list_ll = [",".join(item[1:]) for item in list_ll if item]
276
 
277
- combined_sources_set = set(filter(None, list_hl + list_ll))
 
278
 
279
- combined_sources = [",\t".join(header)]
 
 
 
280
 
281
- for i, item in enumerate(combined_sources_set, start=1):
282
- combined_sources.append(f"{i},\t{item}")
283
 
284
- combined_sources = "\n".join(combined_sources)
 
285
 
286
- return combined_sources
 
 
 
274
  if list_ll:
275
  list_ll = [",".join(item[1:]) for item in list_ll if item]
276
 
277
+ combined_sources = []
278
+ seen = set()
279
 
280
+ for item in list_hl + list_ll:
281
+ if item and item not in seen:
282
+ combined_sources.append(item)
283
+ seen.add(item)
284
 
285
+ combined_sources_result = [",\t".join(header)]
 
286
 
287
+ for i, item in enumerate(combined_sources, start=1):
288
+ combined_sources_result.append(f"{i},\t{item}")
289
 
290
+ combined_sources_result = "\n".join(combined_sources_result)
291
+
292
+ return combined_sources_result