mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-16 22:51:24 +00:00
fix(GraphRAG): create same graph name error. (#2215)
This commit is contained in:
@@ -40,3 +40,7 @@ class GraphStoreBase(ABC):
|
||||
@abstractmethod
|
||||
def get_config(self) -> GraphStoreConfig:
|
||||
"""Get the graph store config."""
|
||||
|
||||
def is_exist(self, name) -> bool:
|
||||
"""Check Graph Name is Exist."""
|
||||
raise NotImplementedError
|
||||
|
@@ -102,6 +102,10 @@ class TuGraphStore(GraphStoreBase):
|
||||
"""Get the TuGraph store config."""
|
||||
return self._config
|
||||
|
||||
def is_exist(self, name) -> bool:
|
||||
"""Check Graph Name is Exist."""
|
||||
return self.conn.is_exist(name)
|
||||
|
||||
def _add_vertex_index(self, field_name):
|
||||
"""Add an index to the vertex table."""
|
||||
# TODO: Not used in the current implementation.
|
||||
|
@@ -316,6 +316,8 @@ class CommunitySummaryKnowledgeGraph(BuiltinKnowledgeGraph):
|
||||
|
||||
async def aload_document(self, chunks: List[Chunk]) -> List[str]:
|
||||
"""Extract and persist graph from the document file."""
|
||||
if not self.vector_name_exists():
|
||||
self._graph_store_apdater.create_graph(self.get_config().name)
|
||||
await self._aload_document_graph(chunks)
|
||||
await self._aload_triplet_graph(chunks)
|
||||
await self._community_store.build_communities(
|
||||
|
@@ -172,6 +172,8 @@ class BuiltinKnowledgeGraph(KnowledgeGraphBase):
|
||||
return chunk.chunk_id
|
||||
|
||||
# wait async tasks completed
|
||||
if not self.vector_name_exists():
|
||||
self._graph_store_apdater.create_graph(self.get_config().name)
|
||||
tasks = [process_chunk(chunk) for chunk in chunks]
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
@@ -187,6 +189,8 @@ class BuiltinKnowledgeGraph(KnowledgeGraphBase):
|
||||
Return:
|
||||
List[str]: chunk ids.
|
||||
"""
|
||||
if not self.vector_name_exists():
|
||||
self._graph_store_apdater.create_graph(self.get_config().name)
|
||||
for chunk in chunks:
|
||||
triplets = await self._triplet_extractor.extract(chunk.content)
|
||||
for triplet in triplets:
|
||||
@@ -279,3 +283,7 @@ class BuiltinKnowledgeGraph(KnowledgeGraphBase):
|
||||
"""Delete by ids."""
|
||||
self._graph_store_apdater.delete_document(chunk_id=ids)
|
||||
return []
|
||||
|
||||
def vector_name_exists(self) -> bool:
|
||||
"""Whether name exists."""
|
||||
return self._graph_store_apdater.graph_store.is_exist(self._config.name)
|
||||
|
Reference in New Issue
Block a user