Skip to content

Commit

Permalink
Add the ability to add new documents to existing graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Shang committed Dec 4, 2024
1 parent c92403b commit 0c1cf4f
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 8 deletions.
23 changes: 21 additions & 2 deletions autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,28 @@ def init_db(self, input_doc: List[Document] | None = None):

def add_records(self, new_records: List) -> bool:
"""
Add a record to the knowledge graph.
Add new records to the knowledge graph.
Args:
new_records (List[Document]): List of new documents to add.
Returns:
bool: True if successful, False otherwise.
"""
pass
if self.graph_store is None:
raise ValueError("Knowledge graph is not initialized. Please call init_db first.")

try:
# Load new documents
new_documents = SimpleDirectoryReader(input_files=[doc.path_or_url for doc in new_records]).load_data()

for doc in new_documents:
self.index.insert(doc)

return True
except Exception as e:
print(f"Error adding records: {e}")
return False

def query(self, question: str, n_results: int = 1, **kwargs) -> GraphStoreQueryResult:
"""
Expand Down
Loading

0 comments on commit 0c1cf4f

Please sign in to comment.