Qdrant Hybrid Search

Combine dense and sparse vectors in one Qdrant search with SearchType.hybrid.

Code

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

COLLECTION_NAME = "thai-recipes"

vector_db = Qdrant(
    collection=COLLECTION_NAME,
    url="http://localhost:6333",
    search_type=SearchType.hybrid,
)

knowledge = Knowledge(
    name="My Qdrant Vector Knowledge Base",
    vector_db=vector_db,
)

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

def qdrantdb_agent(user: str = "user"):
    agent = Agent(
        user_id=user,
        knowledge=knowledge,
        search_knowledge=True,
    )

    while True:
        message = Prompt.ask(f"[bold] :sunglasses: {user} [/bold]")
        if message in ("exit", "bye"):
            break
        agent.print_response(message)

if __name__ == "__main__":
    typer.run(qdrantdb_agent)

To disable sparse-model downloads, pre-cache the sparse model and pass fastembed_kwargs={"local_files_only": True, "cache_dir": "/path/to/local/model/cache"} to load it from the cache. This only configures the sparse embedder. The example still needs network access for OpenAI dense embeddings, the agent model, and the PDF download. Fully offline operation also requires local dense embeddings, a local language model and content, and local Qdrant:

Qdrant(
    collection="my_collection",
    search_type=SearchType.hybrid,
    fastembed_kwargs={
        "local_files_only": True,
        "cache_dir": "/path/to/cached/models",
    },
)

Usage

Set up your virtual environment

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

Install dependencies

uv pip install -U qdrant-client fastembed typer rich pypdf openai agno

Set environment variables

export OPENAI_API_KEY=xxx

Run Qdrant

docker run -d --name qdrant -p 6333:6333 qdrant/qdrant:latest

Run Agent

python qdrant_db_hybrid_search.py