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

> Insert a PDF into an Upstash Vector index, query it with an agent, and delete content by name or metadata.

## Code

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

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

# How to connect to an Upstash Vector index
# - Create a new index in Upstash Console with the correct dimension
# - Fetch the URL and token from Upstash Console
# - Replace the values below or use environment variables

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

# Create knowledge base
knowledge = Knowledge(
    name="Basic SDK Knowledge Base",
    description="Agno 2.0 Knowledge Implementation with Upstash Vector DB",
    vector_db=vector_db,
)

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

# Create and use the agent
agent = Agent(knowledge=knowledge)
agent.print_response("How to make Pad Thai?", markdown=True)

vector_db.delete_by_name("Recipes")
# or
vector_db.delete_by_metadata({"doc_type": "recipe_book"})
```

## Usage

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

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

**2. Set environment variables**

```bash theme={null}
export UPSTASH_VECTOR_REST_URL="your-upstash-vector-rest-url"
export UPSTASH_VECTOR_REST_TOKEN="your-upstash-vector-rest-token"
export OPENAI_API_KEY=xxx
```

**3. Run Agent**

```bash theme={null}
python upstash_db.py
```


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