Setup Vector and Graph Databases Backends for Cognee
Cognee supports multiple database backends for different storage needs. This guide covers all supported databases and their configuration methods. You can configure databases using either environment variables or Python configuration.
Overview
Cognee uses three types of databases:
- Vector Databases: Store and query embeddings for semantic search
- Graph Databases: Store knowledge graphs and relationships
- Relational Databases: Store metadata and structured data
Vector Databases
1. LanceDB (Default)
Environment Variables:
VECTOR_DB_PROVIDER=lancedb
Python Configuration:
cognee.config.set_vector_db_config({
"vector_db_provider": "lancedb"
})
2. ChromaDB
Environment Variables:
VECTOR_DB_PROVIDER=chromadb
VECTOR_DB_URL=http://localhost:8000
Python Configuration:
cognee.config.set_vector_db_config({
"vector_db_url": "http://localhost:8000",
"vector_db_provider": "chromadb"
})
Docker Setup:
# Run ChromaDB server
docker run -p 8000:8000 chromadb/chroma
3. Qdrant
Environment Variables:
VECTOR_DB_PROVIDER=qdrant
VECTOR_DB_URL=https://your-cluster-url
VECTOR_DB_KEY=your-api-key
Python Configuration:
cognee.config.set_vector_db_config({
"vector_db_url": "https://your-cluster-url",
"vector_db_key": "your-api-key",
"vector_db_provider": "qdrant"
})
4. Weaviate
Environment Variables:
VECTOR_DB_PROVIDER=weaviate
VECTOR_DB_URL=https://your-cluster.weaviate.network
VECTOR_DB_KEY=your-api-key
Python Configuration:
cognee.config.set_vector_db_config({
"vector_db_url": "https://your-cluster.weaviate.network",
"vector_db_key": "your-api-key",
"vector_db_provider": "weaviate"
})
5. Milvus
Environment Variables:
VECTOR_DB_PROVIDER=milvus
VECTOR_DB_URL=local_milvus_db_path # Or your Milvus endpoint
VECTOR_DB_KEY=your-token
Python Configuration:
import os
cognee_directory_path = "path/to/your/cognee/system"
local_milvus_db_path = os.path.join(cognee_directory_path, "databases", "milvus.db")
cognee.config.set_vector_db_config({
"vector_db_url": local_milvus_db_path, # or remote endpoint
"vector_db_key": "",
"vector_db_provider": "milvus"
})
6. PGVector (PostgreSQL)
Environment Variables:
VECTOR_DB_PROVIDER=pgvector
DB_PROVIDER=postgres
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=cognee
DB_PASSWORD=cognee
DB_NAME=cognee_db
Python Configuration:
# Configure PGVector
cognee.config.set_vector_db_config({
"vector_db_provider": "pgvector"
})
# Configure PostgreSQL connection
cognee.config.set_relational_db_config({
"db_provider": "postgres",
"db_host": ""127.0.0.1"",
"db_port": "5432",
"db_username": "cognee",
"db_password": "cognee",
"db_name": "cognee_db"
})
PostgreSQL Setup:
# Using Docker with PGVector extension
docker run -d \
--name postgres \
-e POSTGRES_USER=cognee \
-e POSTGRES_PASSWORD=cognee \
-e POSTGRES_DB=cognee_db \
-p 5432:5432 \
pgvector/pgvector:pg17
Graph Databases
1. NetworkX (Default)
Environment Variables:
GRAPH_DATABASE_PROVIDER=networkx
# Uses local file path automatically
Python Configuration:
cognee.config.set_graph_db_config({
"graph_database_provider": "networkx"
})
2. Neo4j
Environment Variables:
GRAPH_DATABASE_PROVIDER=neo4j
GRAPH_DATABASE_URL=bolt://localhost:7687
GRAPH_DATABASE_USERNAME=neo4j
GRAPH_DATABASE_PASSWORD=your-password
Python Configuration:
import os
cognee.config.set_graph_db_config({
"graph_database_url": "bolt://localhost:7687",
"graph_database_provider": "neo4j",
"graph_database_username": "neo4j",
"graph_database_password": "your-password"
})
Docker Setup:
docker run \
--name neo4j \
-p 7474:7474 -p 7687:7687 \
-e NEO4J_AUTH=neo4j/password \
neo4j:latest
3. Kuzu
Environment Variables:
GRAPH_DATABASE_PROVIDER=kuzu
Python Configuration:
cognee.config.set_graph_db_config({
"graph_database_provider": "kuzu"
})
4. FalkorDB
Environment Variables:
GRAPH_DATABASE_PROVIDER=falkordb
GRAPH_DATABASE_URL=localhost
GRAPH_DATABASE_PORT=6379
Python Configuration:
cognee.config.set_graph_db_config({
"graph_database_url": "localhost",
"graph_database_port": 6379,
"graph_database_provider": "falkordb"
})
Docker Setup:
# Run FalkorDB
docker run -p 6379:6379 falkordb/falkordb:latest
Relational Databases
1. SQLite (Default)
Environment Variables:
DB_PROVIDER=sqlite
DB_NAME=cognee_db
# DB_PATH is optional - defaults to .cognee_system/databases
Python Configuration:
cognee.config.set_relational_db_config({
"db_provider": "sqlite",
"db_name": "cognee_db"
})
2. PostgreSQL
Environment Variables:
DB_PROVIDER=postgres
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=cognee
DB_PASSWORD=cognee
DB_NAME=cognee_db
Python Configuration:
cognee.config.set_relational_db_config({
"db_provider": "postgres",
"db_host": "localhost",
"db_port": "5432",
"db_username": "cognee",
"db_password": "cognee",
"db_name": "cognee_db"
})
127.0.0.1 host is when Postgres is used in a local setting. Set DB_HOST=host.docker.internal otherwise, so Cognee docker and Postgres would be on the same network
Complete Configuration Examples
Local Setup
Environment Variables (.env file):
# Vector Database
VECTOR_DB_PROVIDER=lancedb
# Graph Database
GRAPH_DATABASE_PROVIDER=networkx
# Relational Database
DB_PROVIDER=sqlite
DB_NAME=cognee_db
### Remote Setup
**Environment Variables (.env file):**
```bash
# Vector Database - Qdrant Cloud
VECTOR_DB_PROVIDER=qdrant
VECTOR_DB_URL=https://your-cluster.qdrant
VECTOR_DB_KEY=your-api-key
# Graph Database - Neo4j Aura
GRAPH_DATABASE_PROVIDER=neo4j
GRAPH_DATABASE_URL=neo4j+s://your-instance.databases.neo4j.io
GRAPH_DATABASE_USERNAME=neo4j
GRAPH_DATABASE_PASSWORD=your-password
# Relational Database - PostgreSQL
DB_PROVIDER=postgres
DB_HOST=your-postgres-host.com
DB_PORT=5432
DB_USERNAME=cognee
DB_PASSWORD=your-password
DB_NAME=cognee_db
Installation Requirements
Some databases require additional packages. If you didn’t install cognee with all extras:
# For specific databases, check poetry extras
poetry install -E postgres -E neo4j -E kuzu
# With pip
pip install cognee[neo4j,postgres]
Multi-Tenant Setup
For isolated multi-tenant deployments, Cognee supports automatic database isolation:
Environment Variables:
ENABLE_BACKEND_ACCESS_CONTROL=true
When enabled, Cognee automatically uses:
- Kuzu for graph data (file-based isolation)
- LanceDB for vector data (file-based isolation)
This ensures complete data separation between tenants. Please note that user defined graph and vector database settings will be ignored in this case.
Next Steps
- Choose your database backends based on your requirements
- Set up the necessary infrastructure (Docker containers, cloud services)
- Install cognee with extra requirements for your database choice
- Configure Cognee using environment variables or Python configuration
- Test your setup with a simple example
- Scale your deployment as needed
For example scripts, check the /examples/database_examples/
directory in the Cognee repository.