> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/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

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

  <Step title="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
    ```
  </Step>

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U ibm-watsonx-ai sqlalchemy pgvector psycopg pypdf openai agno
    ```
  </Step>

  <Step title="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.
  </Step>

  <Step title="Run Agent">
    Save the code above as `knowledge.py`, then run:

    ```bash theme={null}
    python knowledge.py
    ```
  </Step>

  <Step title="For subsequent runs">
    After the first run, comment out the `knowledge.insert(...)` line to avoid reloading the PDF.
  </Step>
</Steps>

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.
