Skip to content

Commit 060d709

Browse files
authored
Document GraphRAG class (#118)
1 parent 5c40b03 commit 060d709

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

docs/source/api.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ LLMInterface
156156

157157

158158
OpenAILLM
159-
=========
159+
---------
160160

161161
.. autoclass:: neo4j_genai.llm.OpenAILLM
162162
:members:
@@ -182,6 +182,17 @@ ERExtractionTemplate
182182
:members:
183183

184184

185+
****
186+
RAG
187+
****
188+
189+
GraphRAG
190+
========
191+
192+
.. autoclass:: neo4j_genai.generation.graphrag.GraphRAG
193+
:members:
194+
195+
185196
.. _database-interaction-section:
186197

187198
********************

src/neo4j_genai/generation/graphrag.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@
3434

3535

3636
class GraphRAG:
37+
"""Performs a GraphRAG search using a specific retriever
38+
and LLM.
39+
40+
Example:
41+
42+
.. code-block:: python
43+
44+
import neo4j
45+
from neo4j_genai.retrievers import VectorRetriever
46+
from neo4j_genai.llm.openai_llm import OpenAILLM
47+
from neo4j_genai.generation import GraphRAG
48+
49+
driver = neo4j.GraphDatabase.driver(URI, auth=AUTH)
50+
51+
retriever = VectorRetriever(driver, "vector-index-name", custom_embedder)
52+
llm = OpenAILLM()
53+
graph_rag = GraphRAG(retriever, llm)
54+
graph_rag.search(query_text="Find me a book about Fremen")
55+
56+
Args:
57+
retriever (Retriever): The retriever used to find relevant context to pass to the LLM.
58+
llm (LLMInterface): The LLM used to generate the answer.
59+
prompt_template (RagTemplate): The prompt template that will be formatted with context and user question and passed to the LLM.
60+
61+
Raises:
62+
RagInitializationError: If validation of the input arguments fail.
63+
"""
64+
3765
def __init__(
3866
self,
3967
retriever: Retriever,
@@ -67,10 +95,10 @@ def search(
6795
6896
Args:
6997
query_text (str): The user question
70-
examples: Examples added to the LLM prompt.
98+
examples (str): Examples added to the LLM prompt.
7199
retriever_config (Optional[dict]): Parameters passed to the retriever
72100
search method; e.g.: top_k
73-
return_context (bool): Whether to return the retriever result (default: False)
101+
return_context (bool): Whether to append the retriever result to the final result (default: False)
74102
query (Optional[str]): The user question. Will be deprecated in favor of query_text.
75103
76104
Returns:

0 commit comments

Comments
 (0)