Milvus

Insert a PDF, query it with an agent, and delete Milvus records by name or metadata.

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

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(
    name="My Milvus Knowledge Base",
    description="This is a knowledge base that uses a Milvus DB",
    vector_db=vector_db,
)

knowledge.insert(
    name="Recipes",
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    metadata={"doc_type": "recipe_book"},
)

agent = Agent(knowledge=knowledge)
agent.print_response("How to make Tom Kha Gai", markdown=True)

vector_db.delete_by_name("Recipes")

vector_db.delete_by_metadata({"doc_type": "recipe_book"})

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