> ## 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 Claude, OpenAI embeddings, and PgVector.

Add a PDF to a `Knowledge` base, retrieve relevant chunks, and give them to Claude as context.

## Code

```python knowledge.py theme={null}
from agno.agent import Agent
from agno.knowledge.embedder.openai import OpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.models.anthropic import Claude
from agno.vectordb.pgvector import PgVector

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


def main() -> None:
    knowledge = Knowledge(
        vector_db=PgVector(
            table_name="anthropic_recipes",
            db_url=db_url,
            embedder=OpenAIEmbedder(id="text-embedding-3-small"),
        ),
    )

    agent = Agent(
        model=Claude(id="claude-sonnet-4-6"),
        knowledge=knowledge,
    )

    knowledge.insert(
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
        skip_if_exists=True,
    )
    agent.print_response("How do I make Thai curry?", markdown=True)


if __name__ == "__main__":
    main()
```

Embeddings require a separate provider because Anthropic offers no embedding model. This example uses OpenAI for embeddings and Claude for the final answer. Replace `OpenAIEmbedder` with another Agno embedder if you prefer a different embedding provider.

## Usage

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[anthropic,openai,pgvector]" pypdf psycopg sqlalchemy
    ```
  </Step>

  <Step title="Export your API keys">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```powershell Windows theme={null}
      $Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Snippet file="run-pgvector-step.mdx" />

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

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

## Developer Resources

* [Knowledge overview](/knowledge/overview)
* [Anthropic embeddings guidance](https://platform.claude.com/docs/en/build-with-claude/embeddings)
