LarFii commited on
Commit
f020a9c
·
1 Parent(s): 275e33e

fix delete_by_doc_id

Browse files
Files changed (1) hide show
  1. lightrag/lightrag.py +11 -5
lightrag/lightrag.py CHANGED
@@ -395,6 +395,7 @@ class LightRAG:
395
  namespace=make_namespace(
396
  self.namespace_prefix, NameSpace.KV_STORE_LLM_RESPONSE_CACHE
397
  ),
 
398
  embedding_func=self.embedding_func,
399
  )
400
 
@@ -1421,17 +1422,19 @@ class LightRAG:
1421
  # 3. Before deleting, check the related entities and relationships for these chunks
1422
  for chunk_id in chunk_ids:
1423
  # Check entities
 
1424
  entities = [
1425
  dp
1426
- for dp in self.entities_vdb.client_storage["data"]
1427
  if chunk_id in dp.get("source_id")
1428
  ]
1429
  logger.debug(f"Chunk {chunk_id} has {len(entities)} related entities")
1430
 
1431
  # Check relationships
 
1432
  relations = [
1433
  dp
1434
- for dp in self.relationships_vdb.client_storage["data"]
1435
  if chunk_id in dp.get("source_id")
1436
  ]
1437
  logger.debug(f"Chunk {chunk_id} has {len(relations)} related relations")
@@ -1495,7 +1498,9 @@ class LightRAG:
1495
  for entity in entities_to_delete:
1496
  await self.entities_vdb.delete_entity(entity)
1497
  logger.debug(f"Deleted entity {entity} from vector DB")
1498
- self.chunk_entity_relation_graph.remove_nodes(list(entities_to_delete))
 
 
1499
  logger.debug(f"Deleted {len(entities_to_delete)} entities from graph")
1500
 
1501
  # Update entities
@@ -1514,7 +1519,7 @@ class LightRAG:
1514
  rel_id_1 = compute_mdhash_id(tgt + src, prefix="rel-")
1515
  await self.relationships_vdb.delete([rel_id_0, rel_id_1])
1516
  logger.debug(f"Deleted relationship {src}-{tgt} from vector DB")
1517
- self.chunk_entity_relation_graph.remove_edges(
1518
  list(relationships_to_delete)
1519
  )
1520
  logger.debug(
@@ -1545,9 +1550,10 @@ class LightRAG:
1545
 
1546
  async def process_data(data_type, vdb, chunk_id):
1547
  # Check data (entities or relationships)
 
1548
  data_with_chunk = [
1549
  dp
1550
- for dp in vdb.client_storage["data"]
1551
  if chunk_id in (dp.get("source_id") or "").split(GRAPH_FIELD_SEP)
1552
  ]
1553
 
 
395
  namespace=make_namespace(
396
  self.namespace_prefix, NameSpace.KV_STORE_LLM_RESPONSE_CACHE
397
  ),
398
+ global_config=asdict(self),
399
  embedding_func=self.embedding_func,
400
  )
401
 
 
1422
  # 3. Before deleting, check the related entities and relationships for these chunks
1423
  for chunk_id in chunk_ids:
1424
  # Check entities
1425
+ entities_storage = await self.entities_vdb.client_storage
1426
  entities = [
1427
  dp
1428
+ for dp in entities_storage["data"]
1429
  if chunk_id in dp.get("source_id")
1430
  ]
1431
  logger.debug(f"Chunk {chunk_id} has {len(entities)} related entities")
1432
 
1433
  # Check relationships
1434
+ relationships_storage = await self.relationships_vdb.client_storage
1435
  relations = [
1436
  dp
1437
+ for dp in relationships_storage["data"]
1438
  if chunk_id in dp.get("source_id")
1439
  ]
1440
  logger.debug(f"Chunk {chunk_id} has {len(relations)} related relations")
 
1498
  for entity in entities_to_delete:
1499
  await self.entities_vdb.delete_entity(entity)
1500
  logger.debug(f"Deleted entity {entity} from vector DB")
1501
+ await self.chunk_entity_relation_graph.remove_nodes(
1502
+ list(entities_to_delete)
1503
+ )
1504
  logger.debug(f"Deleted {len(entities_to_delete)} entities from graph")
1505
 
1506
  # Update entities
 
1519
  rel_id_1 = compute_mdhash_id(tgt + src, prefix="rel-")
1520
  await self.relationships_vdb.delete([rel_id_0, rel_id_1])
1521
  logger.debug(f"Deleted relationship {src}-{tgt} from vector DB")
1522
+ await self.chunk_entity_relation_graph.remove_edges(
1523
  list(relationships_to_delete)
1524
  )
1525
  logger.debug(
 
1550
 
1551
  async def process_data(data_type, vdb, chunk_id):
1552
  # Check data (entities or relationships)
1553
+ storage = await vdb.client_storage
1554
  data_with_chunk = [
1555
  dp
1556
+ for dp in storage["data"]
1557
  if chunk_id in (dp.get("source_id") or "").split(GRAPH_FIELD_SEP)
1558
  ]
1559