Keyword, Vector or Hybrid Search for RAG? We Measured All Three on BEIR SciFact

Murtaza Shajapurwala ·

Every retrieval-augmented generation (RAG) system has to decide how it finds the passages it hands the model. Keyword search matches words, vector search matches meaning, and hybrid search fuses the two. The usual advice is to use hybrid. We wanted a number instead of advice, so we ran all three on a public benchmark, on one free KiviDB Cloud database, and measured both quality and latency.

The short version: on SciFact, vector search won, hybrid came a close second, and keyword search was last. Vector queries took 2.6 ms from a client in the same AWS region. The rest of this post is how we ran it, so you can repeat it on your own data.

The benchmark

SciFact is one of the datasets in BEIR, the standard collection for comparing retrieval systems. It has 5,183 scientific abstracts and 300 test claims, such as "0-dimensional biomaterials show inductive properties", each with judgements of which abstracts support or refute it. Its claims are phrased differently from the abstracts that answer them, which is exactly the situation RAG systems face when users ask questions in their own words.

We scored each method with nDCG@10 (are the right abstracts near the top of the first ten?) and recall@10 (how many of the right abstracts are in the first ten at all), the two measures BEIR reports.

The setup

Embeddings. We used BAAI/bge-small-en-v1.5, an open 384-dimension model that runs on a CPU. Embedding all 5,183 abstracts took about 13 minutes on a laptop; the 300 claims took 4 seconds. Claims get the model's search instruction prefix; abstracts are the title plus the text.

Storage and index. One hash per abstract holding its title, text and vector, and one index over all three fields:

FT.CREATE sf ON HASH PREFIX 1 sf:doc:
  SCHEMA title TEXT text TEXT
         vec VECTOR HNSW 6 TYPE FLOAT32 DIM 384 DISTANCE_METRIC COSINE

Loading the 5,183 hashes in pipelines of 250 took 47 seconds from a laptop in India to a free-tier database in Frankfurt (eu-central-1). The index then covered every document in 15.5 seconds.

Three retrievals per claim.

  • Keyword: the claim's words, stop words removed, OR'd together over title and text.
  • Vector: the 50 nearest abstracts by cosine similarity.
  • Hybrid: both top-50 lists fused by reciprocal rank fusion (RRF, k = 60), in the client.
def rrf(lists, k=10, c=60):
    score = {}
    for ranked in lists:
        for rank, doc in enumerate(ranked):
            score[doc] = score.get(doc, 0) + 1 / (c + rank + 1)
    return sorted(score, key=score.get, reverse=True)[:k]

keyword = r.execute_command("FT.SEARCH", "sf", "(" + "|".join(words) + ")",
                            "RETURN", "0", "LIMIT", "0", "50", "DIALECT", "2")
vector  = r.execute_command("FT.SEARCH", "sf", "*=>[KNN 50 @vec $v AS d]",
                            "PARAMS", "2", "v", embedding.tobytes(),
                            "RETURN", "0", "LIMIT", "0", "50", "DIALECT", "2")

Quality: vectors led on every measure

Bar chart: nDCG@10 and recall@10 on BEIR SciFact. Keyword 0.633 and 0.757, vector 0.699 and 0.820, hybrid 0.688 and 0.813.

RetrievalnDCG@10Recall@10
Keyword0.6330.757
Vector0.6990.820
Hybrid (RRF)0.6880.813

Our vector score through KiviDB, 0.699, is close to the model's published SciFact score of about 0.71, which is a useful check that the index returns what an exact search would.

Hybrid search did not beat vectors alone. Fusing in keyword results moved some keyword-only matches above better vector ones, and nDCG fell by 0.011. That is not an argument against hybrid search in general. Hybrid tends to help where exact strings matter, such as product names, error codes, people and identifiers, and SciFact has few of those. The lesson is to measure on your own questions before you assume a fusion step is free accuracy.

Latency: where the time goes

We timed the same 300 queries from a task running in AWS eu-central-1, the database's region, taking the second of two passes.

Bar chart of query latency from a client in the same AWS region. Vector KNN 50: 2.6 ms median, 2.8 ms p95. Keyword with the 8 rarest words: 110 and 301 ms. Keyword with all words: 171 and 472 ms. Hybrid with all words: 172 and 473 ms.

QueryMedian95th percentile
Vector, top 502.6 ms2.8 ms
Keyword, all words171 ms472 ms
Keyword, 8 rarest words110 ms301 ms
Hybrid, all words172 ms473 ms

The network round trip to the database was 1.8 ms, so a vector query spent well under a millisecond in the engine.

Keyword search was the slow half, and its cost followed how many documents its words matched. A single common word, cell, matched 1,826 of the abstracts and took 54 ms on its own. Long claims OR'd together touch thousands of postings. Searching only each claim's eight rarest words (by document frequency in the corpus) cut the keyword median from 171 to 110 ms, and hybrid nDCG stayed at 0.687. Hybrid runs both searches at once, so it costs as much as its slower half.

These timings come from a free-tier database, which shares its host with other tenants and has a 100 MB memory limit. Retrieval quality does not depend on the hardware; latency does, so treat the numbers as an order of magnitude for a small index rather than a ceiling.

What we took away

  1. Start with vectors and measure before adding fusion. On semantic questions, a good embedding model carried the result on its own.
  2. Keep the keyword side short. If you do run hybrid, the keyword query is where the time goes; fewer, rarer words keep it fast without hurting quality here.
  3. A free database is enough to evaluate. The whole study, 5,183 documents with vectors and a full-text index, fit in a free KiviDB Cloud database.

Repeat it

SciFact is public through BEIR and the model is on Hugging Face. The commands above are the ones we ran; any KiviDB database with search can hold the index. The full method and every figure are on the case study page.

SciFact: Wadden et al., 2020, distributed in BEIR (Thakur et al., 2021). We report scores only and do not republish the corpus.