DlightRAG - Dual-mode multi-modal RAG service based on LightRAG
Project description
DlightRAG
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 embedding-compatible workspaces with round-robin merging
- Conversational query rewriting — Web UI rewrites follow-up messages into standalone queries via LLM
- 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
Source: docs/architecture.drawio
Quick Start with Four Interfaces
Web UI
Click the image to watch demo (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.internalinstead oflocalhostin 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 RAGServiceManager, DlightragConfig
load_dotenv() # load .env
async def main():
config = DlightragConfig()
manager = RAGServiceManager(config)
await manager.aingest(workspace="default", source_type="local", path="./docs")
result = await manager.aretrieve(query="What are the key findings?")
print(result.contexts)
result = await manager.aanswer(query="What are the key findings?")
print(result.answer)
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 via AnswerEngine |
VISION_MODEL via AnswerEngine (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_chunks→LIGHTRAG_DOC_CHUNKS,full_docs→LIGHTRAG_DOC_FULL). DlightRAG's unified mode adds avisual_chunkstable 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dlightrag-1.1.6.7.tar.gz.
File metadata
- Download URL: dlightrag-1.1.6.7.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51fac17cb68dd5c2f0decf2f4039c7aacea63c39a9cfca6cdff670d25b7699f4
|
|
| MD5 |
aa0e230775a5e8474de571d6c2efee0c
|
|
| BLAKE2b-256 |
3b30fd8ceb11d727451903095aadd69e6970ab053fe1b87db99640afff70019e
|
Provenance
The following attestation bundles were made for dlightrag-1.1.6.7.tar.gz:
Publisher:
publish.yml on hanlianlu/DlightRAG
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dlightrag-1.1.6.7.tar.gz -
Subject digest:
51fac17cb68dd5c2f0decf2f4039c7aacea63c39a9cfca6cdff670d25b7699f4 - Sigstore transparency entry: 1108313396
- Sigstore integration time:
-
Permalink:
hanlianlu/DlightRAG@8eed66b8d5583fb11403993cf572867d24b2fbed -
Branch / Tag:
refs/tags/v1.1.6.7 - Owner: https://github.com/hanlianlu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8eed66b8d5583fb11403993cf572867d24b2fbed -
Trigger Event:
push
-
Statement type:
File details
Details for the file dlightrag-1.1.6.7-py3-none-any.whl.
File metadata
- Download URL: dlightrag-1.1.6.7-py3-none-any.whl
- Upload date:
- Size: 180.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d41819bb065523a55b2151d36ac7bf1ec4706993c243751835c9fb4f92ed8ded
|
|
| MD5 |
09b4374d00dd823efe3b982c6c748a4e
|
|
| BLAKE2b-256 |
3578e496fbea86ab3b963132862b69ca000546c0feb90cb77d070fb4dc755c97
|
Provenance
The following attestation bundles were made for dlightrag-1.1.6.7-py3-none-any.whl:
Publisher:
publish.yml on hanlianlu/DlightRAG
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dlightrag-1.1.6.7-py3-none-any.whl -
Subject digest:
d41819bb065523a55b2151d36ac7bf1ec4706993c243751835c9fb4f92ed8ded - Sigstore transparency entry: 1108313400
- Sigstore integration time:
-
Permalink:
hanlianlu/DlightRAG@8eed66b8d5583fb11403993cf572867d24b2fbed -
Branch / Tag:
refs/tags/v1.1.6.7 - Owner: https://github.com/hanlianlu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8eed66b8d5583fb11403993cf572867d24b2fbed -
Trigger Event:
push
-
Statement type: