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/activate

Install dependencies

uv pip install -U agno lancedb openai pypdf

Export the API key

export OPENAI_API_KEY=your_openai_api_key_here

Run the example

python agent_with_knowledge.py

Search Modes

search_typeBehavior
SearchType.vectorSearches by embedding similarity
SearchType.keywordUses LanceDB native full-text search
SearchType.hybridRuns LanceDB hybrid vector and full-text search

Parameters

ParameterTypeDefaultDescription
uristr/tmp/lancedbThe URI to connect to.
tableLanceTable-The Lance table to use.
table_namestr-The name of the table to use.
connectionDBConnection-The database connection to use.
api_keystr-The API key to use.
embedderEmbedder-The embedder to use.
search_typeSearchTypevectorThe search type to use.
distanceDistancecosineThe distance to use.
nprobesint-The number of probes to use. More Info
rerankerReranker-The reranker to use. More Info
on_bad_vectorsstr-What to do if the vector is bad. One of "error", "drop", "fill", "null".
fill_valuefloat-The value to fill the vector with if on_bad_vectors is "fill".
async_connectionOptional[lancedb.AsyncConnection]NoneExisting async connection to use.
async_tableOptional[lancedb.db.AsyncTable]NoneExisting async table to use.
nameOptional[str]NoneName of the vector database.
descriptionOptional[str]NoneDescription of the vector database.
idOptional[str]GeneratedID derived from the URI and table name when omitted.

Next Steps

TaskGuide
Insert, search, and delete contentLanceDB usage
Call async Agno methodsAsync LanceDB usage
Configure hybrid searchLanceDB hybrid search

Developer Resources