Knowledge CLI

CLI commands for knowledge base management

Knowledge CLI Commands

The praisonai knowledge command group provides CLI access to knowledge base management.

Commands Overview

CommandDescription
indexAdd/index documents into a knowledge base
searchSearch/retrieve from knowledge base
addAlias for index
listList available knowledge bases

Index Command

Add documents to a knowledge base.

bash
praisonai knowledge index [OPTIONS] SOURCES...

Arguments

ArgumentDescription
SOURCESSource files, directories, or URLs to index (required)

Options

OptionShortDescriptionDefault
--collection-cCollection/knowledge base namedefault
--user-id-uUser ID for scoping (required for mem0)None
--agent-id-aAgent ID for scopingNone
--run-id-rRun ID for scopingNone
--backend-bKnowledge backend: mem0, chroma, internalmem0
--config-fConfig file pathNone
--verbose-vVerbose outputFalse
--profileEnable performance profilingFalse
--profile-outSave profile to JSON fileNone

Examples

bash
# Index a directory with user scope
praisonai knowledge index ./docs --user-id myuser

# Index with specific collection and agent scope
praisonai knowledge index paper.pdf --collection research --agent-id research_agent

# Index using chroma backend
praisonai knowledge index ./data --backend chroma

# Index with profiling
praisonai knowledge index ./docs --user-id myuser --profile --profile-out ./profile.json
bash
# When embedding fails (e.g. bad OPENAI_API_KEY or wrong model), the index
# command now exits with a non-zero status so shell pipelines can detect it:
$ praisonai knowledge index ./docs --user-id myuser
✗ Failed to index ./docs: no chunks stored (no supported files found, or content could not be extracted)

Indexing failed for 1 of 1 source(s). Collection: default
$ echo $?
1

Exit Codes

CodeMeaning
0Every source produced at least one stored chunk.
1One or more sources produced no chunks — check the per-source ✗ lines above the summary. Common causes: unsupported file types in the directory, unreadable content, or an embedding failure (see Troubleshooting).

Chain commands with praisonai knowledge index … && … to run the next step only when every source indexes successfully.

Search Command

Search/retrieve from a knowledge base without LLM generation.

bash
praisonai knowledge search [OPTIONS] QUERY

Arguments

ArgumentDescription
QUERYSearch query (required)

Options

OptionShortDescriptionDefault
--collection-cCollection to searchdefault
--user-id-uUser ID for scoping (required for mem0)None
--agent-id-aAgent ID for scopingNone
--run-id-rRun ID for scopingNone
--backend-bKnowledge backend: mem0, chroma, internalmem0
--top-k-kNumber of results to retrieve5
--hybridUse hybrid retrieval (dense + BM25)False
--config-fConfig file pathNone
--verbose-vVerbose outputFalse
--profileEnable performance profilingFalse

Examples

bash
# Basic search with user scope
praisonai knowledge search "capital of France" --user-id myuser

# Search specific collection with more results
praisonai knowledge search "main findings" --collection research --top-k 10

# Hybrid search using chroma backend
praisonai knowledge search "Python tutorial" --hybrid --backend chroma

# Search with agent scope
praisonai knowledge search "company policy" --agent-id company_bot

Output

Results print as a Rich table with #, Score, Source, and Content columns:

┏━━━┳━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ # ┃ Score ┃ Source        ┃ Content                            ┃
┡━━━╇━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │ 0.95  │ geography.txt │ Paris is the capital of France.    │
│ 2 │ 0.82  │ europe.md     │ France is a country in Europe.     │
└───┴───────┴───────────────┴────────────────────────────────────┘

When nothing matches, the command prints:

No results found.

If search consistently returns No results found. for content you just indexed, the embedding call likely failed silently on an older build. Upgrade to the latest release (PR #2823), where indexing errors exit non-zero and print ✗ Failed to index …. See Troubleshooting.

Result normalisation

The CLI accepts results from all three backend return shapes — a typed SearchResult, a legacy dict with a "results" key, or a plain list. Custom backends don’t have to pick one format; the command normalises them all before display.

See Search Results for the SearchResult shape and how to consume it from Python.

List Command

List available knowledge bases/collections.

bash
praisonai knowledge list [OPTIONS]

Options

OptionShortDescriptionDefault
--verbose-vVerbose outputFalse

Example

bash
praisonai knowledge list

Output:

┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Collection   ┃ Path                              ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ default      │ ./.praison/knowledge/default      │
│ research     │ ./.praison/knowledge/research     │
└──────────────┴───────────────────────────────────┘

Scope Identifiers

When to Use Each Scope

ScopeUse CaseExample
--user-idPer-user knowledge isolationMulti-tenant apps
--agent-idShared agent knowledgeCompany FAQ bot
--run-idSession-specific contextConversation history

Backend Selection

mem0 (Default)

Best for production apps with multi-user support:

bash
praisonai knowledge index ./docs --user-id alice --backend mem0

Chroma

Best for local development:

bash
praisonai knowledge index ./docs --backend chroma

Internal

Lightweight built-in storage:

bash
praisonai knowledge index ./docs --backend internal

Configuration File

You can provide a YAML configuration file:

yaml
# knowledge-config.yaml
knowledge:
  vector_store:
    provider: chroma
    config:
      collection_name: my_docs
      path: ./.praison/knowledge/my_docs
  retrieval:
    strategy: hybrid
bash
praisonai knowledge index ./docs --config knowledge-config.yaml

Environment Variables

VariableDefaultWhat it controls
OPENAI_EMBEDDING_MODELtext-embedding-3-smallModel used to embed chunks on index and query text on search. Applies to the chroma / internal backends. Set to text-embedding-3-large for higher-quality retrieval at ~6.5× the cost per token, or to any other OpenAI-compatible embedding model your provider supports.
OPENAI_API_KEY(none)Required by the default OpenAI embedder. A missing or invalid key surfaces as ✗ Failed to index …: no chunks stored and exit code 1.

Profiling

Enable profiling to measure performance:

bash
praisonai knowledge index ./docs --user-id myuser --profile --profile-out ./profile.json

The profile output includes:

  • Wall time
  • Peak memory usage
  • Modules imported
  • Top functions by time

Related Commands

  • praisonai rag query – Answer questions with citations
  • praisonai chat – Interactive chat with knowledge retrieval