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

# Insert, Search, and Delete with PgVector

> Insert a PDF, search it with an agent, and delete PgVector rows by name or metadata.

```python pgvector_db.py theme={null}
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector

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

if __name__ == "__main__":
    knowledge.insert(
        name="Recipes",
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
        metadata={"doc_type": "recipe_book"},
    )

    agent.print_response("How do I make pad thai?", markdown=True)

    vector_db.delete_by_name("Recipes")
    vector_db.delete_by_metadata({"doc_type": "recipe_book"})
```

`delete_by_name()` removes rows whose `name` matches exactly. `delete_by_metadata()` removes rows whose JSON metadata contains the supplied fields.

## 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 pgvector_db.py
    ```
  </Step>
</Steps>

## Next Steps

| Task                    | Guide                                                                                    |
| ----------------------- | ---------------------------------------------------------------------------------------- |
| Run async Agno methods  | [Async PgVector usage](/knowledge/vector-stores/pgvector/usage/async-pgvector-db)        |
| Configure hybrid search | [PgVector hybrid search](/knowledge/vector-stores/pgvector/usage/pgvector-hybrid-search) |
