Copy
Ask AI
from agno.agent import Agent
from agno.db.postgres.postgres import PostgresDb
from agno.knowledge.content import ContentAuth
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
# Create a knowledge base with simplified password handling
knowledge = Knowledge(
vector_db=PgVector(
table_name="pdf_documents_password",
db_url=db_url,
),
contents_db=PostgresDb(db_url=db_url),
)
knowledge.insert(
url="https://agno-public.s3.us-east-1.amazonaws.com/recipes/ThaiRecipes_protected.pdf",
auth=ContentAuth(password="ThaiRecipes"),
)
# Create an agent with the knowledge
agent = Agent(
knowledge=knowledge,
search_knowledge=True,
)
agent.print_response("Give me the recipe for pad thai")
Run the Example
Copy
Ask AI
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/07_knowledge/readers
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
# Optiona: Run PgVector (needs docker)
./cookbook/scripts/run_pgvector.sh
python pdf_reader_url_password.py