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

# Knowledge Bases

> Create and manage RAG-style knowledge bases programmatically.

The `KnowledgeBases` module is the entry point for managing knowledge bases: vector stores backed by uploaded documents. Use it to list existing KBs, load one, or create a new KB. The actual document operations (`add_documents`, `search`, `list_documents`, `delete`) live on the `KnowledgeBase` instance.

```python theme={"dark"}
from xpander_sdk import KnowledgeBases

kbs = KnowledgeBases()

# Create
kb = await kbs.acreate(name="Q4 Reports", description="Quarterly earnings")

# Add documents
await kb.aadd_documents([
    "https://example.com/Q4-2024.pdf",
    "https://example.com/Q4-2025.pdf",
])

# Search
results = await kb.asearch(search_query="revenue trends", top_k=5)
for r in results:
    print(r.score, r.content[:80])
```

## Constructor

```python theme={"dark"}
KnowledgeBases(configuration: Optional[Configuration] = None)
```

| Parameter       | Type            | Default | Description                                |
| --------------- | --------------- | ------- | ------------------------------------------ |
| `configuration` | `Configuration` | `None`  | SDK configuration. Falls back to env vars. |

## Module methods

| Method                                                                   | Returns               | What it does                   |
| ------------------------------------------------------------------------ | --------------------- | ------------------------------ |
| [`alist` / `list`](/developers/sdk-reference/knowledge-bases/list)       | `list[KnowledgeBase]` | All KBs accessible to the org. |
| [`aget` / `get`](/developers/sdk-reference/knowledge-bases/get)          | `KnowledgeBase`       | Load one KB by id.             |
| [`acreate` / `create`](/developers/sdk-reference/knowledge-bases/create) | `KnowledgeBase`       | Create a new KB.               |

## `KnowledgeBase` instance methods

See the [`KnowledgeBase` class reference](/developers/sdk-reference/knowledge-bases/knowledge-base) for:

* `aadd_documents` / `add_documents`
* `alist_documents` / `list_documents`
* `adelete_multiple_documents` / `delete_multiple_documents`
* `asearch` / `search`
* `adelete` / `delete`

## Linking to an agent

Knowledge bases linked to an agent are configured in the Workbench or with `agent.attach_knowledge_base(...)`. Once linked, the agent's framework retriever queries them automatically: see the [Agent knowledge bases page](/developers/sdk-reference/agents/knowledge-bases).
