# dlozf/lightrag architecture

> Architecture diagram of the GitHub repository dlozf/lightrag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dlozf/lightrag
- Repository: https://github.com/dlozf/lightrag

## Overview

LightRAG is a retrieval-augmented generation system that turns uploaded or submitted documents into searchable knowledge and answers user queries from that knowledge. The main workflow is document intake, parsing and chunking, pipeline scheduling and extraction, storage, then query retrieval and LLM response; the API and WebUI expose document, query, and graph-visualization capabilities. Storage backends and model providers are pluggable. The source excerpts show only parts of this system, so links to unsampled implementation details are omitted or marked unverified.

Main entry points: [`lightrag/pipeline.py`](https://github.com/dlozf/lightrag/blob/main/lightrag/pipeline.py) (Ingestion pipeline), [`lightrag/lightrag.py`](https://github.com/dlozf/lightrag/blob/main/lightrag/lightrag.py) (LightRAG engine), [`lightrag_webui/src/features/DocumentManager.tsx`](https://github.com/dlozf/lightrag/blob/main/lightrag_webui/src/features/DocumentManager.tsx) (WebUI), [`lightrag/api/routers/document_routes.py`](https://github.com/dlozf/lightrag/blob/main/lightrag/api/routers/document_routes.py) (Document API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interfaces"]
  node_webui["WebUI"]
  node_api_docs["Document API<br/>[document_routes.py]"]
  node_api_query["Query API<br/>[query_routes.py]"]
  node_api_graph["Graph API<br/>[graph_routes.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_parser["Document parsing<br/>[routing.py]"]
  node_external_parsers["External parsers<br/>[_common.py]"]
  node_chunker["Text chunking<br/>[registry.py]"]
  node_pipeline["Ingestion pipeline<br/>[pipeline.py]"]
  node_ingress["Pipeline ingress"]
  node_pipeline_state["Pipeline coordination<br/>[shared_storage.py]"]
end

subgraph group_knowledge["Knowledge and retrieval"]
  node_rag["LightRAG engine<br/>[lightrag.py]"]
  node_operations["RAG operations<br/>[operate.py]"]
  node_query_settings["Query validation"]
end

subgraph group_platform["Storage and models"]
  node_storage_contracts["Storage contracts<br/>[base.py]"]
  node_storage_factory["Storage factory<br/>[factory.py]"]
  node_storage_backends[("Storage backends<br/>[opensearch_impl.py]")]
  node_llm_providers["LLM providers<br/>[openai.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_webui
node_webui -.->|"manages documents"| node_api_docs
node_webui -.->|"submits queries"| node_api_query
node_webui -->|"views graph"| node_api_graph
node_user -->|"submits documents"| node_api_docs
node_user -->|"queries knowledge"| node_api_query
node_api_docs -->|"manages"| node_rag
node_api_docs -->|"enqueues work"| node_pipeline
node_pipeline -->|"routes parsing"| node_parser
node_parser -.->|"uses shared parsing"| node_external_parsers
node_pipeline -->|"selects chunker"| node_chunker
node_pipeline -->|"signals documents"| node_ingress
node_pipeline -->|"coordinates state"| node_pipeline_state
node_pipeline_state -->|"provides ingress"| node_ingress
node_rag -->|"mixes in"| node_pipeline
node_api_query -->|"validates query"| node_query_settings
node_api_query -.->|"runs query"| node_rag
node_rag -.->|"delegates RAG work"| node_operations
node_rag -.->|"configures storage"| node_storage_factory
node_storage_factory -.->|"selects backend"| node_storage_backends
node_storage_backends -->|"implements contracts"| node_storage_contracts
node_operations -.->|"calls model"| node_llm_providers
node_api_graph -.->|"reads knowledge graph"| node_rag

click node_webui "https://github.com/dlozf/lightrag/blob/main/lightrag_webui/src/features/DocumentManager.tsx"
click node_api_docs "https://github.com/dlozf/lightrag/blob/main/lightrag/api/routers/document_routes.py"
click node_api_query "https://github.com/dlozf/lightrag/blob/main/lightrag/api/routers/query_routes.py"
click node_api_graph "https://github.com/dlozf/lightrag/blob/main/lightrag/api/routers/graph_routes.py"
click node_parser "https://github.com/dlozf/lightrag/blob/main/lightrag/parser/routing.py"
click node_external_parsers "https://github.com/dlozf/lightrag/blob/main/lightrag/parser/external/_common.py"
click node_chunker "https://github.com/dlozf/lightrag/blob/main/lightrag/chunker/registry.py"
click node_pipeline "https://github.com/dlozf/lightrag/blob/main/lightrag/pipeline.py"
click node_ingress "https://github.com/dlozf/lightrag/blob/main/lightrag/kg/pipeline_ingress.py"
click node_pipeline_state "https://github.com/dlozf/lightrag/blob/main/lightrag/kg/shared_storage.py"
click node_rag "https://github.com/dlozf/lightrag/blob/main/lightrag/lightrag.py"
click node_operations "https://github.com/dlozf/lightrag/blob/main/lightrag/operate.py"
click node_query_settings "https://github.com/dlozf/lightrag/blob/main/lightrag/query_validation.py"
click node_storage_contracts "https://github.com/dlozf/lightrag/blob/main/lightrag/base.py"
click node_storage_factory "https://github.com/dlozf/lightrag/blob/main/lightrag/kg/factory.py"
click node_storage_backends "https://github.com/dlozf/lightrag/blob/main/lightrag/kg/opensearch_impl.py"
click node_llm_providers "https://github.com/dlozf/lightrag/blob/main/lightrag/llm/openai.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_webui,node_api_docs,node_api_query,node_api_graph,node_user toneBlue
class node_parser,node_external_parsers,node_chunker,node_pipeline,node_ingress,node_pipeline_state toneAmber
class node_rag,node_operations,node_query_settings toneMint
class node_storage_contracts,node_storage_factory,node_storage_backends,node_llm_providers toneRose
```

## Components

### User interfaces

- [WebUI](https://github.com/dlozf/lightrag/blob/main/lightrag_webui/src/features/DocumentManager.tsx): `lightrag_webui/src/features/DocumentManager.tsx`
- [Document API](https://github.com/dlozf/lightrag/blob/main/lightrag/api/routers/document_routes.py): `lightrag/api/routers/document_routes.py`
- [Query API](https://github.com/dlozf/lightrag/blob/main/lightrag/api/routers/query_routes.py): `lightrag/api/routers/query_routes.py`
- [Graph API](https://github.com/dlozf/lightrag/blob/main/lightrag/api/routers/graph_routes.py): `lightrag/api/routers/graph_routes.py`

### Document ingestion

- [Document parsing](https://github.com/dlozf/lightrag/blob/main/lightrag/parser/routing.py): `lightrag/parser/routing.py`
- [External parsers](https://github.com/dlozf/lightrag/blob/main/lightrag/parser/external/_common.py): `lightrag/parser/external/_common.py`
- [Text chunking](https://github.com/dlozf/lightrag/blob/main/lightrag/chunker/registry.py): `lightrag/chunker/registry.py`
- [Ingestion pipeline](https://github.com/dlozf/lightrag/blob/main/lightrag/pipeline.py): `lightrag/pipeline.py`
- [Pipeline ingress](https://github.com/dlozf/lightrag/blob/main/lightrag/kg/pipeline_ingress.py): `lightrag/kg/pipeline_ingress.py`
- [Pipeline coordination](https://github.com/dlozf/lightrag/blob/main/lightrag/kg/shared_storage.py): `lightrag/kg/shared_storage.py`

### Knowledge and retrieval

- [LightRAG engine](https://github.com/dlozf/lightrag/blob/main/lightrag/lightrag.py): `lightrag/lightrag.py`
- [RAG operations](https://github.com/dlozf/lightrag/blob/main/lightrag/operate.py): `lightrag/operate.py`
- [Query validation](https://github.com/dlozf/lightrag/blob/main/lightrag/query_validation.py): `lightrag/query_validation.py`

### Storage and models

- [Storage contracts](https://github.com/dlozf/lightrag/blob/main/lightrag/base.py): `lightrag/base.py`
- [Storage factory](https://github.com/dlozf/lightrag/blob/main/lightrag/kg/factory.py): `lightrag/kg/factory.py`
- [Storage backends](https://github.com/dlozf/lightrag/blob/main/lightrag/kg/opensearch_impl.py): `lightrag/kg/opensearch_impl.py`
- [LLM providers](https://github.com/dlozf/lightrag/blob/main/lightrag/llm/openai.py): `lightrag/llm/openai.py`

### Other components

- **User**

## Connections

- User → WebUI: uses (evidence: `README.md`)
- WebUI → Document API: manages documents
- WebUI → Query API: submits queries
- WebUI → Graph API: views graph (evidence: `README.md`)
- User → Document API: submits documents (evidence: `README.md`)
- User → Query API: queries knowledge (evidence: `README.md`)
- Document API → LightRAG engine: manages (evidence: `lightrag/api/routers/document_routes.py`)
- Document API → Ingestion pipeline: enqueues work (evidence: `lightrag/api/routers/document_routes.py`)
- Ingestion pipeline → Document parsing: routes parsing (evidence: `lightrag/pipeline.py`)
- Document parsing → External parsers: uses shared parsing
- Ingestion pipeline → Text chunking: selects chunker (evidence: `lightrag/pipeline.py`)
- Ingestion pipeline → Pipeline ingress: signals documents (evidence: `lightrag/kg/pipeline_ingress.py`)
- Ingestion pipeline → Pipeline coordination: coordinates state (evidence: `lightrag/pipeline.py`)
- Pipeline coordination → Pipeline ingress: provides ingress (evidence: `lightrag/kg/shared_storage.py`)
- LightRAG engine → Ingestion pipeline: mixes in (evidence: `lightrag/pipeline.py`)
- Query API → Query validation: validates query (evidence: `lightrag/api/routers/query_routes.py`)
- Query API → LightRAG engine: runs query
- LightRAG engine → RAG operations: delegates RAG work
- LightRAG engine → Storage factory: configures storage
- Storage factory → Storage backends: selects backend
- Storage backends → Storage contracts: implements contracts (evidence: `lightrag/kg/opensearch_impl.py`)
- RAG operations → LLM providers: calls model
- Graph API → LightRAG engine: reads knowledge graph
