Hybrid & Sparse Search

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A single Qdrant point can carry a dense vector, a sparse vector, or both, and the Query API can search across them in one request and merge the resulting rankings server-side — combining the semantic recall of dense embeddings with the exact-term precision of a sparse, BM25/SPLADE-style representation.

Why combine the two

Dense embeddings and sparse term vectors fail in opposite ways. A dense vector captures meaning, so "renew an expired certificate" finds the article about TLS renewal even without sharing words, but it can rank a thematically close yet wrong article above one containing the exact error code or product name you typed. A sparse vector matches on the terms themselves, so an exact identifier ranks first, but it knows nothing about synonyms. Hybrid search runs both and fuses the rankings, which is why it is the default retrieval strategy of most production RAG systems.

The running example on this page is a tiny help-center collection named articles: five articles, a 4-dimensional dense vector each (hand-made, standing in for an embedding model) and a sparse vector over a seven-word vocabulary (0 certificate, 1 tls, 2 expired, 3 renew, 4 password, 5 reset, 6 router). Every output below was produced by running the code against Qdrant 1.20.

id Title Sparse terms (index: weight)

1

Renewing an expired TLS certificate

0: 0.8, 1: 0.7, 2: 0.6, 3: 0.9

2

Resetting a forgotten password

4: 0.9, 5: 0.9

3

Why browsers distrust a certificate

0: 0.9, 1: 0.5

4

Rebooting the office router

6: 0.9

5

Certificate pinning explained

0: 0.6, 1: 0.4

Sparse vectors

A sparse vector is a pair of arrays: indices (token/dimension ids) and values (their weights), holding only the non-zero entries of what would otherwise be a very high-dimensional vector — the same shape produced by a bag-of-words model or a learned-sparse encoder such as SPLADE. Unlike a dense vector, a sparse vector has no fixed size: its dimensionality is implicit in whatever indices appear across the collection. A collection declares sparse-vector support separately from dense vectors_config, under its own named sparse_vectors_config, and each point can then set a value for that name alongside (or instead of) any named dense vector.

from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, SparseVectorParams

client = QdrantClient(url="http://localhost:6333")

client.create_collection(
    collection_name="articles",
    vectors_config={
        "dense": VectorParams(size=384, distance=Distance.COSINE),
    },
    sparse_vectors_config={
        "sparse": SparseVectorParams(),
    },
)

The SparseVectorParams() above takes optional settings. modifier=models.Modifier.IDF makes Qdrant multiply each stored weight by an inverse-document-frequency factor computed from the collection at query time, which is how a BM25-style scorer is built from raw term counts. index=models.SparseIndexParams(on_disk=..., full_scan_threshold=...) controls whether the inverted index lives on disk and below which size a scan replaces it. Both were accepted by a collection created with vectors_config={}, so a collection can hold only sparse vectors.

Upserting a point sets both the named dense vector and the named sparse vector on the same vector mapping. The code below is the runnable version for the five articles, with the real vocabulary indices:

from qdrant_client.models import PointStruct, SparseVector

articles = [
    (1, "Renewing an expired TLS certificate", [0.9, 0.1, 0.1, 0.0], {0: 0.8, 1: 0.7, 2: 0.6, 3: 0.9}),
    (2, "Resetting a forgotten password",      [0.1, 0.9, 0.1, 0.0], {4: 0.9, 5: 0.9}),
    (3, "Why browsers distrust a certificate", [0.7, 0.2, 0.3, 0.1], {0: 0.9, 1: 0.5}),
    (4, "Rebooting the office router",         [0.1, 0.1, 0.9, 0.2], {6: 0.9}),
    (5, "Certificate pinning explained",       [0.5, 0.1, 0.1, 0.6], {0: 0.6, 1: 0.4}),
]

client.upsert(
    collection_name="articles",
    wait=True,
    points=[
        PointStruct(
            id=point_id,
            vector={
                "dense": dense,
                "sparse": SparseVector(indices=list(terms), values=list(terms.values())),
            },
            payload={"title": title},
        )
        for point_id, title, dense, terms in articles
    ],
)

A sparse vector’s indices must be unique within one vector, and the dimensionality is implicit: in a real system the indices are token ids from a tokenizer vocabulary (30,522 for a BERT-family SPLADE model), not the seven toy ids used here.

Background on the representation, how it compares to dense embeddings, and how a SPLADE-style model produces the indices/values pairs is covered in Sparse Vectors.

Hybrid dense + sparse search and fusion

A hybrid query searches the dense vector and the sparse vector in the same request and combines their two ranked result lists into one. Qdrant’s Query API does this with prefetch: each prefetch entry runs its own vector search (naming which vector to use via using) and returns its own candidate list, then the outer query’s fusion step merges those lists. Because a dense cosine score and a sparse dot-product score live on unrelated scales, Qdrant’s built-in fusion method is Reciprocal Rank Fusion (RRF): it re-ranks by each point’s rank position in every child list rather than by the raw scores, so the two scales never need to be normalized against each other.

from qdrant_client.models import FusionQuery, Fusion, Prefetch, SparseVector

query_dense = [0.04, 0.63, 0.31, "...381 more floats..."]
query_sparse = SparseVector(indices=[42, 1337], values=[0.9, 0.4])

results = client.query_points(
    collection_name="articles",
    prefetch=[
        Prefetch(query=query_dense, using="dense", limit=20),
        Prefetch(query=query_sparse, using="sparse", limit=20),
    ],
    query=FusionQuery(fusion=Fusion.RRF),
    limit=10,
)
flowchart TD Q["query_points"] --> P1["Prefetch 1
dense vector, limit 20"] Q --> P2["Prefetch 2
sparse vector, limit 20"] P1 --> L1["Ranked list A"] P2 --> L2["Ranked list B"] L1 --> F["Fusion: RRF or DBSF"] L2 --> F F --> R["Final top limit points"]

Each Prefetch.limit bounds how many candidates that branch contributes before fusion; the outer limit bounds the final fused result. The prefetch + fusion mechanism, its parameters, and other fusion methods are documented in Hybrid Queries.

What fusion actually does

With the query query_dense = [0.8, 0.1, 0.2, 0.1] and a sparse query over certificate, expired and renew (indices=[0, 2, 3], values=[0.5, 0.7, 0.9]), each branch ranks the five articles on its own scale:

dense   [(1, 0.984), (3, 0.979), (5, 0.738), (4, 0.372), (2, 0.249)]      cosine similarity
sparse  [(1, 1.630), (3, 0.450), (5, 0.300)]                              dot product, only matching terms

The sparse branch returned only three points because only they share a term with the query; the other two have a zero dot product and are not candidates. The scores are incomparable (0.98 against 1.63), which is the reason fusion works on ranks. Reciprocal Rank Fusion gives each point a contribution from every list it appears in, with a zero-based rank and k = 2 by default, and sums them. The contribution of one list is 1 / (k + rank):

rrf     [(1, 1.000), (3, 0.667), (5, 0.500), (4, 0.200), (2, 0.167)]

Article 1 is first in both lists: 1/2 + 1/2 = 1.0. Article 3 is second in both: 1/3 + 1/3 = 0.667. Article 4 appears only in the dense list at rank 3: 1/5 = 0.2. A larger k flattens the curve so that deep ranks matter more; with k=10 the same data gives scores of 0.2, 0.182 and 0.167 for the top three, and the lead shrinks accordingly:

from qdrant_client.models import RrfQuery, Rrf

client.query_points(
    "articles",
    prefetch=[Prefetch(query=query_dense, using="dense", limit=5),
              Prefetch(query=query_sparse, using="sparse", limit=5)],
    query=RrfQuery(rrf=Rrf(k=10)),
    limit=5,
)
# [(1, 0.2), (3, 0.1818), (5, 0.1667), (4, 0.0769), (2, 0.0714)]

The other built-in method, Fusion.DBSF (distribution-based score fusion), keeps the scores: it normalizes each list using its own mean and standard deviation, then adds the normalized scores. On the same data it returns [(1, 1.348), (3, 1.075), (5, 0.923), (4, 0.357), (2, 0.297)]. Choose RRF when you do not trust the score scales and want a robust default; choose DBSF when score magnitudes carry information that rank positions would discard.

A case where hybrid rescues the answer

The value of fusion is clearest when one branch misses. Suppose a user asks about a forgotten password, but the query embedding is poor (here the vector [0.1, 0.2, 0.2, 0.8] points toward router and pinning topics), while the sparse query indices=[4, 5] (password, reset) is exact:

dense only    [(5, 0.841), (4, 0.464), (3, 0.369)]     the password article (2) is not in the top 3
sparse only   [(2, 1.800)]                              exact term match
rrf           [(2, 0.700), (5, 0.500), (4, 0.333)]     the password article is now first

Article 2 ranks first in the sparse list (1/2 = 0.5) and fourth in the dense list (1/5 = 0.2); the sum of 0.7 beats the dense winner, which appears only in one list. Neither retriever alone surfaced the right article first; the fusion did.

Filters, depth and nesting

Filters work at two levels. A filter inside a Prefetch restricts only that branch; a query_filter on the outer call restricts the final candidates. Restricting the dense branch to articles 1, 3 and 5 and fusing gives [(1, 0.5), (3, 0.333), (5, 0.25)], while a query_filter on the outer call is applied to the fused result.

Prefetch also nests, so a multi-stage pipeline is one request. This one fuses the two branches, keeps the top 3, and then re-scores those 3 by dense similarity, returning [(1, 0.984), (3, 0.979)]:

client.query_points(
    "articles",
    prefetch=Prefetch(
        prefetch=[Prefetch(query=query_dense, using="dense", limit=5),
                  Prefetch(query=query_sparse, using="sparse", limit=5)],
        query=FusionQuery(fusion=Fusion.RRF),
        limit=3,
    ),
    query=query_dense,
    using="dense",
    limit=2,
)

Re-ranking a candidate set

prefetch also composes as a general two-stage pipeline, independent of fusion: run a cheap first-pass search (dense or sparse) to pull a larger, inexpensive candidate set, then apply a more expensive re-ranking step — such as scoring each candidate’s full text against the query with a cross-encoder model — over only the top N. Because the second stage runs on a small, already-narrowed set, the expensive model only ever scores a handful of candidates instead of the whole collection.

sequenceDiagram participant App as Application participant Q as Qdrant participant R as Re-ranker App->>Q: dense prefetch, limit 50 Q-->>App: 50 candidates with payload App->>R: score query against each candidate text R-->>App: one score per candidate App->>App: sort by score, keep top 3

The code below runs the first stage in Qdrant and the second in the application. The "cross-encoder" here is a deliberately simple stand-in (the fraction of query words that occur in the title) so the example is runnable without a model download; in production the function body is replaced by CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2").predict(pairs) from sentence-transformers, and nothing else changes.

import re
from qdrant_client.models import Prefetch

query_text = "renew an expired certificate"

# Stage 1: cheap dense retrieval narrows the whole collection to (up to) 50 candidates.
candidates = client.query_points(
    collection_name="articles",
    prefetch=Prefetch(query=query_dense, using="dense", limit=50),
    query=query_dense,
    using="dense",          # the outer query needs `using` too on a named-vector collection
    limit=50,
    with_payload=True,
)

# Stage 2: an expensive scorer re-ranks only those candidates.
def words(text):
    return set(re.findall(r"[a-z]+", text.lower()))

def rerank_score(query, title):
    return len(words(query) & words(title)) / len(words(query))

reranked = sorted(candidates.points,
                  key=lambda hit: rerank_score(query_text, hit.payload["title"]),
                  reverse=True)[:3]
for hit in reranked:
    print(hit.id, hit.payload["title"], round(rerank_score(query_text, hit.payload["title"]), 2))

Output:

1 Renewing an expired TLS certificate 0.75
3 Why browsers distrust a certificate 0.25
5 Certificate pinning explained 0.25

Because the second stage sees at most 50 points, its cost is bounded however large the collection is; the trade-off is that a relevant point the first stage did not retrieve can never be rescued, so stage 1’s limit is a recall budget. Omitting using in the outer query is the most common mistake here: on a collection with named vectors the server answers Not existing vector name error.

The Query API also supports re-ranking with a vector stored on the point itself (for example a late-interaction/multivector re-ranker) as the outer query over a prefetch, without leaving Qdrant — see Hybrid Queries for that variant.

Where to go next

  • Filtering & Payload Indexing — narrowing the candidate set with payload filters before (or alongside) the vector search stages described here.

  • CRUD & Batch Operations — day-to-day point CRUD and batching once a collection’s dense/sparse vector configuration is in place.

  • Vector & semantic search — Elasticsearch composes hybrid search from an rrf retriever fusing a standard BM25 retriever with a knn retriever, versus Qdrant’s prefetch + fusion Query API shown above.

  • Text, wildcard, geospatial & Atlas search — MongoDB Atlas combines Atlas Search ($search) and Atlas Vector Search ($vectorSearch) via $rankFusion/compound aggregation pipelines, versus Qdrant’s native fusion.

  • Hybrid Search & Re-ranking — the vendor-neutral theory of score fusion, Reciprocal Rank Fusion and cross-encoder re-ranking behind this page’s Qdrant-specific hybrid queries.