> ## 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.

# Upstash Vector Database

> Use Upstash Vector as a serverless vector database for your Knowledge Base.

## Setup

```shell theme={null}
uv pip install -U upstash-vector pypdf openai agno
```

Create an index in the [Upstash Console](https://console.upstash.com), then copy its REST URL and token.

```shell theme={null}
export UPSTASH_VECTOR_REST_URL="your-index-url"
export UPSTASH_VECTOR_REST_TOKEN="your-index-token"
```

The example uses OpenAI for the agent model, so set your API key:

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

## Example

```python agent_with_knowledge.py theme={null}
import os

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.upstashdb import UpstashVectorDb

vector_db = UpstashVectorDb(
    url=os.getenv("UPSTASH_VECTOR_REST_URL"),
    token=os.getenv("UPSTASH_VECTOR_REST_TOKEN"),
)

knowledge = Knowledge(
    name="Upstash Knowledge Base",
    vector_db=vector_db,
)

knowledge.insert(
    name="Recipes",
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    metadata={"doc_type": "recipe_book"},
)

agent = Agent(knowledge=knowledge)
agent.print_response("How to make Pad Thai?", markdown=True)
```

> [!NOTE]
>
> Without an `embedder`, `UpstashVectorDb` uses Upstash's hosted embedding models. Create your index with an embedding model in the Upstash Console. To embed locally instead, pass an `embedder` and make sure its dimension matches the index.

> **Async Support ⚡**
>
> Upstash also supports asynchronous operations, enabling concurrency and leading to better performance.
>
> ```python async_upstash_db.py theme={null}
> import asyncio
> import os
>
> from agno.agent import Agent
> from agno.knowledge.embedder.openai import OpenAIEmbedder
> from agno.knowledge.knowledge import Knowledge
> from agno.vectordb.upstashdb import UpstashVectorDb
>
> vector_db = UpstashVectorDb(
>     url=os.getenv("UPSTASH_VECTOR_REST_URL"),
>     token=os.getenv("UPSTASH_VECTOR_REST_TOKEN"),
>     dimension=1536,
>     embedder=OpenAIEmbedder(enable_batch=True),
> )
>
> knowledge = Knowledge(
>     vector_db=vector_db,
> )
>
> agent = Agent(knowledge=knowledge)
>
> if __name__ == "__main__":
>     asyncio.run(
>         knowledge.ainsert(
>             url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
>         )
>     )
>
>     asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
> ```
>
> > [!TIP]
> >
> > Use `ainsert()` and `aprint_response()` methods with `asyncio.run()` for non-blocking operations in high-throughput applications.

## UpstashVectorDb Params

<Snippet file="vectordb_upstashdb_params.mdx" />


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