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

# Knowledge Base Management

> Manage vector stores for RAG (Retrieval Augmented Generation) with rf kb

The `rf kb` command provides complete knowledge base (vector store) management for RAG applications. Upload documents, perform semantic search, check processing status, and manage your knowledge bases.

## Commands Overview

| Command                          | Description                                  |
| -------------------------------- | -------------------------------------------- |
| `rf kb list`                     | List all knowledge bases                     |
| `rf kb create <name>`            | Create new knowledge base                    |
| `rf kb upload <kb> <file/dir>`   | Upload documents (async, with live progress) |
| `rf kb jobs <kb>`                | List ingestion jobs and their progress       |
| `rf kb status <kb>`              | Check processing status                      |
| `rf kb docs <kb>`                | List documents in KB                         |
| `rf kb remove-doc <kb> <doc-id>` | Remove specific document                     |
| `rf kb search <kb> <query>`      | Semantic search                              |
| `rf kb delete <kb>`              | Delete knowledge base                        |

## Listing Knowledge Bases

```bash theme={null}
# List all knowledge bases
rf kb list

# Output:
# Knowledge Bases:
# • support-docs (100 documents)
# • product-manual (45 documents)
# • faq-knowledge (12 documents)
```

## Creating Knowledge Base

### Interactive Mode

```bash theme={null}
rf kb create support-docs
# → Select embedding configuration:
#   • OpenAI Small (text-embedding-3-small)
#   • OpenAI Large (text-embedding-3-large)
#   • Custom...
# ✓ Knowledge base 'support-docs' created
```

### Non-Interactive Mode

Perfect for scripts and automation:

```bash theme={null}
# Using embedding name
rf kb create support-docs --embedding "OpenAI Small"

# Using short form
rf kb create support-docs -e openai-small

# Using embedding config ID
rf kb create support-docs --embedding embedding-cfg-123
```

### Options

| Option                 | Alias | Description                 |
| ---------------------- | ----- | --------------------------- |
| `--embedding <config>` | `-e`  | Embedding config ID or name |
| `--yes`                | `-y`  | Skip confirmations          |

## Uploading Documents

### Upload Single File

```bash theme={null}
# Upload one file
rf kb upload support-docs ./manual.pdf
# ⠋ Processing manual.pdf (450/1200 chunks)
# ✓ manual.pdf: 1200 chunks indexed

# Supported formats
rf kb upload support-docs ./faq.txt
rf kb upload support-docs ./guide.md
rf kb upload support-docs ./doc.docx
rf kb upload support-docs ./catalog.csv
```

<Info>
  Since CLI `0.3.22`, uploads use the platform's **async ingestion pipeline**: the file is accepted immediately and embedded in the background with batched embeddings and checkpoint resume; the CLI shows live chunk progress until the job completes. Large files (50k+ row CSV catalogs) no longer time out. Against an older self-hosted API without the async endpoint, the CLI falls back to the legacy synchronous upload automatically.
</Info>

### Upload Directory

```bash theme={null}
# Upload all files in directory (with confirmation)
rf kb upload support-docs ./docs
# ? Upload 15 files from ./docs? (y/N)

# Skip confirmation
rf kb upload support-docs ./docs --yes
# ✓ Uploaded 15 files
```

### Supported File Types

* **PDF** (`.pdf`)
* **Text** (`.txt`)
* **Markdown** (`.md`)
* **Word Documents** (`.docx`)
* **CSV** (`.csv`) — ingested one document per row (great for product catalogs)
* **JSON** (`.json`)

<Info>
  Files are automatically parsed, chunked, and embedded for semantic search.
</Info>

## Ingestion Jobs

Every upload creates an ingestion job you can inspect at any time:

```bash theme={null}
rf kb jobs support-docs

# Output:
# 📥 Ingestion jobs in "support-docs"
#
#   completed   manual.pdf        1200/1200 chunks  7/1/2026, 3:12:04 PM
#   processing  catalog.csv       31488/53068 chunks  7/1/2026, 3:20:11 PM
#   failed      broken-export.csv -  7/1/2026, 2:55:40 PM
#     Unsupported file type: application/octet-stream...
```

Jobs survive worker restarts: ingestion resumes from the last checkpoint instead of starting over.

## Checking Processing Status

```bash theme={null}
# Check if documents are processed
rf kb status support-docs

# Output:
# Knowledge Base: support-docs
# Status: Processing
# Documents: 15 total, 12 processed, 3 pending
# Embedding: OpenAI Small
```

**Statuses:**

* **Processing** - Documents being embedded
* **Ready** - All documents processed
* **Error** - Some documents failed

## Listing Documents

```bash theme={null}
# List all documents in KB
rf kb docs support-docs

# Output:
# Documents in support-docs:
# • doc_abc123 - manual.pdf (1.2 MB, 45 chunks)
# • doc_def456 - faq.txt (50 KB, 12 chunks)
# • doc_ghi789 - guide.md (200 KB, 28 chunks)
```

## Removing Documents

```bash theme={null}
# Remove with confirmation
rf kb remove-doc support-docs doc_abc123
# ? Are you sure you want to remove document 'doc_abc123'? (y/N)

# Remove without confirmation
rf kb remove-doc support-docs doc_abc123 --yes
# ✓ Document removed

# Short form
rf kb remove-doc support-docs doc_abc123 -y
```

<Warning>
  Removing a document is permanent and cannot be undone!
</Warning>

## Semantic Search

Test your knowledge base with semantic search:

```bash theme={null}
# Search for relevant content
rf kb search support-docs "how to reset password"

# Output:
# Search Results:
#
# [1] Score: 0.92
# Source: faq.txt
# Content: To reset your password, go to Settings > Security...
#
# [2] Score: 0.87
# Source: manual.pdf
# Content: Password Reset Procedure: 1. Click Forgot Password...
#
# [3] Score: 0.81
# Source: guide.md
# Content: User accounts can be recovered by...
```

**Search Features:**

* Semantic similarity (not just keyword matching)
* Ranked by relevance score (0-1)
* Shows source document
* Returns top relevant chunks

## Deleting Knowledge Base

```bash theme={null}
# Delete with confirmation
rf kb delete support-docs
# ? Are you sure you want to delete knowledge base 'support-docs'? (y/N)

# Delete without confirmation
rf kb delete support-docs --yes
# ✓ Knowledge base deleted

# Short form
rf kb delete support-docs -y
```

<Warning>
  Deleting a knowledge base removes all documents and embeddings permanently!
</Warning>

## Complete Workflow Example

```bash theme={null}
# 1. Create knowledge base
rf kb create support-docs --embedding "OpenAI Small"

# 2. Upload documents
rf kb upload support-docs ./docs/manual.pdf
rf kb upload support-docs ./docs/faq.md
rf kb upload support-docs ./docs --yes

# 3. Check processing status
rf kb status support-docs
# Wait until status is "Ready"

# 4. Test semantic search
rf kb search support-docs "how to install"
rf kb search support-docs "pricing information"
rf kb search support-docs "troubleshooting errors"

# 5. List all documents
rf kb docs support-docs

# 6. Remove outdated document
rf kb remove-doc support-docs doc_old123 --yes

# 7. Use in your agent
cd my-agent/
rf test
# → Agent now has access to support-docs knowledge base
```

## Using with RAG Agents

### Creating RAG Agent with Knowledge Base

```bash theme={null}
# 1. Create agent from RAG template
rf create --name support-bot --template rag-agent --yes

# 2. Create and populate knowledge base
rf kb create support-knowledge --embedding "OpenAI Small"
rf kb upload support-knowledge ./company-docs --yes

# 3. Test locally
cd support-bot/
rf test

# 4. Deploy
rf agents deploy
```

### Agent Configuration

Your agent code will reference the knowledge base:

```typescript theme={null}
import { Agent } from '@runflow-ai/core';

const agent = new Agent({
  name: 'Support Bot',
  instructions: 'Use the knowledge base to answer questions',
  knowledgeBase: 'support-knowledge', // Reference your KB
  model: 'gpt-4',
});
```

## Automation & Scripts

### Bulk Upload Script

```bash theme={null}
#!/bin/bash

# Create KB
rf kb create product-docs --embedding "OpenAI Small"

# Upload all PDFs
find ./documents -name "*.pdf" -exec rf kb upload product-docs {} \;

# Wait for processing
while [ "$(rf kb status product-docs | grep 'Status:' | awk '{print $2}')" != "Ready" ]; do
  echo "Processing..."
  sleep 5
done

echo "Knowledge base ready!"
```

### Multi-KB Setup

```bash theme={null}
#!/bin/bash

# Setup multiple knowledge bases
kb_configs=(
  "support-docs:./support-files"
  "product-manual:./manuals"
  "legal-docs:./legal"
)

for config in "${kb_configs[@]}"; do
  kb_name="${config%%:*}"
  kb_dir="${config##*:}"
  
  rf kb create "$kb_name" --embedding "OpenAI Small"
  rf kb upload "$kb_name" "$kb_dir" --yes
done
```

## Best Practices

### 1. Organize Documents by Domain

```bash theme={null}
# Create separate KBs for different topics
rf kb create customer-support
rf kb create product-documentation
rf kb create legal-compliance
rf kb create internal-wiki
```

### 2. Keep Documents Updated

```bash theme={null}
# Remove old versions
rf kb remove-doc support-docs doc_old_manual --yes

# Upload new versions
rf kb upload support-docs ./manual-v2.pdf
```

### 3. Test Before Production

```bash theme={null}
# Always test search quality
rf kb search my-kb "common query 1"
rf kb search my-kb "common query 2"
rf kb search my-kb "edge case query"

# Refine documents if results are poor
```

### 4. Choose Appropriate Embedding Model

```bash theme={null}
# Small model - faster, cheaper, good for most use cases
rf kb create kb-small --embedding "OpenAI Small"

# Large model - more accurate, better for complex domains
rf kb create kb-large --embedding "OpenAI Large"
```

### 5. Monitor Processing Status

```bash theme={null}
# After large uploads, monitor status
rf kb upload docs ./large-dataset --yes
rf kb status docs

# Wait for processing to complete before using
```

## Document Processing

### How It Works

1. **Upload** - File sent to server
2. **Parse** - Content extracted (text from PDF, DOCX, etc.)
3. **Chunk** - Split into manageable pieces (\~500 tokens)
4. **Embed** - Generate vector embeddings
5. **Index** - Store in vector database
6. **Ready** - Available for search

### Processing Time

* Small files (\<1 MB): \~5-10 seconds
* Medium files (1-10 MB): \~30-60 seconds
* Large files (>10 MB): \~2-5 minutes
* Directories: Depends on total size and file count

### Chunking Strategy

Documents are automatically chunked with:

* **Chunk size**: \~500 tokens (\~375 words)
* **Overlap**: 50 tokens (for context continuity)
* **Smart splitting**: Respects paragraph boundaries

## Troubleshooting

### KB Already Exists

```bash theme={null}
rf kb create existing-kb
# Error: Knowledge base 'existing-kb' already exists
```

**Solution:** Use a different name or delete the existing KB:

```bash theme={null}
rf kb delete existing-kb --yes
rf kb create existing-kb --embedding "OpenAI Small"
```

### Upload Failed

```bash theme={null}
rf kb upload docs ./file.pdf
# Error: Failed to upload file
```

**Possible causes:**

* File format not supported
* File too large (>50 MB)
* Network connection issues

**Solution:**

* Check file format (PDF, TXT, MD, DOCX only)
* Split large files
* Retry upload

### Documents Stuck in Processing

```bash theme={null}
rf kb status docs
# Status: Processing (stuck for 30+ minutes)
```

**Solution:**

* Check document format and content
* Contact support if issue persists
* Remove and re-upload problematic documents

### Poor Search Results

If search quality is low:

1. **Add more documents** - More context improves results
2. **Use larger embedding model** - Better semantic understanding
3. **Improve document quality** - Clear, well-structured content
4. **Test queries** - Refine search terms

```bash theme={null}
# Try different embedding
rf kb create kb-improved --embedding "OpenAI Large"
rf kb upload kb-improved ./docs --yes
rf kb search kb-improved "test query"
```

## Advanced Usage

### Environment-Specific KBs

```bash theme={null}
# Development KB with test data
rf switch dev
rf kb create test-kb --embedding "OpenAI Small"
rf kb upload test-kb ./test-data --yes

# Production KB with real data
rf switch prod
rf kb create prod-kb --embedding "OpenAI Large"
rf kb upload prod-kb ./production-data --yes
```

### Backup and Restore

```bash theme={null}
# Document metadata can be exported via API
# (CLI backup feature coming soon)

# For now, keep source files backed up
cp -r ./original-docs ./backup-$(date +%Y%m%d)
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Create RAG Agent" icon="plus" href="/cli/create">
    Create agent with knowledge base
  </Card>

  <Card title="Test Locally" icon="flask" href="/cli/test">
    Test KB integration locally
  </Card>

  <Card title="Prompts" icon="file-lines" href="/cli/prompts">
    Create RAG-specific prompts
  </Card>

  <Card title="Knowledge & RAG" icon="book" href="/core-concepts/knowledge-rag">
    Learn more about RAG concepts
  </Card>
</CardGroup>
