import asyncio
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"),
)
# Initialize Upstash DB
knowledge = Knowledge(
name="Basic SDK Knowledge Base",
description="Agno 2.0 Knowledge Implementation with Upstash Vector DB",
vector_db=vector_db,
)
# Create and use the agent
agent = Agent(knowledge=knowledge)
if __name__ == "__main__":
# Comment out after first run
asyncio.run(
knowledge.add_content_async(
name="Recipes",
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
metadata={"doc_type": "recipe_book"},
)
)
# Create and use the agent
asyncio.run(
agent.aprint_response("How to make Pad Thai?", markdown=True)
)
Create a virtual environment
Terminal
and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install -U upstash-vector pypdf openai agno
Set environment variables
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
Run Agent
python cookbook/knowledge/vector_db/upstash_db/upstash_db.py