Neo4jNativeGraphQueryEngine

Neo4jNativeGraphQueryEngine(
    host: str = 'neo4j://localhost',
    port: int = 7687,
    username: str = 'neo4j',
    password: str = 'password',
    embeddings: ForwardRef('Embedder') | None = None,
    embedding_dimension: int | None = 3072,
    llm: ForwardRef('LLMInterface') | None = None,
    query_llm: ForwardRef('LLMInterface') | None = None,
    entities: List[str] | None = None,
    relations: List[str] | None = None,
    potential_schema: List[tuple[str, str, str]] | None = None
)

A graph query engine implemented using the Neo4j GraphRAG SDK.
Provides functionality to initialize a knowledge graph, create a vector index, and query the graph using Neo4j and LLM.
Initialize a Neo4j graph query engine.

Parameters:
NameDescription
hostType: str

Default: ‘neo4j
portType: int

Default: 7687
usernameType: str

Default: ‘neo4j’
passwordType: str

Default: ‘password’
embeddingsType: ForwardRef(‘Embedder’) | None

Default: None
embedding_dimensionType: int | None

Default: 3072
llmType: ForwardRef(‘LLMInterface’) | None

Default: None
query_llmType: ForwardRef(‘LLMInterface’) | None

Default: None
entitiesType: List[str] | None

Default: None
relationsType: List[str] | None

Default: None
potential_schemaType: List[tuple[str, str, str]] | None

Default: None

Instance Methods

add_records

add_records(self, new_records: list[Document]) -> bool

Add new records to the Neo4j database.

Parameters:
NameDescription
new_recordsList of new Documents to be added

Type: list[Document]
Returns:
TypeDescription
boolbool: True if records were added successfully, False otherwise.

init_db

init_db(self, input_doc: list[Document] | None = None) -> None

Initialize the Neo4j graph database using the provided input doc.
Currently this method only supports single document input (only reads the first doc).
This method supports both text and PDF documents. It performs the following steps:
1. Clears the existing database.
2. Extracts graph nodes and relationships from the input data to build a knowledge graph.
3. Creates a vector index for efficient retrieval.

Parameters:
NameDescription
input_docInput documents for building the graph.

Type: list[Document] | None

Default: None

query

query(
    self,
    question: str,
    n_results: int = 1,
    **kwargs: Any
) -> GraphStoreQueryResult

Query the Neo4j database using a natural language question.

Parameters:
NameDescription
questionThe question to be answered by querying the graph.

Type: str
n_resultsType: int

Default: 1
**kwargsType: Any
Returns:
TypeDescription
GraphStoreQueryResultGraphStoreQueryResult: The result of the query.