Skip to main content
Context Management
Knowledge Backends
Configure and use different knowledge storage backends in PraisonAI
Choose the right storage backend for your knowledge base — from local development with Chroma to multi-tenant production with mem0.
The user asks a question; the agent retrieves from mem0, Chroma, or a custom knowledge store you configured.
You can also use the direct API for more control:
Direct API — same scope keywords:
On Atlas
Knowledge stores that interpolate collection names into DDL/DML now require collection names to match
Register before the first
Confirm which adapter you actually got:
How It Works
Quick Start
1
Simple — enable with True
2
With backend config
Available Backends
Scope Identifiers
Knowledge backends support three scope identifiers for multi-tenant isolation:Example with Scope
Combining Multiple Scopes
Combineuser_id, agent_id, and run_id to isolate knowledge down to a specific session for a specific agent and user.
When you pass more than one scope identifier, PraisonAI automatically combines them using ChromaDB’s
$and operator. A single identifier is passed through unchanged. You don’t need to write the $and yourself.MongoDB backend
The MongoDB knowledge adapter honors the sameuser_id / agent_id / run_id scope on add() and search().
$vectorSearch, the scope is injected as the stage-level filter; on the text-search fallback, it is merged into the find() query. Only provided scopes are applied — omit an identifier to broaden the search on that dimension.
Multi-tenant SaaS application flow:
- Per-customer isolation → set
user_id - Per-agent isolation (e.g. SupportBot vs. SalesBot share infra but not data) → also set
agent_id - Per-conversation isolation (e.g. ephemeral session memory) → also set
run_id
Direct Knowledge API
For advanced use cases, you can use the Knowledge class directly:Normalization Guarantees
PraisonAI normalizes all backend results to ensure consistent behavior:- metadata is ALWAYS a dict (never
None) - text field is always present (mapped from
memoryfor mem0) - score is always a float (defaults to 0.0)
Protocol-Driven Architecture
All backends implement theKnowledgeStoreProtocol:
Supported Providers
Setvector_store.provider to any name below. The value resolves through the Knowledge adapter registry.
qdrant, pgvector, milvus, and pinecone are not top-level Knowledge providers. They are inner backends of mem0. Set provider: "mem0" and place the store name inside mem0’s nested config — see mem0 Backend below.Configuration Options
mem0 Backend (Default)
Top-levelprovider is mem0; qdrant, pgvector, and similar stores live inside mem0’s nested config.
Chroma Backend
path is optional. Omit it and the store persists under an absolute per-project directory: <project>/.praisonai/knowledge/chroma. The store is isolated per project, so multiple projects (or Windows setups) never share one on-disk sqlite.
Error Handling
Collection Naming Rules
Enhanced Security (PR #1597): Knowledge stores now validate collection names to prevent SQL injection attacks.
^[A-Za-z0-9_]+$. Affected backends:
- Cassandra
- pgvector
- SingleStore vector
ValueError("collection_name must be non-empty and contain only alphanumerics and underscores")
Valid examples:
my_collectionUserData123agent_v2_docs
my-collection(contains hyphen)user.docs(contains dot)data collection(contains space)../../etc(path traversal attempt)
Best Practices
Always provide scope identifiers for mem0
Always provide scope identifiers for mem0
The mem0 backend requires at least one scope identifier. Without it, operations raise
ScopeRequiredError.Use alphanumeric collection names
Use alphanumeric collection names
Collection names must match
^[A-Za-z0-9_]+$ for backends that use DDL/DML (Cassandra, pgvector, SingleStore).Valid: my_collection, UserData123. Invalid: my-collection, user.docs.Prefer Agent API over direct Knowledge API
Prefer Agent API over direct Knowledge API
The Agent API handles scoping, retrieval, and context injection automatically. Use the direct
Knowledge class only when you need custom control over indexing or search.Implement KnowledgeStoreProtocol for custom backends
Implement KnowledgeStoreProtocol for custom backends
Any class implementing
KnowledgeStoreProtocol works as a backend — no base class inheritance needed.Extension: Custom Adapters
Register your own backend under any provider name, then reach it throughvector_store.provider.
Agent(...) or Knowledge(...) call reads .memory. See Custom Knowledge Adapters for the full protocol contract and registration API.
Behaviour on Unknown Provider
An explicitly-configured provider that isn’t a built-in adapter and hasn’t been registered raisesValueError.
Shipped vs Plugin Providers
Top-levelvector_store.provider accepts only providers with a registered Knowledge adapter.
qdrant, pgvector, milvus, and pinecone also work as inner backends of mem0 without registration — set provider: "mem0" and nest the store under mem0’s own config. See mem0 Backend.Related
Incremental Indexing
Skip unchanged files for fast knowledge base updates
Knowledge
Core knowledge retrieval and agent integration
Vector Store
Store and query embeddings with a pluggable, namespace-aware backend


