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

# Insert, Search, and Delete with LanceDB

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

```python lance_db.py theme={null}
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.lancedb import LanceDb

vector_db = LanceDb(table_name="recipes", uri="tmp/lancedb")
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(
        "List the ingredients for Massaman Gai.",
        markdown=True,
    )

    vector_db.delete_by_name("Recipes")
    # To delete by metadata instead:
    # vector_db.delete_by_metadata({"doc_type": "recipe_book"})
```

Choose one deletion method after the search. `delete_by_name()` and `delete_by_metadata()` load matching rows and delete their IDs from the LanceDB table.

## Run the Example

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

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno lancedb openai pypdf
```

**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 lance_db.py
```

## Next Steps

| Task | Guide |
| - | - |
| Call async Agno methods | [Async LanceDB usage](https://agno-v2.mintlify.site/knowledge/vector-stores/lancedb/usage/async-lance-db.md) |
| Configure hybrid search | [LanceDB hybrid search](https://agno-v2.mintlify.site/knowledge/vector-stores/lancedb/usage/lance-db-hybrid-search.md) |
| Configure search behavior | [LanceDB overview](https://agno-v2.mintlify.site/knowledge/vector-stores/lancedb/overview.md) |


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