> ## 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 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

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

**1. Install dependencies**

```bash theme={null}
uv pip install -U "agno[anthropic,openai,pgvector]" pypdf psycopg sqlalchemy
```

**2. Export your API keys**

```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"
```

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

**3. Run the agent**

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

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

## Developer Resources

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


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