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

# 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

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

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

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

  <Step title="Export the API key">
    ```bash theme={null}
    export OPENAI_API_KEY=your_openai_api_key_here
    ```
  </Step>

  <Step title="Run the example">
    ```bash theme={null}
    python async_pgvector_db.py
    ```
  </Step>
</Steps>

## Next Steps

| Task                      | Guide                                                                 |
| ------------------------- | --------------------------------------------------------------------- |
| Use the synchronous API   | [PgVector usage](/knowledge/vector-stores/pgvector/usage/pgvector-db) |
| Configure search behavior | [PgVector overview](/knowledge/vector-stores/pgvector/overview)       |
