from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.models.openai import OpenAIChat
from agno.vectordb.pgvector import PgVector, SearchType
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector(
table_name="recipes", db_url=db_url, search_type=SearchType.hybrid
),
)
# Load the knowledge base: Comment out after first run
knowledge_base.load(recreate=False)
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
knowledge=knowledge_base,
search_knowledge=True,
read_chat_history=True,
markdown=True,
)
agent.print_response(
"How do I make chicken and galangal in coconut milk soup", stream=True
)
agent.print_response("What was my last question?", stream=True)
Create a virtual environment
Open the Terminal
and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
Set your API key
export OPENAI_API_KEY=xxx
Install libraries
pip install -U pgvector pypdf "psycopg[binary]" sqlalchemy openai agno
Run PgVector
./cookbook/scripts/run_pgvector.sh
Run Agent
python cookbook/agent_concepts/hybrid_search/pgvector/agent.py
Was this page helpful?
from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.models.openai import OpenAIChat
from agno.vectordb.pgvector import PgVector, SearchType
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector(
table_name="recipes", db_url=db_url, search_type=SearchType.hybrid
),
)
# Load the knowledge base: Comment out after first run
knowledge_base.load(recreate=False)
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
knowledge=knowledge_base,
search_knowledge=True,
read_chat_history=True,
markdown=True,
)
agent.print_response(
"How do I make chicken and galangal in coconut milk soup", stream=True
)
agent.print_response("What was my last question?", stream=True)
Create a virtual environment
Open the Terminal
and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
Set your API key
export OPENAI_API_KEY=xxx
Install libraries
pip install -U pgvector pypdf "psycopg[binary]" sqlalchemy openai agno
Run PgVector
./cookbook/scripts/run_pgvector.sh
Run Agent
python cookbook/agent_concepts/hybrid_search/pgvector/agent.py
Was this page helpful?