LightRAG Algorithm

LightRAG is Almanac's graph-enhanced retrieval system that understands not just what information exists, but how it connects together. Unlike traditional RAG that treats documents as isolated chunks, LightRAG builds a knowledge graph that captures entities and their relationships.

The Problem with Traditional RAG

Traditional RAG systems have a fundamental limitation:

User Query → Vector Search → Chunks → LLM

Issues:

  • No Context: Chunks are isolated - no understanding of relationships

  • Token Hungry: Need to retrieve many chunks to get full context

  • Miss Connections: Can't answer questions about how things relate

Example Problem:

"How is the authentication system connected to billing?"

Traditional RAG might find chunks about "authentication" and chunks about "billing", but it doesn't understand the connection between them.

How LightRAG Solves This

LightRAG extracts entities (people, projects, concepts) and relationships (works on, depends on, discussed in) to build a knowledge graph:

Documents → Entity Extraction → Knowledge Graph

User Query → Keyword Extraction → Graph Traversal → Results

Now the same question can be answered by following the graph:

The 5 Query Modes

LightRAG adapts its retrieval strategy based on your query type. Think of it like having 5 different librarians, each with their own expertise:

1. Naive Mode (The Speed Reader)

What it does: Pure vector search - fastest option

Best for:

  • Simple keyword searches

  • When you know exact terms

  • Quick lookups

How it works:

Example:

Pros: ⚡ Fastest (50-100ms) Cons: ❌ No graph context, may miss relevant information


2. Local Mode (The Specialist)

What it does: Focuses on specific entities and their immediate connections

Best for:

  • Questions about specific people, projects, or concepts

  • Finding everything related to one topic

  • "What is X?" queries

How it works:

Example:

Pros: 🎯 Entity-focused, includes relationships Cons: ⚠️ Limited to 1-hop connections


3. Global Mode (The Connector)

What it does: Focuses on relationships between entities

Best for:

  • Understanding connections and workflows

  • "How does X relate to Y?" queries

  • Finding indirect connections

How it works:

Example:

Pros: 🔗 Reveals indirect connections, big-picture understanding Cons: ⚠️ May miss specific details


4. Hybrid Mode (The Balanced Approach)

What it does: Combines Local + Global modes

Best for:

  • Complex questions requiring both details and connections

  • When you're not sure which mode to use

  • Multi-faceted queries

How it works:

Example:

Pros: ⚖️ Balanced, comprehensive results Cons: ⏱️ Slower than single modes (200-400ms)


5. Mix Mode (The Expert) 🌟

What it does: Uses all modes + reranking for maximum accuracy

Best for:

  • When accuracy matters most

  • Complex, nuanced questions

  • Production applications

How it works:

Example:

Pros: 🎯 Most accurate, best results Cons: ⏱️ Slowest (300-600ms), requires reranker model


Query Mode Comparison

Mode
Speed
Accuracy
Use Case
Graph Used

Naive

⚡⚡⚡ Fast

⭐ Basic

Simple keyword search

❌ No

Local

⚡⚡ Good

⭐⭐ Good

Entity-focused questions

✅ 1-hop

Global

⚡⚡ Good

⭐⭐ Good

Relationship questions

✅ Multi

Hybrid

⚡ Slower

⭐⭐⭐ Better

Complex questions

✅ Full

Mix

⏱️ Slowest

⭐⭐⭐⭐ Best

Production/accuracy

✅ + Rerank

Keyword Extraction: Dual-Level Approach

LightRAG uses two levels of keyword extraction:

High-Level Keywords

Purpose: Capture broad concepts and relationships

Example:

Used in: Global mode (finding relationships)

Low-Level Keywords

Purpose: Capture specific entities

Example:

Used in: Local mode (finding entities)

Why Two Levels?

Different query modes need different granularity:

  • Local mode: Needs specific entity names (Alice, Project X)

  • Global mode: Needs broader concepts (authentication, workflows)

The dual-level approach lets each mode work optimally.

Token Reduction: Why LightRAG is Efficient

Traditional RAG might need 10-20 chunks (10,000+ tokens) to answer a question. LightRAG uses entity-based retrieval to reduce this dramatically:

Traditional RAG

LightRAG (Local Mode)

How?

  1. Entity Focus: Only retrieve documents directly related to query entities

  2. Graph Pruning: Use relationships to filter irrelevant content

  3. Smart Ranking: Return most relevant results first

Real-World Example

Let's see all modes in action:

Query: "What performance issues did the team discuss last week?"

Naive Mode

Local Mode

Global Mode

Hybrid Mode

Mix Mode

When to Use Each Mode

Use Naive Mode When:

  • ✅ You know exact terms/keywords

  • ✅ Speed is critical (< 100ms)

  • ✅ Simple lookup queries

  • ❌ Don't need context or relationships

Use Local Mode When:

  • ✅ Asking about specific people/projects/concepts

  • ✅ "What is X?" or "Tell me about Y"

  • ✅ Need entity-focused results

  • ❌ Don't need broader connections

Use Global Mode When:

  • ✅ Understanding relationships and workflows

  • ✅ "How does X connect to Y?"

  • ✅ Need big-picture context

  • ❌ Don't need specific details

Use Hybrid Mode When:

  • ✅ Complex multi-part questions

  • ✅ Need both details and connections

  • ✅ Unsure which mode to use

  • ❌ Don't need maximum accuracy

Use Mix Mode When:

  • ✅ Accuracy is critical

  • ✅ Production applications

  • ✅ Complex, nuanced questions

  • ✅ Have reranker configured

  • ❌ Speed isn't the priority

Performance Tuning

Each mode has configurable parameters:

See Query API for full parameter reference.

Next Steps

Last updated

Was this helpful?