> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# List knowledge sources
praisonai knowledge list
```

<Frame>
  <img src="https://mintcdn.com/praisonai/aAYxXsQWSI9rL4cN/docs/cli/knowledge-list-knowledge.gif?s=dad38bf55b36e77403cbad8ac316d792" alt="List knowledge example" width="1216" height="897" data-path="docs/cli/knowledge-list-knowledge.gif" />
</Frame>

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

| Store      | Description                         | Requirements                  |
| ---------- | ----------------------------------- | ----------------------------- |
| `memory`   | In-memory (default, no persistence) | None                          |
| `chroma`   | ChromaDB local vector store         | `pip install chromadb`        |
| `pinecone` | Pinecone cloud vector store         | `PINECONE_API_KEY`            |
| `qdrant`   | Qdrant vector database              | `pip install qdrant-client`   |
| `weaviate` | Weaviate vector database            | `pip install weaviate-client` |

### Retrieval Strategies

| Strategy     | Description                               |
| ------------ | ----------------------------------------- |
| `basic`      | Simple vector similarity search (default) |
| `fusion`     | Multi-query with Reciprocal Rank Fusion   |
| `recursive`  | Depth-limited recursive retrieval         |
| `auto_merge` | Merges adjacent chunks from same document |

### Rerankers

| Reranker        | Description                     | Requirements                        |
| --------------- | ------------------------------- | ----------------------------------- |
| `simple`        | Keyword-based scoring (default) | None                                |
| `llm`           | LLM-based relevance scoring     | `OPENAI_API_KEY`                    |
| `cross_encoder` | Cross-encoder model             | `pip install sentence-transformers` |
| `cohere`        | Cohere Rerank API               | `COHERE_API_KEY`                    |

### Index Types

| Type      | Description                       |
| --------- | --------------------------------- |
| `vector`  | Vector similarity index (default) |
| `keyword` | BM25 keyword index                |
| `hybrid`  | Combined vector + keyword         |

### Query Modes

| Mode           | Description                  |
| -------------- | ---------------------------- |
| `default`      | Standard RAG query           |
| `sub_question` | Decomposes complex questions |
| `summarize`    | Summarizes retrieved context |

## Supported File Types

| Type     | Extensions                | Description                        |
| -------- | ------------------------- | ---------------------------------- |
| PDF      | `.pdf`                    | PDF documents with text extraction |
| Markdown | `.md`, `.mdx`             | Markdown files                     |
| Text     | `.txt`                    | Plain text files                   |
| Code     | `.py`, `.js`, `.ts`, etc. | Source code files                  |
| HTML     | `.html`, `.htm`           | Web pages                          |
| JSON     | `.json`                   | JSON documents                     |
| CSV      | `.csv`                    | Tabular data                       |
| URL      | `http://`, `https://`     | Web pages                          |

## Use Cases

### Documentation Search

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Add project documentation
praisonai knowledge add ./docs/

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

### Code Understanding

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Add codebase
praisonai knowledge add ./src/

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

### Research Assistant

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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

<Tip>
  Organize documents by topic in separate directories for better search relevance.
</Tip>

<Warning>
  Large documents are automatically chunked. Very large knowledge bases may increase response latency.
</Warning>

<CardGroup cols={2}>
  <Card title="Document Quality">
    Use well-structured documents with clear headings
  </Card>

  <Card title="Regular Updates">
    Keep knowledge base updated with latest documentation
  </Card>

  <Card title="Specific Queries">
    Use specific search terms for better results
  </Card>

  <Card title="Organize by Topic">
    Group related documents together
  </Card>
</CardGroup>

## Related

* [Knowledge Concept](/concepts/knowledge)
* [RAG Features](/features/rag)
* [Fast Context CLI](/docs/cli/fast-context)
