Skip to main content
The knowledge command manages document knowledge bases with support for multiple vector stores, retrieval strategies, rerankers, and query modes.

Quick Start

# List knowledge sources
praisonai knowledge list
List knowledge example
# Add a document
praisonai knowledge add document.pdf

# Query knowledge base with RAG
praisonai knowledge query "API authentication"

# Query with advanced options
praisonai knowledge query "How to authenticate?" --retrieval fusion --reranker llm

Commands

Add Documents

# Add a single file
praisonai knowledge add document.pdf

# Add a directory
praisonai knowledge add ./docs/

# Add a URL
praisonai knowledge add https://example.com/docs.html

# Add with glob pattern
praisonai knowledge add "*.pdf"
Expected Output:
📚 Adding documents to knowledge base...

✅ Added: document.pdf
   • Pages: 45
   • Chunks: 128
   • Vectors: 128

Knowledge base updated successfully!
┌─────────────────────┬──────────────┐
│ Metric              │ Value        │
├─────────────────────┼──────────────┤
│ Total Documents     │ 12           │
│ Total Chunks        │ 1,456        │
│ Storage Size        │ 24.5 MB      │
└─────────────────────┴──────────────┘

Query Knowledge Base

# Basic query
praisonai knowledge query "How to authenticate API requests"

# Query with specific vector store
praisonai knowledge query "authentication" --vector-store chroma

# Query with fusion retrieval (multi-query)
praisonai knowledge query "How to authenticate?" --retrieval fusion

# Query with LLM reranking
praisonai knowledge query "API auth" --reranker llm

# Query with sub-question decomposition
praisonai knowledge query "What is Python and how to install it?" --query-mode sub_question

# Full advanced query
praisonai knowledge query "authentication flow" \
  --vector-store chroma \
  --retrieval fusion \
  --reranker llm \
  --index-type hybrid \
  --query-mode sub_question
Expected Output:
🔍 Querying knowledge base...

Found 5 relevant results:

1. [score: 0.95] api-docs.pdf (page 23)
   "Authentication is handled via Bearer tokens. Include the token
   in the Authorization header: Authorization: Bearer <token>"

2. [score: 0.87] security-guide.md (section 3.2)
   "All API requests must be authenticated. Unauthenticated requests
   will receive a 401 Unauthorized response."

3. [score: 0.82] quickstart.txt (line 45)
   "To get started, first obtain an API key from the dashboard..."

List Documents

praisonai knowledge list
Expected Output:
📚 Knowledge Base Contents:

┌────┬─────────────────────┬──────────┬────────┬─────────────────────┐
│ #  │ Document            │ Type     │ Chunks │ Added               │
├────┼─────────────────────┼──────────┼────────┼─────────────────────┤
│ 1  │ api-docs.pdf        │ PDF      │ 234    │ 2024-12-15 10:30    │
│ 2  │ security-guide.md   │ Markdown │ 45     │ 2024-12-15 10:32    │
│ 3  │ quickstart.txt      │ Text     │ 12     │ 2024-12-15 10:33    │
│ 4  │ faq.md              │ Markdown │ 28     │ 2024-12-16 09:15    │
│ 5  │ architecture.pdf    │ PDF      │ 156    │ 2024-12-16 14:20    │
└────┴─────────────────────┴──────────┴────────┴─────────────────────┘

Total: 5 documents, 475 chunks

Show Knowledge Base Info

praisonai knowledge info
Expected Output:
📊 Knowledge Base Information:

┌─────────────────────────┬────────────────────────────┐
│ Property                │ Value                      │
├─────────────────────────┼────────────────────────────┤
│ Location                │ .praison/knowledge/        │
│ Vector Store            │ ChromaDB                   │
│ Embedding Model         │ text-embedding-3-small     │
│ Total Documents         │ 5                          │
│ Total Chunks            │ 475                        │
│ Total Vectors           │ 475                        │
│ Storage Size            │ 12.3 MB                    │
│ Last Updated            │ 2024-12-16 14:20:00        │
└─────────────────────────┴────────────────────────────┘

Clear Knowledge Base

# Clear all documents
praisonai knowledge clear
Expected Output:
⚠️  This will delete all documents from the knowledge base.
Are you sure? (y/N): y

🗑️  Clearing knowledge base...
✅ Knowledge base cleared successfully!

Show Statistics

praisonai knowledge stats
Expected Output:
📊 Knowledge Base Statistics:
  workspace: /path/to/project
  vector_store: chroma
  retrieval_strategy: basic
  reranker: none
  index_type: vector
  query_mode: default
  document_count: 5

Export Knowledge Base

# Export to default timestamped file
praisonai knowledge export

# Export to specific file
praisonai knowledge export backup.json

# Export to specific path
praisonai knowledge export /path/to/knowledge_backup.json
Expected Output:
✅ Exported 12 documents to knowledge_export_20241226_103045.json

Import Knowledge Base

# Import from JSON file
praisonai knowledge import backup.json

# Import from specific path
praisonai knowledge import /path/to/knowledge_backup.json
Expected Output:
✅ Imported 12 documents from backup.json

Help

praisonai knowledge help
Expected Output:
Knowledge Commands:
  praisonai knowledge add <file|dir|url>   - Add document(s) to knowledge base
  praisonai knowledge query <question>     - Query knowledge base with RAG
  praisonai knowledge list                 - List indexed documents
  praisonai knowledge clear                - Clear knowledge base
  praisonai knowledge stats                - Show knowledge base statistics
  praisonai knowledge export <file.json>   - Export knowledge base to JSON file
  praisonai knowledge import <file.json>   - Import knowledge base from JSON file

Options:
  --workspace <path>           - Workspace directory (default: current)
  --vector-store <name>        - Vector store: chroma, pinecone, qdrant, weaviate, memory
  --retrieval <strategy>       - Retrieval: basic, fusion, recursive, auto_merge
  --reranker <name>            - Reranker: simple, llm, cross_encoder, cohere
  --index-type <type>          - Index: vector, keyword, hybrid
  --query-mode <mode>          - Query: default, sub_question, summarize
  --session <id>               - Session ID for persistence
  --db <path>                  - Database path for persistence

Advanced Options Reference

Vector Stores

StoreDescriptionRequirements
memoryIn-memory (default, no persistence)None
chromaChromaDB local vector storepip install chromadb
pineconePinecone cloud vector storePINECONE_API_KEY
qdrantQdrant vector databasepip install qdrant-client
weaviateWeaviate vector databasepip install weaviate-client

Retrieval Strategies

StrategyDescription
basicSimple vector similarity search (default)
fusionMulti-query with Reciprocal Rank Fusion
recursiveDepth-limited recursive retrieval
auto_mergeMerges adjacent chunks from same document

Rerankers

RerankerDescriptionRequirements
simpleKeyword-based scoring (default)None
llmLLM-based relevance scoringOPENAI_API_KEY
cross_encoderCross-encoder modelpip install sentence-transformers
cohereCohere Rerank APICOHERE_API_KEY

Index Types

TypeDescription
vectorVector similarity index (default)
keywordBM25 keyword index
hybridCombined vector + keyword

Query Modes

ModeDescription
defaultStandard RAG query
sub_questionDecomposes complex questions
summarizeSummarizes retrieved context

Supported File Types

TypeExtensionsDescription
PDF.pdfPDF documents with text extraction
Markdown.md, .mdxMarkdown files
Text.txtPlain text files
Code.py, .js, .ts, etc.Source code files
HTML.html, .htmWeb pages
JSON.jsonJSON documents
CSV.csvTabular data
URLhttp://, https://Web pages

Use Cases

# Add project documentation
praisonai knowledge add ./docs/

# Query documentation
praisonai "How do I configure the database?" --knowledge

Code Understanding

# Add codebase
praisonai knowledge add ./src/

# Ask about code
praisonai "Explain the authentication flow" --knowledge

Research Assistant

# Add research papers
praisonai knowledge add ./papers/

# Query research
praisonai knowledge search "machine learning optimization techniques"

Using Knowledge with Agents

Once documents are added, agents can automatically query the knowledge base:
# Enable knowledge for agent
praisonai "Answer based on the documentation" --knowledge
Expected Output:
📚 Knowledge base enabled (5 documents)

╭─ Agent Info ─────────────────────────────────────────────────────────────────╮
│  👤 Agent: DirectAgent                                                       │
│  Role: Assistant                                                             │
│  📚 Knowledge: 5 documents, 475 chunks                                      │
╰──────────────────────────────────────────────────────────────────────────────╯

╭────────────────────────────────── Response ──────────────────────────────────╮
│ Based on the documentation, here's how to configure the database:            │
│                                                                              │
│ 1. Set the DATABASE_URL environment variable...                             │
│ [Response based on knowledge base content]                                   │
╰──────────────────────────────────────────────────────────────────────────────╯

📖 Sources:
  • api-docs.pdf (page 12)
  • quickstart.txt (section 2)

Best Practices

Organize documents by topic in separate directories for better search relevance.
Large documents are automatically chunked. Very large knowledge bases may increase response latency.

Document Quality

Use well-structured documents with clear headings

Regular Updates

Keep knowledge base updated with latest documentation

Specific Queries

Use specific search terms for better results

Organize by Topic

Group related documents together