LanceDB
Store and search Knowledge embeddings in a local or remote LanceDB table.
LanceDb supports vector, full-text, and hybrid search. A filesystem path creates a local database. A db:// URI connects to LanceDB Cloud and requires api_key= or LANCEDB_API_KEY.
In the current adapter, dictionary filters are applied after LanceDB returns the limited candidates, and filter-expression lists are ignored. Filtered searches can return fewer documents than requested. Search results also omit the stored LanceDB row ID.
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.lancedb import LanceDb
knowledge = Knowledge(
vector_db=LanceDb(
table_name="recipes",
uri="tmp/lancedb",
)
)
agent = Agent(knowledge=knowledge, search_knowledge=True)
if __name__ == "__main__":
knowledge.insert(
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
)
agent.print_response("How do I make pad thai?", markdown=True)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno lancedb openai pypdfExport the API key
export OPENAI_API_KEY=your_openai_api_key_hereRun the example
python agent_with_knowledge.pySearch Modes
search_type | Behavior |
|---|---|
SearchType.vector | Searches by embedding similarity |
SearchType.keyword | Uses LanceDB native full-text search |
SearchType.hybrid | Runs LanceDB hybrid vector and full-text search |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
uri | str | /tmp/lancedb | The URI to connect to. |
table | LanceTable | - | The Lance table to use. |
table_name | str | - | The name of the table to use. |
connection | DBConnection | - | The database connection to use. |
api_key | str | - | The API key to use. |
embedder | Embedder | - | The embedder to use. |
search_type | SearchType | vector | The search type to use. |
distance | Distance | cosine | The distance to use. |
nprobes | int | - | The number of probes to use. More Info |
reranker | Reranker | - | The reranker to use. More Info |
on_bad_vectors | str | - | What to do if the vector is bad. One of "error", "drop", "fill", "null". |
fill_value | float | - | The value to fill the vector with if on_bad_vectors is "fill". |
async_connection | Optional[lancedb.AsyncConnection] | None | Existing async connection to use. |
async_table | Optional[lancedb.db.AsyncTable] | None | Existing async table to use. |
name | Optional[str] | None | Name of the vector database. |
description | Optional[str] | None | Description of the vector database. |
id | Optional[str] | Generated | ID derived from the URI and table name when omitted. |
Next Steps
| Task | Guide |
|---|---|
| Insert, search, and delete content | LanceDB usage |
| Call async Agno methods | Async LanceDB usage |
| Configure hybrid search | LanceDB hybrid search |