Knowledge CLI

Manage RAG/vector store knowledge bases with advanced retrieval strategies

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

Quick Start

bash
# List knowledge sources
praisonai knowledge list
List knowledge example
bash
# 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

bash
# 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

bash
# 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..."

Search Knowledge Base

Unlike query, search returns raw ranked results with no LLM answer generation.

bash
praisonai knowledge search "capital of France" --user-id myuser

See Knowledge CLI for the full flag reference, and Search Results for the SearchResult shape returned when calling Knowledge.search() from Python.

List Documents

bash
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

bash
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

bash
# 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

bash
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

bash
# 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

bash
# 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

bash
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

Documentation Search

bash
# Add project documentation
praisonai knowledge add ./docs/

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

Code Understanding

bash
# Add codebase
praisonai knowledge add ./src/

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

Research Assistant

bash
# 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:

bash
# 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

Related