Make RAG 100x Better with Real-Time Knowledge Graphs

Cole MedinAbout 5 min readMay 29, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

  • Retrieval Augmented Generation (RAG): A technique to provide AI agents with external knowledge.
  • Temporal Aware Knowledge Graph: A knowledge graph that tracks changes in data over time, providing historical context.
  • Knowledge Graph: A graph database that represents knowledge as nodes and relationships.
  • Neo4j: A graph database management system used by Graffiti.
  • Episodes: Units of information stored in Graffiti's knowledge graph.
  • Center Node Search: A search strategy that focuses on nodes related to a specific central node.
  • Agentic RAG: An approach where AI agents have multiple tools (e.g., knowledge graph search, vector database search) to retrieve information.
  • Pydantic AI: A framework for building AI agents using Pydantic data validation.
  • Massive Language Models (MLMs): A hypothetical new type of AI model introduced as an example.

Graffiti: Temporal Aware Knowledge Graph for RAG

The Problem with Static RAG

Traditional RAG systems suffer from being static, requiring manual and inefficient synchronization of the agent's knowledge base with the underlying data store. This becomes problematic in dynamic environments where data is constantly changing (e.g., user preferences, market conditions).

Introducing Graffiti

Graffiti is an open-source platform designed to address the limitations of static RAG by building temporal aware knowledge graphs. It allows for continuous ingestion of ever-changing data while maintaining a historical record of data changes.

Temporal Awareness Explained

Graffiti doesn't just replace old data with new data; it adds new information while preserving historical context. For example, if a customer initially likes Adidas shoes but later prefers Puma, Graffiti stores both preferences with timestamps indicating when each preference was valid. This historical context is valuable for providing personalized customer experiences.

Knowledge Graph Structure

Graffiti uses Neo4j as its underlying knowledge graph engine. Information is stored as nodes with relationships connecting them. These relationships capture how information is related and how it has changed over time. Metadata, such as version information (e.g., GPT-4 is a successor to GPT-3.5), helps tie information together.

Graffiti vs. Other Knowledge Graph Solutions (Light RAG, Graph RAG)

While other knowledge graph solutions like Light RAG and Graph RAG are suitable for static document summarization, Graffiti excels in dynamic data environments. Graffiti is more lightweight, scalable, and offers sub-second latency for both building the knowledge graph and querying it.

Quick Start Guide

The video provides a quick start guide to using Graffiti, based on the project's GitHub repository. The prerequisites include:

  • Python
  • Neo4j
  • OpenAI API key (or other LLM provider)

Neo4j can be installed using Neo4j Desktop or through a Docker-based local AI package. The quick start involves:

  1. Connecting to Neo4j: Initializing Graffiti with Neo4j credentials.
  2. Building Indices and Constraints: Setting up the initial knowledge graph structure.
  3. Adding Episodes: Inserting information into the knowledge graph. Episodes can be in various formats (e.g., text, JSON). Each episode requires a reference time to indicate when the information was valid.
  4. Searching the Knowledge Graph: Using the graffiti.search function to query the knowledge graph. Results include the fact, a unique identifier, and the valid-at timestamp.
  5. Center Node Search: Refining searches by focusing on nodes related to a specific central node.
  6. Closing the Connection: Terminating the Neo4j connection to prevent memory leaks.

Building an AI Agent with Graffiti

The video demonstrates how to build an AI agent using Pydantic AI that leverages Graffiti as a tool. The agent has a single tool: searching the knowledge graph. The process involves:

  1. Connecting to Neo4j: Establishing a connection to the Neo4j knowledge graph.
  2. Creating Episodes: Defining units of information to be added to the knowledge graph.
  3. Building the Agent: Creating an AI agent with Pydantic AI, passing in the Graffiti client as a dependency.
  4. Defining the Tool: Implementing a tool that allows the agent to search the knowledge graph using Graffiti.
  5. Evolving the Knowledge Base: Adding information to the knowledge graph in phases, simulating how data changes over time.
  6. Querying the Agent: Asking the agent questions and observing how its answers change as the knowledge base evolves.

LLM Evolution Example

The video presents an example where the agent's knowledge of the "best LLM" evolves over time:

  • Phase 1: The agent learns about GPT-4.1, Gemini 2.5 Pro, and Claude 3.7 Sonnet.
  • Phase 2: The agent learns that Anthropic released Claude 4, which is now the best LLM. The knowledge graph updates to reflect this change, invalidating the previous "best LLM" fact.
  • Phase 3: The agent learns about a new type of AI model called Massive Language Models (MLMs), rendering LLMs obsolete. The agent's responses reflect this new information.

Combining Knowledge Graphs with Traditional RAG

The video emphasizes that knowledge graphs should be used alongside traditional RAG with vector databases. Agentic RAG involves giving the agent multiple tools to explore knowledge in different ways. This allows the agent to leverage the strengths of both knowledge graphs and vector databases.

Conclusion

Graffiti is a powerful platform for building temporal aware knowledge graphs that can significantly enhance RAG systems. Its ability to track data changes over time provides valuable context for AI agents, leading to more robust and informative responses. Combining knowledge graphs with traditional RAG strategies creates the ideal RAG solution for many AI agent applications.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.