Introduction
LightRAG is a retrieval-augmented generation framework that builds a knowledge graph from your documents and uses it alongside vector search for retrieval. By combining entity-level and thematic-level graph traversal with traditional embedding similarity, it produces answers that capture relationships standard RAG pipelines miss.
What LightRAG Does
- Builds a knowledge graph automatically from ingested documents
- Supports four retrieval modes: naive, local, global, and hybrid
- Uses dual-level retrieval combining entity-specific and high-level thematic queries
- Works with OpenAI, Ollama, and other LLM backends for generation
- Provides incremental insertion so new documents extend the existing graph
Architecture Overview
During ingestion, LightRAG extracts entities and relationships from text using an LLM, then stores them in a graph structure alongside vector embeddings of text chunks. At query time, the framework runs graph traversal at two levels: local retrieval finds specific entities and their neighbors, while global retrieval identifies broader themes and communities. Results from both levels merge with vector similarity matches before the final LLM generation step.
Self-Hosting & Configuration
- Install from PyPI and set the working directory for index persistence
- Configure the LLM backend by passing model name and API key to the constructor
- Adjust chunking parameters to control how documents are split before graph extraction
- Graph storage defaults to local files; can be configured for Neo4j or other backends
- Set embedding model and dimensions to match your vector store requirements
Key Features
- Graph-based retrieval captures entity relationships that flat vector search misses
- Hybrid mode combines all retrieval strategies for best answer quality
- Incremental indexing avoids reprocessing the entire corpus when adding documents
- Lightweight dependency footprint compared to full knowledge-graph platforms
- Compatible with multiple LLM providers and embedding models
Comparison with Similar Tools
- LlamaIndex — general-purpose RAG framework; graph retrieval is optional and requires extra setup
- GraphRAG (Microsoft) — also uses knowledge graphs but has heavier preprocessing and higher cost
- RAGFlow — focuses on document parsing and chunk-level retrieval without built-in graph construction
- Haystack — pipeline-based RAG; graph integration requires custom components
FAQ
Q: How is LightRAG different from standard vector-based RAG? A: It adds a knowledge graph layer that captures entity relationships, enabling answers that connect information across documents rather than relying solely on embedding similarity.
Q: What LLMs can I use? A: Any OpenAI-compatible API, Ollama local models, or custom endpoints. Configure the model parameter when initializing LightRAG.
Q: Does it scale to large document collections? A: Yes. Incremental insertion and graph-based indexing handle growing corpora, though very large graphs may benefit from a dedicated graph database backend.
Q: Can I use my own embedding model? A: Yes. Pass a custom embedding function or specify a Hugging Face model name in the configuration.