Skip to main content

DlightRAG - Dual-mode multi-modal RAG service based on LightRAG

Project description

DlightRAG

PyPI CI

Dual-mode multimodal RAG built on LightRAG — knowledge graph + vector retrieval as a modern and unified production-ready service.

Features

  • Dual multimodal RAG modes — Caption mode (parse → caption → embed) for pipeline based multimodal paradigm; Unified mode (render → multimodal embed) for modern multimodal paradigm
  • Knowledge graph + vector retrieval — Fusional search based on LightRAG's foundation
  • Multimodal ingestion — PDF, Word, Excel, PowerPoint, images, etc.
  • Reranking — Generic LLM-based list/point-wise; Specialized rerankers support from Cohere, Jina, Aliyun, Azure Cohere; Support any additional backend via custom endpoint
  • Cross-workspace federation — Query across workspaces with round-robin merging
  • Citation and highlighter — Answer / Retrieved contexts with source, page, citation, highlighting attribution.
  • Flexible sourcing — Local filesystem, Azure Blob Storage, Snowflake
  • Four interfaces — Web UI, REST API, MCP server, and Python SDK

Architecture

DlightRAG Architecture

Source: docs/architecture.drawio

Quick Start with Four Interfaces

Web UI

Click the image to watch demo (YouTube)
Watch Demo on YouTube

If you already have the REST API running (via Docker or dlightrag-api), the Web UI is available at:

http://localhost:8100/web/

Without Docker:

uv add dlightrag        # or: pip install dlightrag
cp .env.example .env    # edit .env — at minimum set DLIGHTRAG_OPENAI_API_KEY
dlightrag-api --env-file .env

Docker (Self-Hosted)

git clone https://github.com/hanlianlu/dlightrag.git && cd dlightrag
cp .env.example .env    # edit .env — at minimum set DLIGHTRAG_OPENAI_API_KEY
docker compose up

Includes PostgreSQL (pgvector + AGE), REST API (:8100), and MCP server (:8101).

Local models (Ollama, Xinference, etc.): use host.docker.internal instead of localhost in base URL settings.

curl http://localhost:8100/health

curl -X POST http://localhost:8100/ingest \
  -H "Content-Type: application/json" \
  -d '{"source_type": "local", "path": "/app/dlightrag_storage/sources"}'

curl -X POST http://localhost:8100/retrieve \
  -H "Content-Type: application/json" \
  -d '{"query": "What are the key findings?"}'

curl -X POST http://localhost:8100/answer \
  -H "Content-Type: application/json" \
  -d '{"query": "What are the key findings?", "stream": true}'

MCP Server (for AI Agents)

uv tool install dlightrag   # or: pip install dlightrag
cp .env.example .env        # edit .env — at minimum set DLIGHTRAG_OPENAI_API_KEY
dlightrag-mcp --env-file .env
{
  "mcpServers": {
    "dlightrag": {
      "command": "uvx",
      "args": ["dlightrag-mcp", "--env-file", "/absolute/path/to/.env"]
    }
  }
}

Tools: retrieve, answer, ingest, list_files, delete_files, list_workspaces — all with workspace isolation.

Python SDK

uv add dlightrag        # or: pip install dlightrag
cp .env.example .env    # edit .env — at minimum set DLIGHTRAG_OPENAI_API_KEY
import asyncio
from dotenv import load_dotenv
from dlightrag import RAGService, DlightragConfig

load_dotenv()  # load .env

async def main():
    config = DlightragConfig()
    service = await RAGService.create(config=config)

    await service.aingest(source_type="local", path="./docs")

    result = await service.aretrieve(query="What are the key findings?")
    print(result.contexts)

    result = await service.aanswer(query="What are the key findings?")
    print(result.answer)

    await service.close()

asyncio.run(main())

Requires PostgreSQL with pgvector + AGE, or JSON fallback for development (see Configuration).

API Reference

Request and response structures for ingest, retrieve, and answer across all interfaces. See docs/response-schema.md for the full reference — ingestion parameters, retrieval contexts, sources, media, SSE streaming, citations, and multimodal queries.

Configuration

All settings via DLIGHTRAG_ env vars, .env file, or constructor args. See .env.example for the full reference.

Priority: constructor args > env vars > .env file > defaults

RAG Mode

The first decision — determines your ingestion pipeline, model requirements, and retrieval behavior.

Mode Pipeline Best for
caption (default) Document parsing → VLM captioning → text embedding → KG Text-heavy documents, structured elements
unified Page rendering → multimodal embedding → VLM entity extraction → KG Visually rich documents (charts, diagrams, complex layouts)

Caption mode parsers (DLIGHTRAG_PARSER):

Parser Description
mineru (default) MinerU PDF parser — fast, good for text-heavy documents
docling Docling parser — alternative structure-aware parser
vlm VLM-based OCR — renders pages and uses vision model to extract structured content; no external parser dependency, requires VISION_MODEL

All caption mode parsers use Docling's HybridChunker for structure-aware chunking.

Model usage by stage:

Stage Caption Unified
Image captioning VISION_MODEL ¹ VISION_MODEL
Table / equation captioning CHAT_MODEL
Entity extraction CHAT_MODEL CHAT_MODEL
Embedding EMBEDDING_MODEL EMBEDDING_MODEL (multimodal)
Rerank RERANK_* via LightRAG VISION_MODEL ² or RERANK_* API
Answer generation CHAT_MODEL VISION_MODEL (sees page images)

¹ Falls back to CHAT_MODEL if vision model not configured. ² When RERANK_BACKEND=llm (pointwise VLM scoring).

For unified mode, set DLIGHTRAG_RAG_MODE=unified and point embedding/vision at multimodal models:

DLIGHTRAG_RAG_MODE=unified
DLIGHTRAG_EMBEDDING_MODEL=Qwen3-VL-Embedding    # must be multimodal
DLIGHTRAG_EMBEDDING_DIM=4096
DLIGHTRAG_VISION_MODEL=qwen3-vl-32b

Limitations: Snowflake is text-only (no visual embedding). A workspace is locked to one mode after first ingestion. Page images ~3-7 MB/page at 250 DPI.

Providers

Variable Default Description
DLIGHTRAG_LLM_PROVIDER openai openai, azure_openai, anthropic, google_gemini, qwen, minimax, xinference, openrouter, ollama, voyage
DLIGHTRAG_EMBEDDING_PROVIDER (follows llm_provider) Override embedding provider
DLIGHTRAG_VISION_PROVIDER (follows llm_provider) Override vision provider
DLIGHTRAG_EMBEDDING_MODEL text-embedding-3-large Embedding model

Each provider uses its own API key. For Ollama, use openai provider with DLIGHTRAG_OPENAI_BASE_URL pointing to Ollama.

Storage Backends

Variable Default Options
DLIGHTRAG_VECTOR_STORAGE PGVectorStorage PGVectorStorage, MilvusVectorDBStorage, NanoVectorDBStorage, ...
DLIGHTRAG_GRAPH_STORAGE PGGraphStorage PGGraphStorage, Neo4JStorage, NetworkXStorage, ...
DLIGHTRAG_KV_STORAGE PGKVStorage PGKVStorage, JsonKVStorage, RedisKVStorage, ...
DLIGHTRAG_DOC_STATUS_STORAGE PGDocStatusStorage PGDocStatusStorage, JsonDocStatusStorage, ...

Note: When using PostgreSQL backends, LightRAG maps its internal namespace names to different table names (e.g. text_chunksLIGHTRAG_DOC_CHUNKS, full_docsLIGHTRAG_DOC_FULL). DlightRAG's unified mode adds a visual_chunks table via its own KV storage.

Workspaces

Each workspace has its own knowledge graph, vector store, and document index. DLIGHTRAG_WORKSPACE (default: default) is automatically bridged to backend-specific env vars — no manual setup needed.

Backend type Isolation mechanism
PostgreSQL (PG*) workspace column / graph name in same database
Neo4j / Memgraph Label prefix
Milvus / Qdrant Collection prefix
MongoDB / Redis Collection scope
JSON / Nano / NetworkX / Faiss Subdirectory under working_dir/<workspace>/

Reranking

Variable Default Description
DLIGHTRAG_RERANK_BACKEND llm llm, cohere, jina, aliyun, azure_cohere
DLIGHTRAG_RERANK_MODEL (backend default) Model name sent to the endpoint
DLIGHTRAG_RERANK_BASE_URL (provider default) Custom endpoint URL for any compatible service
DLIGHTRAG_RERANK_API_KEY API key (falls back to provider-specific keys)
Backend Default model Key
llm (follows CHAT_MODEL) (follows LLM_PROVIDER)
cohere rerank-v4.0-pro DLIGHTRAG_COHERE_API_KEY
jina jina-reranker-v3 DLIGHTRAG_JINA_API_KEY
aliyun qwen3-rerank DLIGHTRAG_ALIYUN_RERANK_API_KEY
azure_cohere Cohere-rerank-v4.0-pro DLIGHTRAG_AZURE_COHERE_API_KEY

Point any backend at a local reranker (Xinference, LiteLLM, etc.) via RERANK_BASE_URL + RERANK_MODEL.

REST API

Method Endpoint Description
POST /ingest Ingest from local, Azure Blob, or Snowflake
POST /retrieve Contexts + sources (no LLM answer)
POST /answer LLM answer + contexts + sources (stream: true for SSE)
GET /files List ingested documents
DELETE /files Delete documents
GET /api/files/{path} Serve/download a file (local: stream, Azure: 302 SAS redirect)
GET /workspaces List available workspaces
GET /health Health check with storage status

All write endpoints accept optional workspace; read endpoints accept workspaces list for cross-workspace federated search. Set DLIGHTRAG_API_AUTH_TOKEN to enable bearer auth.

Development

git clone https://github.com/hanlianlu/dlightrag.git && cd dlightrag
cp .env.example .env && uv sync
docker compose up -d                # PostgreSQL + API + MCP
docker compose up postgres -d       # PostgreSQL only
uv run pytest tests/unit            # unit tests (no external services)
uv run pytest tests/integration     # integration tests (requires PostgreSQL)
uv run ruff check src/ tests/ scripts/ --fix && uv run ruff format src/ tests/ scripts/

License

Apache License 2.0 — see LICENSE.


Built by HanlianLyu. Contributions welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dlightrag-1.1.6.3.tar.gz (833.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dlightrag-1.1.6.3-py3-none-any.whl (156.0 kB view details)

Uploaded Python 3

File details

Details for the file dlightrag-1.1.6.3.tar.gz.

File metadata

  • Download URL: dlightrag-1.1.6.3.tar.gz
  • Upload date:
  • Size: 833.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dlightrag-1.1.6.3.tar.gz
Algorithm Hash digest
SHA256 0f1620b6a9e5a6133401c6001c5aa8ba23ccd5c0c6103be0ba8e3d4ed27d6bd7
MD5 b94d37a43910060683841053b4270315
BLAKE2b-256 48620092c0eaabc31ed848f489c857d993968e2529faf59c3b2b71ae558bb2c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dlightrag-1.1.6.3.tar.gz:

Publisher: publish.yml on hanlianlu/DlightRAG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dlightrag-1.1.6.3-py3-none-any.whl.

File metadata

  • Download URL: dlightrag-1.1.6.3-py3-none-any.whl
  • Upload date:
  • Size: 156.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dlightrag-1.1.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 654b87422195a61bb090fb28f4efed2e366122cd69d5d335383a99a8a14cf452
MD5 1a318b08b1a7ff7b9774d8e812358f7d
BLAKE2b-256 05c93cdb0fc5d06fb80370e1113ca34791f7c157c0d7176be83c0a77075f6e67

See more details on using hashes here.

Provenance

The following attestation bundles were made for dlightrag-1.1.6.3-py3-none-any.whl:

Publisher: publish.yml on hanlianlu/DlightRAG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page