Usage
1
Create a virtual environment
Open the
Terminal and create a python virtual environment.2
Run PgVector
3
Install libraries
4
Run PgVector Agent
Information
- View on Github
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
from phi.agent import Agent
from phi.storage.agent.postgres import PgAgentStorage
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
agent = Agent(
storage=PgAgentStorage(table_name="recipe_agent", db_url=db_url),
knowledge_base=PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector(table_name="recipe_documents", db_url=db_url),
),
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to search the knowledge base
search_knowledge=True,
# Enable the agent to read the chat history
read_chat_history=True,
)
# Comment out after first run
agent.knowledge_base.load(recreate=False) # type: ignore
agent.print_response("How do I make pad thai?", markdown=True)
Create a virtual environment
Terminal and create a python virtual environment.python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
python3 -m venv aienv
aienv/scripts/activate
Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v pgvolume:/var/lib/postgresql/data \
-p 5532:5432 \
--name pgvector \
phidata/pgvector:16
Install libraries
pip install -U pgvector pypdf "psycopg[binary]" sqlalchemy phidata
Run PgVector Agent
python cookbook/integrations/pgvector/agent.py
python cookbook/integrations/pgvector/agent.py
Was this page helpful?