Make your AI Agents 10x Smarter with GraphRAG (n8n)

The AI AutomatorsAbout 6 min readJul 31, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

Knowledge Graph, Graph RAG, Traditional RAG, Nodes/Entities, Edges/Relationships, Properties, Graph Databases, Neo4j, Cipher, Semantic Search, Lost Context, Multihop Reasoning, Microsoft Graph RAG, Light RAG, Dual Level Retrieval, Local Keywords, Global Keywords, Hybrid Search, Reranking, Contextual Embeddings, N8N, AI Agents, Vector Store, Ingestion Pipeline.

What is a Knowledge Graph?

A knowledge graph is a structured representation of information about real-world entities and their relationships. It's essentially a massive mind map of interconnected things. Key components include:

  • Nodes/Entities: Represent real-world objects (e.g., person, course, institution).
  • Edges/Relationships: Define how entities are connected (e.g., "teaches," "lives in").
  • Properties: Describe the characteristics of nodes (e.g., "computer science course," "English language").

Example: A knowledge graph of Steve Jobs shows he was born in San Francisco, founder of Apple, and Apple created the iPhone.

Graph RAG vs. Traditional RAG

Traditional RAG:

  1. User asks a question.
  2. Search a vector store for semantically relevant document chunks.
  3. Send the question and document chunks to an LLM to generate an answer.

Graph RAG:

  1. Knowledge Graph Construction: Documents are ingested, and an LLM extracts entities and relationships, storing them in a graph database.
  2. Inference Time:
    • Query the vector store for semantically relevant document chunks.
    • Query the knowledge graph for relevant entities, relationships, and neighboring entities.
    • Send the question, document chunks, and graph data to an LLM to generate an answer.

Why Graph RAG?

Graph RAG addresses inherent problems with semantic search:

  • Lost Context: Traditional RAG can return fragmented chunks, losing the overall context of a document (e.g., pulling exclusions from an insurance policy without realizing it's about exclusions).
  • Missing Relationships: Independent chunks may not capture the relationships between entities, leading to inaccurate LLM responses.
  • Multihop Reasoning: Semantic search struggles with traversing real-world networks and connecting seemingly unrelated entities (e.g., the "Six Degrees of Kevin Bacon" game). Graph RAG enables AI agents to answer complex questions requiring multiple connections. Example: "Who should I contact for budget approval for a marketing automation project?"

Graph RAG Implementations: Microsoft Graph RAG vs. Light RAG

Microsoft Graph RAG:

  • Automated knowledge graph construction with LLMs.
  • Extensive enrichment and processing to generate clusters and community summaries.
  • Strong performance on global questions and multihop reasoning.
  • Cons: Expensive, slow inference, complex incremental updates.

Light RAG:

  • Automated knowledge graph construction.
  • Uses dual-level retrieval instead of clusters/summaries.
  • Pros: Strong performance, cheaper, faster responses, easier updates.
  • Cons: Simplified graph, doesn't handle multihop queries well.

Dual Level Retrieval (Light RAG):

  • Extracts local keywords (exact words from the query) and global keywords (broader concepts inferred from the query).
  • Example: For "How has the FIA budget cap affected midfield teams' performance pace?", local keywords are "FIA," "budget cap," "midfield," and global keywords are "financial regulations," "resource allocation," "wind tunnel usage."
  • Returns a semantic context with both exact matches and higher-level concepts.

Light RAG Demo and Setup

Light RAG is an open-source Python application that can be run locally or on a cloud server.

Setup on Render:

  1. Create an account on render.com.
  2. Create a new project and a web service.
  3. Use the Light RAG Docker image from GitHub Container Registry.
  4. Set environmental variables:
    • AUTH_ACCOUNTS: Username and password for the Light RAG app (e.g., DanielWalsh:password).
    • LIGHTRAG_API_KEY: API key for N8N to authenticate.
    • OpenAI API credentials for embeddings and LLM (API key, base URL, model).
    • Concurrency configuration (MAX_ASYNC, PARALLEL_INSERTS, EMBEDDING_ASYNC_CALLS, BATCH_SIZE).
  5. Add a disk for persistent storage (mount to /app/data).
  6. Deploy the web service.

Light RAG Interface:

  • Documents: Upload documents manually.
  • Knowledge Graph: View the generated graph.
  • Retrieval: Test conversations with the documents.
  • API: Endpoints for connecting to N8N.

Document Ingestion Process:

  1. Upload documents.
  2. Filter and deduplicate.
  3. Chunk the document based on configured chunk size.
  4. Vector Store Ingestion: Embed chunks and store vectors in a vector database.
  5. Entity and Relationship Extraction: Use an LLM to extract entities and relationships from each chunk.
  6. Parsing, Transformation, and Merging: Parse, transform, and merge extracted entities and relationships to avoid duplicates.
  7. Entity Description Generation: Generate consolidated entity descriptions using an LLM (if the number of references exceeds a threshold, e.g., 4).
  8. Embedding Entity Descriptions: Embed the entity descriptions to create vectors.
  9. Saving to Databases: Save entities and relationships to the graph database and vectors to the semantic search database.

Connecting Light RAG to N8N

  1. Create a new workflow in N8N.
  2. Add a Chat Trigger, AI Agent, and Chat Model (e.g., OpenAI).
  3. Add an HTTP Request node to query the Light RAG API.
  4. Import the curl request from the Light RAG API documentation.
  5. Set authentication using a generic credential with the X-API-Key header.
  6. Configure the HTTP Request node to pass the query text from the AI Agent.
  7. Specify a system message in the AI Agent to trigger the Light RAG tool.

Light RAG as an Independent Expert vs. Knowledge Graph Provider

Light RAG can act as an independent expert by using the "mix" query mode and re-ranking. However, it has limitations compared to N8N:

  • No agentic capabilities or workflow logic.
  • Basic chunking.
  • Single LLM for ingestion and inference.
  • No advanced RAG features like hybrid search, contextual retrieval, or metadata filters.

N8N RAG System with Knowledge Graph Integration

The video presents a state-of-the-art N8N RAG system that integrates Light RAG for knowledge graph capabilities.

Ingestion Pipeline Enhancements:

  • Document and metadata enrichment.
  • Contextual vector embeddings.
  • Knowledge Graph Updates:
    • If a document is new, ingest it into Light RAG.
    • Fetch the document ID from Light RAG and update the record manager in Superbase.
    • If a document has changed, delete it from Light RAG and reingest the new version.

Inference Workflow Enhancements:

  • Query routing: The agent decides whether to query the vector store or the knowledge graph.
  • If querying the knowledge graph, use the Light RAG API to retrieve entities and relationships.
  • Tidy up the response and send it back to the agent to generate a grounded response.

Conclusion

Graph RAG, particularly with Light RAG, offers a powerful way to enhance AI agent accuracy and reliability by leveraging structured knowledge. While Light RAG can function as an independent expert, integrating it into a comprehensive N8N RAG system allows for advanced features like contextual embeddings, hybrid search, and agentic capabilities, resulting in more comprehensive and accurate AI agent responses. The key is to use Light RAG for its knowledge graph capabilities and combine it with N8N's advanced RAG features for optimal performance.

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.