> ## 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.GraphQueryEngine

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

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

```python theme={null}
GraphQueryEngine(*args, **kwargs)
```

An abstract base class that represents a graph query engine on top of a underlying graph database.<br />This interface defines the basic methods for graph-based RAG.

<b>Parameters:</b>

| Name       | Description |
| ---------- | ----------- |
| `*args`    |             |
| `**kwargs` |             |

### Instance Methods

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

#### add\_records

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

Add new records to the underlying database and add to the graph if required.

<b>Parameters:</b>

| Name          | Description                 |
| ------------- | --------------------------- |
| `new_records` | **Type:** list\[typing.Any] |

<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
```

This method initializes graph database with the input documents or records.<br />Usually, it takes the following steps,

1. connecting to a graph database.<br />2. extract graph nodes, edges based on input data, graph schema and etc.<br />3. build indexes etc.<br />

<b>Parameters:</b>

| Name        | Description                                                                                                                                                                                                                    |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `input_doc` | a list of input documents that are used to build the graph in database.<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,
    n_results: int = 1,
    **kwarg: Any
) -> GraphStoreQueryResult
```

This method transform a string format question into database query and return the result.

<b>Parameters:</b>

| Name        | Description                             |
| ----------- | --------------------------------------- |
| `question`  | **Type:** str                           |
| `n_results` | **Type:** int<br /><br />**Default:** 1 |
| `**kwarg`   | **Type:** Any                           |

<br />
