Knowledge Backends - PraisonAI
Skip to main content
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.

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:
The mem0 backend requires at least one scope identifier. If none is provided, operations will fail with a ScopeRequiredError.
delete_all() requires a scope. The Chroma and SQLite backends now enforce the same contract as mem0: an unscoped delete_all() raises ScopeRequiredError instead of silently wiping the entire (typically shared) collection or table. Scoped deletes are unchanged.

Example with Scope

Combining Multiple Scopes

Combine user_id, agent_id, and run_id to isolate knowledge down to a specific session for a specific agent and user.
You can also use the direct API for more control:
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 same user_id / agent_id / run_id scope on add() and search().
Direct API — same scope keywords:
On Atlas $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.
All provided identifiers are required to match (logical AND). Omit an identifier to broaden the scope 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 memory for mem0)
  • score is always a float (defaults to 0.0)
This means you can safely access metadata without null checks:

Protocol-Driven Architecture

All backends implement the KnowledgeStoreProtocol:

Supported Providers

Set vector_store.provider to any name below. The value resolves through the Knowledge adapter registry.
Setting vector_store.provider to a name that isn’t a built-in adapter and hasn’t been registered raises ValueError with the list of valid names. This is intentional — the old behaviour silently ran on Mem0, hiding typos and custom-adapter bugs. The implicit default (omit vector_store entirely) still falls back to Mem0.Explicit falsey values ("" or None) raise too. Only the missing-config default is silent.
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-level provider 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.
A corrupt or cross-project Chroma store raises RuntimeError: Chroma persist failed at '<path>' (PanicException: ...) instead of crashing the process. Delete <path> and re-index, or point path at a fresh directory. See Knowledge Storage.

Error Handling

Collection Naming Rules

Enhanced Security (PR #1597): Knowledge stores now validate collection names to prevent SQL injection attacks.
Knowledge stores that interpolate collection names into DDL/DML now require collection names to match ^[A-Za-z0-9_]+$. Affected backends:
  • Cassandra
  • pgvector
  • SingleStore vector
Invalid names raise: ValueError("collection_name must be non-empty and contain only alphanumerics and underscores") Valid examples:
  • my_collection
  • UserData123
  • agent_v2_docs
Invalid examples:
  • my-collection (contains hyphen)
  • user.docs (contains dot)
  • data collection (contains space)
  • ../../etc (path traversal attempt)

Best Practices

The mem0 backend requires at least one scope identifier. Without it, operations raise ScopeRequiredError.
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.
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.
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 through vector_store.provider.
Register before the first 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 raises ValueError.
Confirm which adapter you actually got:
Explicit "" and None raise as well. Only the implicit default (omit vector_store entirely) silently falls back to Mem0 with a debug log — the raise catches typos and custom-adapter registration bugs early.

Shipped vs Plugin Providers

Top-level vector_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.

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