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

# Neo4j integration guide

Neo4j is a graph database that stores data as nodes, relationships, and properties instead of tables or documents. This structure allows you to organize your data in an intuitive way, similar to sketching ideas on a whiteboard. With SambaNova, you can power Neo4j applications with state-of-the-art language models for enhanced graph analytics and natural language queries.

<Note>
  This guide was tested with Neo4j 5.x and the SambaNova GraphRAG codebase v1.x. If you're using different versions, some steps may vary.
</Note>

## Overview

This guide walks you through building a GraphRAG application using agents powered by SambaNova LLMs and Neo4j. GraphRAG is a structured, hierarchical approach to Retrieval Augmented Generation (RAG) that leverages graph relationships rather than plain text snippets.

The sample application retrieves electronic health records for patients in the Synthea dataset. The agents use Neo4j's graph query language (Cypher) to access records through two methods:

* **Static queries**: Pre-defined Cypher queries for common operations.
* **Dynamic queries**: LLM-generated Cypher queries based on natural language input (text-to-Cypher).

## Prerequisites

* A [SambaCloud](http://cloud.sambanova.ai) account and [API key](https://cloud.sambanova.ai/apis), or SambaStack deployment.
* Python 3.11 or later.
* [UV package manager](https://github.com/astral-sh/uv) for Python dependency management.
* Neo4j database instance (local or cloud-hosted).

## Setup

### Install dependencies

1. Install the UV package manager.

   ```bash theme={null}
   pip install uv
   ```

2. Clone the integrations repository and navigate to the project directory.

   ```bash theme={null}
   git clone git@github.com:sambanova/integrations.git
   cd integrations/langgraph/agentic_graph_rag
   ```

3. Create a virtual environment and install dependencies.

   ```bash theme={null}
   uv venv
   source .venv/bin/activate
   uv pip install -r requirements.txt
   ```

### Load the Synthea dataset

1. Download the [Synthea dataset dump file](https://drive.google.com/file/d/15WQWmEkHTB71H3OZ_3Kbb_OKBvM9tbVz/view?usp=drive_link).

2. Load the dump file into your Neo4j instance. For Neo4j Desktop:

   1. Stop the database.

   2. Open the terminal for your database.

   3. Run the following command, replacing the path with your download location:

      ```bash theme={null}
      neo4j-admin database load --from-path=/path/to/dump synthea --overwrite-destination
      ```

   4. Start the database.

For Neo4j Aura or other cloud instances, refer to the [Neo4j data import documentation](https://neo4j.com/docs/operations-manual/current/tools/neo4j-admin/neo4j-admin-import/).

### Configure environment variables

1. Copy the example environment file.

   ```bash theme={null}
   cp .env.example .env
   ```

2. Edit `.env` and set the following variables:

   ```bash theme={null}
   # SambaNova API configuration
   SAMBANOVA_API_KEY=your_api_key_here
   SAMBANOVA_BASE_URL=https://api.sambanova.ai/v1

   # Neo4j connection
   NEO4J_URI=bolt://localhost:7687
   NEO4J_USERNAME=neo4j
   NEO4J_PASSWORD=your_password_here
   ```

## Run the application

### Start the backend

Launch the HTTP server that connects to the Neo4j database using SambaNova LLMs.

```bash theme={null}
bash ./start_server.sh
```

You should see output indicating the server is running:

```
INFO:     Uvicorn running on http://0.0.0.0:8000
INFO:     Application startup complete.
```

### Open the frontend

Open your browser to the application landing page:

```
http://localhost:8000/app
```

### Verify the connection

1. In the chatbot interface, enter a test query such as "List all patients."
2. Confirm that the application returns patient records from the Neo4j database.

## Capabilities

Once configured, the GraphRAG application enables:

* **Natural language queries**: Ask questions about patient data in plain English.
* **Graph traversal**: Explore relationships between patients, conditions, medications, and encounters.
* **Text-to-Cypher**: Automatically generate Cypher queries from natural language input.
* **Healthcare analytics**: Analyze patterns across the Synthea dataset using graph-based insights.

## Video demonstration

The following video demonstrates the GraphRAG application leveraging SambaNova LLMs to access healthcare data from a Neo4j database.

<iframe width="560" height="315" src="https://www.youtube.com/embed/2cwvj07cY8s?cc_load_policy=1" title="Demo: GraphRAG application with SambaNova and Neo4j" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerPolicy="strict-origin-when-cross-origin" allowFullScreen />

## Troubleshooting

| Issue                                      | Solution                                                                                                                  |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- |
| `Connection refused` when starting backend | Verify Neo4j is running and the `NEO4J_URI` in `.env` is correct.                                                         |
| Authentication errors                      | Check that `NEO4J_USERNAME` and `NEO4J_PASSWORD` match your Neo4j credentials.                                            |
| `SAMBANOVA_API_KEY not set` error          | Ensure your `.env` file exists and contains a valid API key from [SambaCloud](https://cloud.sambanova.ai/apis).           |
| Empty query results                        | Confirm the Synthea dataset was loaded correctly. Run `MATCH (n) RETURN count(n)` in Neo4j Browser to verify data exists. |
| `ModuleNotFoundError`                      | Ensure you activated the virtual environment: `source .venv/bin/activate`                                                 |

## Additional resources

* [Neo4j documentation](https://neo4j.com/docs/)
* [Cypher query language reference](https://neo4j.com/docs/cypher-manual/current/)
* [SambaNova GraphRAG repository](https://github.com/sambanova/integrations/tree/main/langgraph/agentic_graph_rag)
* [SambaCloud API reference](/en/api-reference/overview)
* [SambaCloud support](https://sambanova.ai/support)
