> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.agentchat.contrib.graph_rag.neo4j_native_graph_query_engine.Neo4jNativeGraphQueryEngine

<h2 id="autogen.agentchat.contrib.graph_rag.neo4j_native_graph_query_engine.Neo4jNativeGraphQueryEngine" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">Neo4jNativeGraphQueryEngine</span>
</h2>

```python theme={null}
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.<br />Provides functionality to initialize a knowledge graph,
create a vector index, and query the graph using Neo4j and LLM.<br />Initialize a Neo4j graph query engine.<br />

<b>Parameters:</b>

| Name                  | Description                                                                 |
| --------------------- | --------------------------------------------------------------------------- |
| `host`                | **Type:** str<br /><br />**Default:** 'neo4j                                |
| `port`                | **Type:** int<br /><br />**Default:** 7687                                  |
| `username`            | **Type:** str<br /><br />**Default:** 'neo4j'                               |
| `password`            | **Type:** str<br /><br />**Default:** 'password'                            |
| `embeddings`          | **Type:** ForwardRef('Embedder') \| None<br /><br />**Default:** None       |
| `embedding_dimension` | **Type:** int \| None<br /><br />**Default:** 3072                          |
| `llm`                 | **Type:** ForwardRef('LLMInterface') \| None<br /><br />**Default:** None   |
| `query_llm`           | **Type:** ForwardRef('LLMInterface') \| None<br /><br />**Default:** None   |
| `entities`            | **Type:** List\[str] \| None<br /><br />**Default:** None                   |
| `relations`           | **Type:** List\[str] \| None<br /><br />**Default:** None                   |
| `potential_schema`    | **Type:** List\[tuple\[str, str, str]] \| None<br /><br />**Default:** None |

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### add\_records

```python theme={null}
add_records(self, new_records: list[Document]) -> bool
```

Add new records to the Neo4j database.<br />

<b>Parameters:</b>

| Name          | Description                                                                                                                                         |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `new_records` | List of new Documents to be added<br /><br />**Type:** list\[[Document](/docs/api-reference/autogen/agentchat/contrib/graph_rag/document/Document)] |

<b>Returns:</b>

| Type | Description                                                     |
| ---- | --------------------------------------------------------------- |
| bool | bool: True if records were added successfully, False otherwise. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### init\_db

```python theme={null}
init_db(self, input_doc: list[Document] | None = None) -> None
```

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

<b>Parameters:</b>

| Name        | Description                                                                                                                                                                                    |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `input_doc` | Input documents for building the graph.<br /><br />**Type:** list\[[Document](/docs/api-reference/autogen/agentchat/contrib/graph_rag/document/Document)] \| None<br /><br />**Default:** None |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### query

```python theme={null}
query(self, question: str) -> GraphStoreQueryResult
```

Query the Neo4j database using a natural language question.<br />

<b>Parameters:</b>

| Name       | Description                                                                 |
| ---------- | --------------------------------------------------------------------------- |
| `question` | The question to be answered by querying the graph.<br /><br />**Type:** str |

<b>Returns:</b>

| Type                                                                                                                      | Description                                     |
| ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| [GraphStoreQueryResult](/docs/api-reference/autogen/agentchat/contrib/graph_rag/graph_query_engine/GraphStoreQueryResult) | GraphStoreQueryResult: The result of the query. |

<br />
