> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Cassandra Vector Database

> Use Cassandra as a vector database for your Knowledge Base.

## Setup

Install Cassandra packages

```shell theme={null}
uv pip install -U agno cassio cassandra-driver mistralai pypdf
```

Run Cassandra with Docker:

```shell theme={null}
docker run -d \
  --name cassandra-db \
  -p 9042:9042 \
  cassandra:latest
```

Set your Mistral API key. The examples below use Mistral for embeddings and responses.

```shell theme={null}
export MISTRAL_API_KEY=xxx
```

## Example

```python agent_with_knowledge.py theme={null}
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.cassandra import Cassandra
from agno.knowledge.embedder.mistral import MistralEmbedder
from agno.models.mistral import MistralChat
from cassandra.cluster import Cluster

# Set up your Cassandra DB

cluster = Cluster()

session = cluster.connect()
session.execute(
    """
    CREATE KEYSPACE IF NOT EXISTS testkeyspace
    WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }
    """
)

knowledge_base = Knowledge(
    vector_db=Cassandra(table_name="recipes", keyspace="testkeyspace", session=session, embedder=MistralEmbedder()),
)

knowledge_base.insert(
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
)

agent = Agent(
    model=MistralChat(id="mistral-large-latest"),
    knowledge=knowledge_base,
)

agent.print_response(
    "What are the health benefits of Khao Niew Dam Piek Maphrao Awn?", markdown=True, show_full_reasoning=True
)
```

> [!NOTE]
>
> Cassandra tables are created with a fixed vector dimension of 1024. Use an embedder that outputs 1024-dimension vectors, like `MistralEmbedder()` or `OpenAIEmbedder(dimensions=1024)`.

> **Async Support ⚡**
>
> Cassandra also supports asynchronous operations, enabling concurrency and leading to better performance.
>
> ```python async_cassandra.py theme={null}
> import asyncio
>
> from agno.agent import Agent
> from agno.knowledge.embedder.mistral import MistralEmbedder
> from agno.knowledge.knowledge import Knowledge
> from agno.models.mistral import MistralChat
> from agno.vectordb.cassandra import Cassandra
>
> try:
>     from cassandra.cluster import Cluster  # type: ignore
> except (ImportError, ModuleNotFoundError):
>     raise ImportError(
>         "Could not import cassandra-driver python package.Please install it with pip install cassandra-driver."
>     )
>
> cluster = Cluster()
>
> session = cluster.connect()
> session.execute(
>     """
>     CREATE KEYSPACE IF NOT EXISTS testkeyspace
>     WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }
>     """
> )
>
> knowledge_base = Knowledge(
>     vector_db=Cassandra(
>         table_name="recipes",
>         keyspace="testkeyspace",
>         session=session,
>         embedder=MistralEmbedder(),
>     ),
> )
>
> agent = Agent(
>     model=MistralChat(),
>     knowledge=knowledge_base,
> )
>
> if __name__ == "__main__":
>     asyncio.run(knowledge_base.ainsert(
>         url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
>         )
>     )
>
>     # Create and use the agent
>     asyncio.run(
>         agent.aprint_response(
>             "What are the health benefits of Khao Niew Dam Piek Maphrao Awn?",
>             markdown=True,
>         )
>     )
> ```
>
> > [!TIP]
> >
> > Use `ainsert()` and `aprint_response()` methods with `asyncio.run()` for non-blocking operations in high-throughput applications.

## Cassandra Params

<Snippet file="vectordb_cassandra_params.mdx" />


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.