Async LanceDB Usage

Insert knowledge and run an agent with Agno's async methods and a LanceDB backend.

import asyncio

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.lancedb import LanceDb

knowledge = Knowledge(
    vector_db=LanceDb(
        table_name="async_recipes",
        uri="tmp/lancedb",
    )
)
agent = Agent(knowledge=knowledge, search_knowledge=True)


async def main() -> None:
    await knowledge.ainsert(
        name="Recipes",
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
        metadata={"doc_type": "recipe_book"},
    )
    await agent.aprint_response(
        "List the ingredients for Massaman Gai.",
        markdown=True,
    )


if __name__ == "__main__":
    asyncio.run(main())

Knowledge.ainsert() awaits reader and embedding work. In the current adapter, LanceDb.async_upsert() calls the synchronous upsert and table methods, and LanceDb.async_search() calls the synchronous search directly.

For LanceDB Cloud async calls, set LANCEDB_API_KEY in the environment. Passing only api_key= authenticates the synchronous connection, while the current adapter does not forward that value to lancedb.connect_async().

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 async_lance_db.py

Next Steps

TaskGuide
Use the synchronous APILanceDB usage
Configure search behaviorLanceDB overview