> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent with Knowledge

> Answer questions from a PDF using a WatsonX agent and PgVector.

## Code

```python knowledge.py theme={null}
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.models.ibm import WatsonX
from agno.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

knowledge = Knowledge(
    vector_db=PgVector(table_name="recipes", db_url=db_url),
)
# Add content to the knowledge
knowledge.insert(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf")

agent = Agent(
    model=WatsonX(id="mistralai/mistral-small-3-1-24b-instruct-2503"),
    knowledge=knowledge,
)
agent.print_response("How to make Thai curry?", markdown=True)
```

## Usage

<Snippet file="create-venv-step.mdx" />

**1. Set your API keys**

```bash theme={null}
export IBM_WATSONX_API_KEY=xxx
export IBM_WATSONX_PROJECT_ID=xxx
export OPENAI_API_KEY=***  # Used by the default OpenAIEmbedder
```

**2. Install dependencies**

```bash theme={null}
uv pip install -U ibm-watsonx-ai sqlalchemy pgvector psycopg pypdf openai agno
```

**3. Set up PostgreSQL with pgvector**

You need a PostgreSQL database with the pgvector extension installed. Adjust the `db_url` in the code to match your database configuration.

**4. Run Agent**

Save the code above as `knowledge.py`, then run:

```bash theme={null}
python knowledge.py
```

**5. For subsequent runs**

After the first run, comment out the `knowledge.insert(...)` line to avoid reloading the PDF.

The example loads a PDF from a URL, processes it into a vector database (PostgreSQL with pgvector), and creates an IBM WatsonX agent that can query this knowledge base.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.