import asyncio from os import getenv from agno.agent import Agent from agno.knowledge.knowledge import Knowledge from agno.vectordb.pineconedb import PineconeDb api_key = getenv("PINECONE_API_KEY") index_name = "thai-recipe-index" vector_db = PineconeDb( name=index_name, dimension=1536, metric="cosine", spec={"serverless": {"cloud": "aws", "region": "us-east-1"}}, api_key=api_key, ) knowledge = Knowledge( name="My Pinecone Knowledge Base", description="This is a knowledge base that uses a Pinecone Vector DB", vector_db=vector_db, ) agent = Agent( knowledge=knowledge, search_knowledge=True, read_chat_history=True, ) if __name__ == "__main__": asyncio.run( knowledge.add_content_async( name="Recipes", url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf", metadata={"doc_type": "recipe_book"}, ) ) asyncio.run( agent.aprint_response("How do I make pad thai?", markdown=True) )
Create a virtual environment
Terminal
python3 -m venv .venv source .venv/bin/activate
Install libraries
pip install -U pinecone-client pypdf openai agno
Set environment variables
export PINECONE_API_KEY="your-pinecone-api-key" export OPENAI_API_KEY=xxx
Run Agent
python cookbook/knowledge/vector_db/pinecone_db/pinecone_db.py