forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Graph RAG] Init Commit with GraphRag interfaces
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List | ||
|
||
from autogen.agentchat import ConversableAgent | ||
|
||
from .graph_store import GraphStore | ||
|
||
|
||
class GraphRagAgent(ConversableAgent, ABC): | ||
""" | ||
A graph rag agent is a conversable agent which could query graph database for answers. | ||
An implementing agent class would | ||
1. create a graph in the underlying database with input documents | ||
2. use the retrieve() method to retrieve information. | ||
3. use the retrieved information to generate and send back messages. | ||
""" | ||
|
||
@abstractmethod | ||
def _init_db(self, input_doc: List | None = None) -> GraphStore: | ||
""" | ||
This method initializes graph database with the input documents or records. | ||
Usually, it takes the following steps, | ||
1. connecting to a graph database. | ||
2. extract graph nodes, edges based on input data, graph schema and etc. | ||
3. build indexes etc. | ||
return: GraphStore | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def retrieve(self, question: str, **kwargs): | ||
""" | ||
Retrieve answers with human readable questions. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def add_records(self, new_records: List) -> bool: | ||
""" | ||
Add new records to the underlying database and add to the graph if required. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class GraphStoreQueryResult: | ||
""" | ||
A wrapper of graph store query results. | ||
""" | ||
|
||
answer: str | ||
|
||
|
||
class GraphStore(ABC): | ||
"""An abstract base class that represents a underlying graph database. | ||
This interface defines the basic methods which are required by implementing graph rag from graph database. | ||
""" | ||
|
||
@abstractmethod | ||
def query(self, question: str, **kwargs) -> GraphStoreQueryResult: | ||
""" | ||
This method transform a string format question into database query and return the result. | ||
""" | ||
pass |