rag_agent.py with the following code:
rag_agent.py
Usage
1
Create a virtual environment
Open the
Terminal and create a python virtual environment.2
Install libraries
3
Run the agent
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
rag_agent.py with the following code:
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.embedder.openai import OpenAIEmbedder
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.lancedb import LanceDb, SearchType
# Create a knowledge base from a PDF
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
# Use LanceDB as the vector database
vector_db=LanceDb(
table_name="recipes",
uri="tmp/lancedb",
search_type=SearchType.vector,
embedder=OpenAIEmbedder(model="text-embedding-3-small"),
),
)
# Comment out after first run as the knowledge base is loaded
knowledge_base.load(recreate=False)
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
# Add the knowledge base to the agent
knowledge=knowledge_base,
show_tool_calls=True,
markdown=True,
)
agent.print_response("How do I make chicken and galangal in coconut milk soup", stream=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
Install libraries
pip install openai lancedb tantivy pypdf sqlalchemy
Run the agent
python rag_agent.py
Was this page helpful?