# Building AI Knowledge Graph Using Graphiti & Neo4j

Graphiti is a compact yet powerful Python library that converts raw text or JSON into an **AI Knowledge Graph**—a structured store of facts that acts as **AI Agent Memory**. Below is the exact workflow I used to load **FutureSmart AI** data into Neo4j, explore the resulting **AI Graph Memory**, and run hybrid (semantic + keyword) searches.

---

## 1\. Why Graphiti for AI Agent Memory?

* **Real‑time inserts** – Add new facts without bulk re‑processing.
    
* **LLM‑powered parsing** – Entity extraction, relationship mapping, summaries, and embeddings handled automatically.
    
* **Neo4j under the hood** – First‑class graph database with Cypher, indexes, and visualization tools.
    
* **Perfect for AI Agent Memory** – Your agent can recall structured facts on demand.
    

---

## 2\. Quick Refresher: Knowledge‑Graph Basics

```plaintext
“Pradip Nichite founded FutureSmart AI.”
```

| Component | Example |
| --- | --- |
| **Entity** | `Pradip Nichite` |
| **Entity** | `FutureSmart AI` |
| **Edge** | `founded` |
| **Triple** | (Pradip Nichite, founded, FutureSmart AI) |

Graphiti stores each triple as Neo4j nodes (**Entity**) and edges (**RELATES\_TO**), plus an **Episode** node that records the original text—together forming your **AI Graph Memory**.

---

## 3\. Setup

```bash
pip install graphiti-core  # build your AI Knowledge Graph in minutes
```

```python
import os
from google.colab import userdata

os.environ["OPENAI_API_KEY"] = userdata.get("OPENAI_API_KEY")
neo4j_uri      = "neo4j+s://<your‑instance>.databases.neo4j.io"
neo4j_user     = "neo4j"
neo4j_password = userdata.get("NEO4J_PASSWORD")
```

---

## 4\. Initialise Graphiti (clean slate)

```python
from graphiti_core import Graphiti
from graphiti_core.utils.maintenance.graph_data_operations import clear_data

graphiti = Graphiti(neo4j_uri, neo4j_user, neo4j_password)
await clear_data(graphiti.driver)              # optional for a fresh start
await graphiti.build_indices_and_constraints() # creates indexes once
```

---

## 5\. Insert Episodes into Your AI Knowledge Graph

```python
episodes = [
    {
        "name": "About Me",
        "content": "Hi, I'm Pradip Nichite. I am the founder and CEO of FutureSmart AI.",
        "type": EpisodeType.text,
        "description": "intro"
    },
    {
        "name": "About FutureSmart AI",
        "content": "FutureSmart AI builds custom AI solutions for clients.",
        "type": EpisodeType.text,
        "description": "company overview"
    }
]

await add_data(episodes)  # helper loops and calls graphiti.add_episode()
```

### Under‑the‑Hood Workflow

1. **Entity extraction** (people, orgs, products)
    
2. **Relationship extraction** (`founded`, `associated_with`, …)
    
3. **Deduplication** of entities
    
4. **Summary** + **embedding** generation
    
5. **Graph write** → Neo4j (your **AI Graph Memory**)
    

All steps run via LLM calls you can inspect in your OpenAI usage logs.

---

## 6\. Visual Exploration of AI Graph Memory

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754036009862/076718dd-f8c0-42a6-8d7a-8e2d8fcb491b.png align="center")

* **Blue** = Episode nodes (source text)
    
* **Brown** = Entity nodes (deduplicated concepts)
    
* Edges labelled **MENTIONS** & **RELATES\_TO** connect everything
    

Run `MATCH (n) RETURN n` in Neo4j Browser to explore your **AI Knowledge Graph**. Click any node to view its `summary` and vector `embedding`.

---

## 7\. CSV Export at a Glance

| Metric | Count |
| --- | --- |
| Nodes total | 9 |
| • Entity | 5 |
| • Episode | 4 |
| Relationships total | 13 |
| • `MENTIONS` | 8 |
| • `RELATES_TO` | 5 |

Sample from `node‑export.csv`:

| name | label | summary |
| --- | --- | --- |
| Pradip Nichite | Entity | Pradip Nichite is the founder and CEO of FutureSmart AI. |
| FutureSmart AI | Entity | FutureSmart AI is a company that develops AI solutions for clients and is known for creating AI demos. |
| About Me | Episodic |  |
| AI Demos | Entity | AI Demos is associated with FutureSmart AI and was founded by Pradip Nichite. |
| FutureSmart Agent | Entity | FutureSmart Agent is a product developed by FutureSmart AI. |
| About FutureSmart AI | Episodic |  |
| About AI Demos | Episodic |  |
| FutureSmart Agent | Episodic |  |
| [https://agent.futuresmart.ai/](https://agent.futuresmart.ai/) | Entity | FutureSmart AI is the company behind the product FutureSmart Agent. Their website is [https://agent.futuresmart.ai/](https://agent.futuresmart.ai/). |

---

## 8\. Query Your AI Agent Memory (Hybrid Search)

```python
query   = "What products FutureSmart has"
results = await graphiti.search(query=query, num_results=3)
print_result(results)
```

```plaintext
Search Results:
UUID: dae5cb4d-adb2-401f-991f-aa5259127245
Fact: FutureSmart Agent is a product of FutureSmart AI
Valid from: 2025-08-01 07:54:17+00:00
---
UUID: afc8af04-0af2-4fd8-940a-91cf93da6943
Fact: https://agent.futuresmart.ai/ is the website of FutureSmart Agent
Valid from: 2025-08-01 07:54:17+00:00
---
UUID: c6d353e8-6fb1-4263-a0e9-4df21ea5805f
Fact: FutureSmart AI is the company behind AI Demos
Valid from: 2025-08-01 07:54:08+00:00
```

Graphiti blends embedding similarity with BM25 keywords to surface relevant facts for downstream agents.

---

## 9\. Practical Uses of an AI Graph Memory

* **AI Agent Memory** for chatbots and assistants
    
* Enterprise **AI Knowledge Graph** for internal search
    
* Neo4j Bloom dashboards for leadership teams
    
* Light‑weight RAG pipelines powered by graph facts
    

---

## 10\. What’s Next?

* Integrate Graphiti memory into LangGraph / LangChain agents
    
* Combine vector store retrieval with graph queries
    
* Package everything in FastAPI + Streamlit for a live demo
    

---

### Prefer video over text?

Watch the full walkthrough here  

%[https://youtu.be/H2Cb5wbcRzo] 

---

### Need a Custom AI Agent or Graph Solution?

FutureSmart AI helps companies turn raw data into production-ready **AI Knowledge Graphs** and **AI Agent Memory** systems.

* End-to-end Graphiti + Neo4j pipelines
    
* LangChain / LangGraph agent integrations
    
* Scalable FastAPI & Streamlit front-ends
    
* Secure, cloud-native deployment
    

Want proof we deliver? 👉 **See our real-world results:** [https://futuresmart.ai/case-studies](https://futuresmart.ai/case-studies)

> **Book a free consult:** [contact@futuresmart.ai](mailto:contact@futuresmart.ai)

---

### Questions?

Drop a comment on YouTube or email [**contact@futuresmart.ai**](mailto:contact@futuresmart.ai).
