# Knowledge Bases

Knowledge bases are collections of content sources that power AI agents with contextual information. They index content, generate vector embeddings, and provide intelligent retrieval capabilities.

## What are Knowledge Bases?

A knowledge base is an organized collection of content sources that provides:

- **Interactive Chat** — Ask questions and have conversations with your indexed content using built-in RAG
- **Vector Embeddings** — AI-powered content representations for similarity matching
- **Agent Context** — Provide agents with relevant information automatically
- **Content Triggers** — Automatically run agents when content changes
- **Multi-Source Indexing** — Combine multiple sources into one searchable collection

Knowledge bases act as the "memory" for your AI agents, allowing them to access and reason about your content intelligently.

## Creating a Knowledge Base

1. Navigate to the **Knowledge Bases** page
2. Click **Create Knowledge Base**
3. Give it a name and optional description
4. Select one or more content sources to include
5. Configure retrieval settings (or keep the defaults)

You can add or remove sources at any time after creation.

## Retrieval Settings

Each knowledge base has configurable retrieval settings that control how content is returned to agents:

| Setting             | Description                                                       | Default |
| ------------------- | ----------------------------------------------------------------- | ------- |
| **Reranker Model**  | Model used to rerank search results for relevance                 | —       |
| **Top N**           | Maximum number of results returned from the initial vector search | 20      |
| **Top K**           | Number of results kept after reranking                            | 5       |
| **Score Threshold** | Minimum relevance score (0–1) a result must meet to be included   | 0.0     |

## Chat

Every knowledge base has a built-in chat interface that lets you have interactive conversations with your indexed content. The chat uses RAG under the hood — each message triggers a retrieval against the knowledge base, then feeds the relevant content to an LLM to generate a grounded response.

**Starting a conversation**

Open a knowledge base and switch to the **Chat** tab. Type a question and press Enter. A new conversation is created automatically, and the response streams back in real time.

**Key capabilities:**

- **Multiple conversations** — Create as many conversations as you need. Each one maintains its own message history and can be renamed, archived, or deleted.
- **Model selection** — Choose between Fast (Nova Lite), Balanced (Claude Sonnet), and Thorough (Claude Opus) tiers per message. You can also select a specific model from the full [model catalogue](https://seclai.com/docs/models).
- **Streaming responses** — Responses stream token-by-token so you see results immediately.
- **Conversation management** — Rename conversations for easy reference, archive old ones to keep the sidebar clean, or bulk-delete conversations you no longer need.
- **Regenerate responses** — If a response isn't satisfactory, regenerate it to get a fresh answer.
- **Copy and feedback** — Copy any message to your clipboard, and use the thumbs-up/down feedback buttons to rate response quality.

**How it works**

When you send a message, Seclai:

1. Retrieves relevant content chunks from the knowledge base using the configured retrieval settings (Top N, Top K, reranker, score threshold)
2. Constructs a RAG prompt with the retrieved context and your conversation history
3. Sends the prompt to the selected model and streams the response back

Conversations persist across sessions — come back any time to continue where you left off.

## API Access

Knowledge bases can be managed programmatically via the Public API using your API key:

```bash
# List knowledge bases
curl "https://api.seclai.com/knowledge_bases?page=1&limit=20" \
  -H "X-API-Key: $SECLAI_API_KEY"

# Create a knowledge base
curl -X POST https://api.seclai.com/knowledge_bases \
  -H "X-API-Key: $SECLAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Tech News KB",
    "description": "Aggregated tech news sources",
    "source_ids": ["source-id-1", "source-id-2"]
  }'

# Get a knowledge base
curl "https://api.seclai.com/knowledge_bases/$KNOWLEDGE_BASE_ID" \
  -H "X-API-Key: $SECLAI_API_KEY"

# Update a knowledge base
curl -X PUT "https://api.seclai.com/knowledge_bases/$KNOWLEDGE_BASE_ID" \
  -H "X-API-Key: $SECLAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Renamed KB", "top_k": 10}'

# Delete a knowledge base
curl -X DELETE "https://api.seclai.com/knowledge_bases/$KNOWLEDGE_BASE_ID" \
  -H "X-API-Key: $SECLAI_API_KEY"
```

See [API Examples](https://seclai.com/docs/api-examples) for more examples in multiple languages.

## MCP Tools

Knowledge base operations are available as MCP tools for AI coding assistants:

| Tool                                  | Description                                      |
| ------------------------------------- | ------------------------------------------------ |
| <code>list_knowledge_bases</code>     | List knowledge bases with pagination and sorting |
| <code>get_knowledge_base</code>       | Get full details of a knowledge base             |
| <code>create_knowledge_base</code>    | Create a new knowledge base                      |
| <code>update_knowledge_base</code>    | Update a knowledge base's configuration          |
| <code>delete_knowledge_base</code>    | Delete a knowledge base                          |
| <code>chat_with_knowledge_base</code> | Send a message and get a RAG-powered response    |
| <code>list_kb_conversations</code>    | List conversations for a knowledge base          |
| <code>load_kb_chat_messages</code>    | Load messages from a conversation                |
| <code>rename_kb_conversation</code>   | Rename a conversation                            |
| <code>delete_kb_conversation</code>   | Delete a conversation                            |

See [MCP Server → Knowledge Base Tools](https://seclai.com/docs/mcp#knowledge-base-tools) for setup instructions.

## Exporting

Export a knowledge base's full content — sources, metadata, and indexed items — as a downloadable JSON file.

- **UI:** Open the knowledge base detail page and click the **Export** button. You'll see an estimate of the export size before confirming.
- **API:** `POST /authenticated/resource-exports` with `resource_type: "knowledge_base"` and the knowledge base ID.
- **MCP:** Use the `create_resource_export` tool with `resource_type: "knowledge_base"`.

See [Export Formats → Knowledge Base](https://seclai.com/docs/export-formats#knowledge-base) for the full file schema and available filter options.

## Next Steps

- [Content Sources](https://seclai.com/docs/content-sources) — Learn about content sources
- [Contents](https://seclai.com/docs/contents) — Inspect, replace, and delete indexed content items
- [Agents](https://seclai.com/docs/agents) — Build agents that use knowledge bases
- [API Examples](https://seclai.com/docs/api-examples) — Code samples for the API
- [API Reference](https://seclai.com/docs/api) — Complete API documentation
- [MCP Server](https://seclai.com/docs/mcp) — Use knowledge base tools from AI coding assistants
