Milvus Async

Insert knowledge and run an agent with ainsert() and aprint_response() on a Milvus backend.

This example uses Milvus Lite with a local .db file. Install the Lite extra on a platform supported by your selected Milvus Lite version; use a server URI instead when local Lite is unavailable.

Code

async_milvus_db.py
import asyncio
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.milvus import Milvus

vector_db = Milvus(
    collection="recipes",
    uri="/tmp/milvus.db",
)

knowledge = Knowledge(
    vector_db=vector_db,
)

agent = Agent(knowledge=knowledge)

async def main():
    await knowledge.ainsert(
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
    )
    await agent.aprint_response("How to make Tom Kha Gai", markdown=True)

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

Usage

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U "pymilvus[milvus-lite]" pypdf openai agno

Set environment variables

export OPENAI_API_KEY=xxx

Run Agent

python async_milvus_db.py