Copy
Ask AI
"""
Qdrant Hybrid Search
====================
Demonstrates Qdrant hybrid retrieval in an interactive loop.
"""
import typer
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.qdrant import Qdrant
from agno.vectordb.search import SearchType
from rich.prompt import Prompt
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
COLLECTION_NAME = "thai-recipes"
vector_db = Qdrant(
collection=COLLECTION_NAME,
url="http://localhost:6333",
search_type=SearchType.hybrid,
)
# ---------------------------------------------------------------------------
# Create Knowledge Base
# ---------------------------------------------------------------------------
knowledge = Knowledge(
name="My Qdrant Vector Knowledge Base",
vector_db=vector_db,
)
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
def qdrantdb_agent(user: str = "user"):
agent = Agent(
user_id=user,
knowledge=knowledge,
search_knowledge=True,
)
while True:
message = Prompt.ask(f"[bold]{user}[/bold]")
if message in ("exit", "bye"):
break
agent.print_response(message)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
def main() -> None:
knowledge.insert(
name="Recipes",
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
metadata={"doc_type": "recipe_book"},
)
typer.run(qdrantdb_agent)
if __name__ == "__main__":
main()
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/qdrant_db
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
python qdrant_db_hybrid_search.py