> ## 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 Module Reference

> Complete API reference for the Knowledge Bases module including all classes, methods, properties, and parameters

## Introduction

The **Knowledge Bases Module** provides comprehensive functionality for managing knowledge repositories and performing semantic searches within the xpander.ai platform.

## Overview

In this module, you can:

* Create and manage knowledge bases for document storage
* Add documents from URLs to knowledge repositories
* Perform semantic searches across document collections
* Delete and manage knowledge base lifecycle
* Handle both synchronous and asynchronous operations

## Examples

### Creating Knowledge Bases

This example demonstrates how to create new knowledge bases with both asynchronous and synchronous approaches.

#### Asynchronous Example

Using `acreate()` to create knowledge bases asynchronously:

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

kbs = KnowledgeBases()
kb = await kbs.acreate(
    name="Product Documentation",
    description="Knowledge base for product documentation and guides"
)
print(f"Created knowledge base: {kb.name} (ID: {kb.id})")
```

#### Synchronous Example

Using `create()` to create knowledge bases synchronously:

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

kbs = KnowledgeBases()
kb = kbs.create(
    name="Product Documentation",
    description="Knowledge base for product documentation and guides"
)
print(f"Created knowledge base: {kb.name} (ID: {kb.id})")
```

### Listing Knowledge Bases

Retrieve all available knowledge bases in your organization.

#### Asynchronous Example

```python theme={"dark"}
kbs_list = await kbs.alist()
for kb in kbs_list:
    print(f"Knowledge Base: {kb.name} (ID: {kb.id})")
    print(f"Type: {kb.type}")
```

#### Synchronous Example

```python theme={"dark"}
kbs_list = kbs.list()
for kb in kbs_list:
    print(f"Knowledge Base: {kb.name} (ID: {kb.id})")
    print(f"Type: {kb.type}")
```

### Adding Documents

Add documents to knowledge bases from URLs.

#### Asynchronous Example

```python theme={"dark"}
documents = await kb.aadd_documents(
    document_urls=[
        "https://example.com/docs/guides.pdf",
        "https://example.com/docs/API reference.md"
    ],
    sync=True
)
print(f"Added {len(documents)} documents to knowledge base")
```

#### Synchronous Example

```python theme={"dark"}
documents = kb.add_documents(
    document_urls=[
        "https://example.com/docs/guides.pdf",
        "https://example.com/docs/API reference.md"
    ],
    sync=True
)
print(f"Added {len(documents)} documents to knowledge base")
```

### Searching Knowledge Bases

Perform semantic searches across document collections.

#### Asynchronous Example

```python theme={"dark"}
search_results = await kb.asearch("authentication methods")
for result in search_results:
    print(f"Score: {result.score:.3f}")
    print(f"Content: {result.content[:200]}...")
    print("---")
```

#### Synchronous Example

```python theme={"dark"}
search_results = kb.search("authentication methods")
for result in search_results:
    print(f"Score: {result.score:.3f}")
    print(f"Content: {result.content[:200]}...")
    print("---")
```

### Deleting Knowledge Bases

Remove knowledge bases when they're no longer needed.

#### Asynchronous Example

```python theme={"dark"}
await kb.adelete()
print(f"Knowledge base {kb.name} has been deleted")
```

#### Synchronous Example

```python theme={"dark"}
kb.delete()
print(f"Knowledge base {kb.name} has been deleted")
```

***

Continue to the [Knowledge Bases API Reference](/api-reference/knowledge/api-reference) for detailed documentation on classes and methods.

## Related Documentation

<CardGroup cols={2}>
  <Card title="Agents Module" icon="robot" href="/API reference/agents">
    Agent interaction with knowledge bases
  </Card>

  <Card title="Tools Repository" icon="wrench" href="/API reference/tools">
    Tool integration and management
  </Card>

  <Card title="Configuration" icon="gear" href="/API reference/configuration">
    SDK configuration and authentication
  </Card>

  <Card title="Tasks Module" icon="play" href="/API reference/tasks">
    Task execution and management
  </Card>
</CardGroup>

## Support

For additional help:

* Full [SDK Documentation](https://docs.xpander.ai)
* Email: [dev@xpander.ai](mailto:dev@xpander.ai)
