Copy
Ask AI
"""
Milvus Hybrid Search
====================
Demonstrates Milvus hybrid search with sync and async flows.
"""
import asyncio
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.milvus import Milvus, SearchType
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
vector_db = Milvus(
collection="recipes",
uri="/tmp/milvus_hybrid.db",
search_type=SearchType.hybrid,
)
# ---------------------------------------------------------------------------
# Create Knowledge Base
# ---------------------------------------------------------------------------
knowledge = Knowledge(vector_db=vector_db)
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(knowledge=knowledge)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
def run_sync() -> None:
knowledge.insert(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf")
agent.print_response("How to make Tom Kha Gai", markdown=True)
async def run_async() -> None:
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__":
run_sync()
asyncio.run(run_async())
Run the Example
Copy
Ask AI
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/07_knowledge/vector_db/milvus_db
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
python milvus_db_hybrid_search.py