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

# Async PgVector Usage

> Insert knowledge and run an agent with Agno's async methods and a PgVector backend.

```python async_pgvector_db.py theme={null}
import asyncio

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="async_recipes",
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
    )
)
agent = Agent(knowledge=knowledge, search_knowledge=True)


async def main() -> None:
    await knowledge.ainsert(
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
    )
    await agent.aprint_response("How do I make pad thai?", markdown=True)


if __name__ == "__main__":
    asyncio.run(main())
```

`Knowledge.ainsert()` awaits reader and embedding work. PgVector uses a synchronous SQLAlchemy engine for database writes. `PgVector.async_search()` runs the synchronous search method in a worker thread.

## Run the Example

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

**1. Install dependencies**

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

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

**2. Export the API key**

```bash theme={null}
export OPENAI_API_KEY=your_openai_api_key_here
```

**3. Run the example**

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

## Next Steps

| Task | Guide |
| - | - |
| Use the synchronous API | [PgVector usage](https://agno-v2.mintlify.site/knowledge/vector-stores/pgvector/usage/pgvector-db.md) |
| Configure search behavior | [PgVector overview](https://agno-v2.mintlify.site/knowledge/vector-stores/pgvector/overview.md) |


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