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.- 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:
Configuration Options
mem0 Backend (Default)
Chroma Backend
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.Troubleshooting: silent SQLite fallback
Configure amem0 or mongodb vector store on a release before 2026-07-14 and get keyword-style results instead of semantic ones? Your Knowledge instance was likely degraded to SQLite without warning. The adapter constructors rejected an internal verbose keyword, and the resulting TypeError was swallowed at debug level (PR #2982 fixes it).
Confirm which adapter you actually got:
Mem0Adapter / MongoDBKnowledgeAdapter, upgrade to a release built after commit 69d7ecf. On the fixed release, an explicitly-configured provider that fails to construct emits a WARNING. The exact message to look for:
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

