Knowledge Graphs and LightRAG

Aug 4, 2025

Overview

This lecture explains what a knowledge graph is, how Graph RAG (Retrieval Augmented Generation using knowledge graphs) improves AI accuracy, and demonstrates setting up and integrating LightRAG with N8N for more reliable AI agent responses.

Knowledge Graphs: Concepts and Structure

  • A knowledge graph represents entities (nodes), their relationships (edges), and properties in a structured way.
  • Entities are real-world things like people, organizations, or events.
  • Relationships (edges) connect entities, showing how they are related.
  • Properties provide additional details about entities.
  • Knowledge graphs help identify patterns and context often missed in flat or fragmented data.

How Graph RAG Works

  • Traditional RAG queries a vector store to retrieve document chunks relevant to the query.
  • Graph RAG builds a knowledge graph from ingested documents, extracting entities and relationships using LLMs.
  • On query, both the vector store and the knowledge graph are searched; results are combined and sent to the LLM for answer generation.
  • Graph RAG retrieves not just relevant documents but related concepts, improving context and reducing fragmented answers.
  • Enables multi-hop reasoning, connecting information through several degrees of relationships.

LightRAG vs. Other Graph RAG Solutions

  • Microsoft GraphRAG provides advanced enrichment (clusters, community summaries) but is complex and resource-intensive.
  • LightRAG is open source, cheaper, faster, and easier to update but less advanced (no multi-hop, no clusters).
  • LightRAG uses dual retrieval: extracts both exact (local) and broader (global) concepts from queries.

Deploying and Using LightRAG

  • LightRAG can be run locally or deployed via Docker/cloud (e.g., Render).
  • Documents are uploaded and processed: de-duplication, chunking, embedding, entity and relationship extraction, merging and description generation.
  • Knowledge graph is visualized and can be queried for detailed answers.
  • Retrieval modes: naive (vector store only), local (exact matches), global (broader concepts), hybrid/mix (combines all).

Integrating with N8N and Building Pipelines

  • LightRAG connects to N8N via API for agent-based question answering.
  • N8N pipelines can automate document ingestion, enrichment, and knowledge graph updates.
  • Hybrid systems can route queries to vector store or knowledge graph depending on context, maximizing answer accuracy.
  • Proper configuration (e.g., re-ranking, token limits) is needed for efficient retrieval.

Strengths and Limitations

  • Knowledge graphs add context, support multi-hop reasoning, and improve citation and traceability.
  • LightRAG is easy to set up but lacks advanced workflow, chunking, and retrieval features found in more robust systems or when combined with N8N.
  • Use LightRAG for knowledge graph creation and N8N for advanced agent logic and retrieval.

Key Terms & Definitions

  • Knowledge Graph — A structured network of real-world entities and their relationships.
  • Entity (Node) — An object or concept represented in the graph.
  • Edge (Relationship) — A connection showing how two entities relate.
  • Property — A characteristic or detail about an entity.
  • RAG (Retrieval Augmented Generation) — AI method retrieving supporting data for LLM answers.
  • Graph RAG — RAG using a knowledge graph for deeper, contextual retrieval.
  • LightRAG — An open-source tool for automated knowledge graph construction and dual-level retrieval.

Action Items / Next Steps

  • Practice ingesting documents and building a knowledge graph with LightRAG.
  • Explore deploying LightRAG and connecting via API to your AI agent in N8N.
  • Test different retrieval modes and re-ranking to optimize answer quality.
  • Review and tune configuration settings (embedding models, chunking, token limits) for your use case.