Skip to content

Commit a53612d

Browse files
feat(graphgen): add clear func
1 parent b612600 commit a53612d

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

graphgen/graphgen.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://github.com/HKUDS/LightRAG
1+
# Adapt from https://github.com/HKUDS/LightRAG
22

33
import os
44
import asyncio
@@ -17,7 +17,6 @@
1717

1818
sys_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
1919

20-
2120
@dataclass
2221
class GraphGen:
2322
unique_id: int = int(time.time())
@@ -207,3 +206,17 @@ async def async_traverse(self):
207206
self.graph_storage, self.traverse_strategy, self.text_chunks_storage)
208207
await self.qa_storage.upsert(results)
209208
await self.qa_storage.index_done_callback()
209+
210+
def clear(self):
211+
loop = create_event_loop()
212+
loop.run_until_complete(self.async_clear())
213+
214+
async def async_clear(self):
215+
await self.full_docs_storage.clear()
216+
await self.text_chunks_storage.clear()
217+
await self.wiki_storage.clear()
218+
await self.graph_storage.clear()
219+
await self.rephrase_storage.clear()
220+
await self.qa_storage.clear()
221+
222+
logger.info("All caches are cleared")

graphgen/operators/extract_kg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def _process_single_content(chunk: Chunk, max_loop: int = 3):
4545
hint_prompt = KG_EXTRACTION_PROMPT[language]["TEMPLATE"].format(
4646
**KG_EXTRACTION_PROMPT["FORMAT"], input_text=content
4747
)
48+
print(hint_prompt, len(hint_prompt))
4849

4950
final_result = await llm_client.generate_answer(hint_prompt)
5051
logger.info('First result: %s', final_result)

models/storage/json_storage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ async def upsert(self, data: dict):
4545

4646
async def drop(self):
4747
self._data = {}
48+
49+
async def clear(self):
50+
if os.path.exists(self._file_name):
51+
os.remove(self._file_name)

models/storage/networkx_storage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,10 @@ async def delete_node(self, node_id: str):
150150
logger.info("Node %s deleted from the graph.", node_id)
151151
else:
152152
logger.warning("Node %s not found in the graph for deletion.", node_id)
153+
154+
async def clear(self):
155+
"""
156+
Clear the graph by removing all nodes and edges.
157+
"""
158+
self._graph.clear()
159+
logger.info("Graph %s cleared.", self.namespace)

0 commit comments

Comments
 (0)