LightRAG Storage Backends: Complete Guide to KV, Vector, Graph, and Doc Status

LightRAG supports 24 production-ready storage backends across four persistence layers—key-value, vector, graph, and document-status data—utilizing a plug-in architecture that enables mixing JSON files, Redis, PostgreSQL, MongoDB, Neo4j, OpenSearch, and other databases.

The HKUDS/LightRAG repository decouples data persistence from retrieval logic through abstract base classes defined in lightrag/base.py. This modular design allows developers to configure independent storage backends for each layer, swapping file-based solutions for enterprise databases as deployment requirements evolve.

KV Storage Backends

LightRAG provides five concrete implementations for key-value storage, handling raw text chunks, LLM cache, and entity data:

All KV backends inherit from BaseKVStorage and implement standardized methods including get_by_id, upsert, and delete.

Vector Storage Backends

Eight backends support embedding vector persistence for similarity search, ranging from local file indices to distributed vector databases:

These classes extend BaseVectorStorage and provide query methods for approximate nearest neighbor search.

Graph Storage Backends

Six graph storage implementations manage knowledge-graph nodes and edges using undirected graph structures:

Graph backends inherit from BaseGraphStorage and expose methods for node insertion, edge creation, and graph traversal.

Document Status Storage Backends

Five backends track per-document processing state, including chunk lists, metadata, and pipeline status:

These extend DocStatusStorage and maintain processing state across document ingestion pipelines.

How to Initialize Storage Backends

Instantiate any storage class by importing from its implementation module and passing the standard constructor arguments defined in the base classes:

from lightrag.kg.json_kv_impl import JsonKVStorage
from lightrag.kg.faiss_impl import FaissVectorDBStorage
from lightrag.kg.networkx_impl import NetworkXStorage
from lightrag.kg.json_doc_status_impl import JsonDocStatusStorage

# Initialize JSON-backed KV storage

kv = JsonKVStorage(
    namespace="text_chunks",
    embedding_func=my_embed,
    global_config={"working_dir": "./data"},
    workspace="my_project",
)

# Initialize Faiss vector storage

vector = FaissVectorDBStorage(
    namespace="text_chunks",
    embedding_func=my_embed,
    global_config={"working_dir": "./data"},
    workspace="my_project",
)

# Initialize NetworkX graph storage

graph = NetworkXStorage(
    namespace="knowledge_graph",
    embedding_func=my_embed,
    global_config={"working_dir": "./data"},
    workspace="my_project",
)

# Initialize JSON document status storage

doc_status = JsonDocStatusStorage(
    namespace="doc_status",
    embedding_func=my_embed,
    global_config={"working_dir": "./data"},
    workspace="my_project",
)

To switch backends, change only the imported class while maintaining identical initialization parameters. For example, replacing JsonKVStorage with RedisKVStorage requires updating the import statement and class name:

from lightrag.kg.redis_impl import RedisKVStorage

kv = RedisKVStorage(
    namespace="text_chunks",
    embedding_func=my_embed,
    global_config={"working_dir": "./data"},
    workspace="my_project",
)

All storage classes share common interface methods including is_empty, upsert, and get_by_id, enabling seamless backend substitution without modifying pipeline logic.

Summary

  • LightRAG provides 24 production-ready storage backends across four persistence layers: KV (5), Vector (8), Graph (6), and Document Status (5)
  • Each backend implements standardized interfaces (BaseKVStorage, BaseVectorStorage, BaseGraphStorage, DocStatusStorage) defined in lightrag/base.py
  • Database-specific implementations reside in lightrag/kg/ with dedicated modules for PostgreSQL, MongoDB, Redis, Neo4j, OpenSearch, Memgraph, Milvus, Qdrant, and others
  • Constructor signatures are uniform across all backends, allowing drop-in replacement by changing only the import statement and class name
  • ChromaVectorDBStorage is deprecated and located in lightrag/kg/deprecated/chroma_impl.py (line 20); new implementations should use FaissVectorDBStorage or database-backed alternatives

Frequently Asked Questions

Can I use different database backends for different storage layers in LightRAG?

Yes. LightRAG's modular architecture allows mixing storage technologies according to your operational needs. For example, you can configure RedisKVStorage for key-value data, MilvusVectorDBStorage for vectors, Neo4JStorage for graphs, and JsonDocStatusStorage for document status within the same pipeline instance.

Which storage backend offers the best performance for large-scale deployments?

PostgreSQL (via PGKVStorage, PGVectorStorage, PGGraphStorage, and PGDocStatusStorage) and Neo4j (via Neo4JStorage) provide the strongest consistency and query performance for high-volume transactional workloads. For specialized vector search throughput, Milvus or Qdrant typically outperform file-based alternatives in distributed environments.

How do I migrate from file-based storage to PostgreSQL?

Migration requires changing import statements from file-based implementations (e.g., JsonKVStorage) to PostgreSQL equivalents (e.g., PGKVStorage) while maintaining the same constructor arguments. You must ensure your global_config includes PostgreSQL connection parameters. The data itself requires manual migration or re-ingestion, as storage implementations do not provide automatic data transfer between backend types.

Is the Chroma vector storage still supported?

ChromaVectorDBStorage is deprecated and remains available only in lightrag/kg/deprecated/chroma_impl.py at line 20 for backward compatibility. It is not recommended for new projects. Migrate to FaissVectorDBStorage for local file-based vector storage, or to PGVectorStorage or QdrantVectorDBStorage for production database solutions.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →