Vector and hybrid retrieval for RAG, measured on the same embeddings in pgvector, Qdrant and OpenSearch. One embedding pass, three engines under identical limits, exact ground truth, and the trade-offs that actually decide a production choice: recall against latency, what a filter does to recall, how long an index takes to build and how much memory it holds, what happens under concurrent load and while rows are being written, and whether BM25, vectors or both find the relevant documents.
The question behind it is the one every RAG system meets early: do we need a vector database, or is Postgres enough — and do we need hybrid search at all? Vendor benchmarks answer it for their own engine. This repository answers it with public data, pinned versions and numbers anyone can rerun, including the ones that flatter nobody.
All figures come from MEASUREMENTS.md, which has the method, the environment and every table.
| Question | Measured |
|---|---|
| Does the engine change retrieval quality? | No. On the same vectors, pgvector, Qdrant and OpenSearch are within 0.0015 nDCG@10 of exact search on SciFact, ArguAna and Touché 2020 |
| Is hybrid search worth it? | As a hedge. RRF of BM25 and vectors: +1.3 points of nDCG@10 over vector search on SciFact, +7.3 on Touché (where BM25 alone wins), −2.2 on ArguAna. The best recall@100 of any bge-small method on all three |
| Can Postgres do the keyword half? | Not with built-in full-text. The best variant measured trails BM25 by 8–23 points, hybrid built on it scores below vector search alone on all three datasets, and a long ArguAna query takes about 8 s. The ranker most examples use (ts_rank_cd) halves SciFact's score; AND semantics find nothing for 274 of 300 queries |
| How fast, at the same recall? | Indistinguishable single-client. At recall@10 ≈ 0.97 over 381,559 vectors: p50 0.66 ms pgvector HNSW, 0.68 Qdrant, 0.79 OpenSearch, on round-trip floors of 0.15–0.28 ms. IVFFlat needs 3.78 ms for the same recall. Past 0.99 recall pgvector's p95 grows fastest (9.05 ms at ef_search 640, against 4.61 and 2.98) |
| How far does it scale on 4 CPUs? | Peak throughput at 8 clients: Qdrant 5,643 QPS (p95 2.1 ms), OpenSearch 4,920, pgvector HNSW 4,483; IVFFlat tops out at 732 |
| What does a selective filter do? | Post-filtering silently returns less. At 1% selectivity pgvector's HNSW returns 0.38 rows of 10 and OpenSearch's post-filter 0.10, as fast as a full answer. pgvector's relaxed_order iterative scan brings recall back to 0.964 at 13× the latency; Qdrant and OpenSearch switch to exact search (1.000, about 1 ms). The middle is the risk: at 10%, OpenSearch's efficient filter gives 0.745, Qdrant 0.925, pgvector 0.949 |
| What does it cost to build and hold? | Median build from scratch: pgvector HNSW 66 s, IVFFlat 16 s, Qdrant 76 s, OpenSearch 91 s. pgvector: 739 MiB of HNSW index on a 597 MiB table, every vector stored twice. Qdrant: 821 MiB on disk. OpenSearch: 1,181 MiB store, 614 MiB native graph, 3.7 GiB container including a 2 GiB heap |
| What happens while rows are written? | pgvector is slow to write and steady to read: 639 rows/s, query p50 unchanged, everything searchable on commit. Qdrant ingests 25× faster (15,921 rows/s) but its p50 rose from 0.66 to 2.30 ms until the optimiser finished, 86 s later. OpenSearch: 3,086 rows/s, searchable within its 1 s refresh |
| Would a bigger model help more? | Yes, here. bge-base adds 2.8 and 3.4 points of nDCG@10 on SciFact and ArguAna, more than fusion did, for 3.4–3.5× the embedding time |
Each failure here changed the design; the failure log lists what and where.
flowchart LR
beir[("BEIR datasets<br/>SciFact · ArguAna · Touché 2020")] -->|rbench download| corpus["corpus, queries,<br/>qrels"]
corpus -->|"rbench embed<br/>bge-small, pinned"| npy[("float32 vectors<br/>.npy, normalised")]
npy --> truth["exact kNN<br/>numpy, ± filter mask"]
subgraph engines["Docker Compose · 4 CPUs, 5 GiB each"]
pg["PostgreSQL 18<br/>pgvector 0.8.7<br/>HNSW · IVFFlat · tsvector"]
qd["Qdrant 1.19.2<br/>HNSW · payload index"]
os["OpenSearch 3.9.0<br/>Faiss HNSW · BM25<br/>RRF pipeline"]
end
npy -->|same arrays, row ids 0..n-1| pg & qd & os
corpus -->|text| pg & os
pg & qd & os --> runner["rbench ann / churn / quality<br/>sweeps · filters · processes"]
truth --> runner
corpus -->|qrels| runner
runner --> json[("results/*.json")]
json -->|rbench report| charts["charts · tables"]
- One set of vectors. Every corpus is embedded once and every engine loads the same normalised float32 arrays and uses inner product, so a recall gap is an index gap (ADR 1).
- Exact ground truth. Brute force in numpy, with the filter applied, for every query; recall@10 is measured against it.
- Same recall, then compare. Each engine's recall–latency curve is swept; single-number comparisons happen at each engine's own recall@10 ≥ 0.95 point (ADR 2).
- Timing a client would see, one engine at a time, warm, five interleaved passes, medians, and only on mains power (ADR 3).
- Quality against human judgements, for BM25, Postgres full-text, vector and hybrid (ADR 5).
uv sync --extra embed # torch + sentence-transformers, only for embedding
make data embed # download BEIR sets, embed once (about 80 min on an M5 GPU)
make quality # nDCG@10 / recall@100, all three datasets
make ann churn # timed runs, one engine at a time; waits for AC power
make report # charts and results/tables.md
make check # ruff, mypy --strict, pytest
make smoke # the CI run: generated data through every adapter- Choose the engine for operations, not for quality. Given the same vectors the three return the same documents (within 0.0015 nDCG@10), and at recall ≈ 0.97 their median latency differs by 0.13 ms. What differs is write behaviour, filtering, memory and throughput under load.
- Never post-filter a selective query. It does not fail, it returns four rows
instead of ten (pgvector, 10%) or almost none (OpenSearch, 1%). On pgvector 0.8+, set
hnsw.iterative_scan = relaxed_order; it beatstrict_orderby 4–7 points of recall at 10% and 1%. In OpenSearch, put the filter inside theknnclause. - Test the middle selectivities, not just the extremes. 1% is easy for Qdrant and OpenSearch because they fall back to exact search; at 10% OpenSearch's filtered graph walk lost nearly a quarter of its recall (0.745).
- For hybrid, use a real BM25. Postgres's built-in full-text made hybrid worse than
no hybrid on every dataset. If it has to be Postgres, OR the terms and rank with
ts_rank(…, 1), and expect seconds per long query. - Match the engine to the write pattern. For a corpus that changes all day, pgvector's synchronous index keeps reads steady and writes slow (639 rows/s); for bulk refreshes, Qdrant loads 25× faster but needs its optimiser's time (86 s here) before query latency recovers. Plan reindexing windows accordingly.
- Do not use IVFFlat for latency-sensitive search at this size. Same recall, 5.7× the latency of HNSW and a sixth of the throughput; it wins only on build time (16 s) and insert speed.
- Measure hybrid on your own data before turning it on. It lost 2.2 points on ArguAna. Where both were measured, a better embedding model gained more than fusion.
- Pick
ef_searchfrom a recall measurement, not a default. The same value gave recall@10 from 0.82 to 0.90 across engines, and builds of one engine vary by a point. - Check an evaluation set for near-duplicates of its own queries. 98.5% of the ANN
queries here had one; recall looked like 0.965 at
ef_search = 10until they were held out.
Things that went wrong, what they showed, and what changed because of them.
| # | What happened | What it meant | What changed |
|---|---|---|---|
| 1 | The first pgvector sweep reached recall@10 0.965 at ef_search = 10 on 382k vectors |
98.5% of the ArguAna queries had a document at cosine ≥ 0.95 in args.me: both collections scraped idebate.org, so the index already held the queries | The 986 near-duplicates are held out of the ANN corpus; a query's median similarity to its nearest document fell from 0.988 to 0.861, in line with Touché's own topics at 0.866 (ADR 4, experiments.ann_data) |
| 2 | In the same run, one setting's QPS rose 459 → 591 → 703 over three passes, and p50 was not monotonic in ef_search |
A 50-query warm-up after an index build is not a warm-up | A full warm-up pass per point, five timed passes, interleaved across the sweep (bench.run_points) |
| 3 | The rerun was several times slower: p50 5.65 ms at ef_search = 10 against 1.26 ms |
The machine had been unplugged; on battery macOS switches on Low Power Mode | Timed runs refuse to start, and fail at the end, unless on AC power with Low Power Mode off; the state is recorded in each result (ADR 3, envinfo.require_ac) |
| 4 | OpenSearch took 6.5 ms per query on 5,000 vectors while its took said 1 ms |
Not a bug: a match_all costs 2.8 ms at the client with took 0; that is request handling outside the timer |
Latency is client-observed and every engine's round-trip floor is published next to it (ADR 3) |
| 5 | OpenSearch reported a 39 KB index for 5,183 vectors | Store stats read straight after a force-merge are stale; the index was 16.8 MB | Flush before reading sizes (OpenSearchEngine.sizes) |
| 6 | Postgres full-text found nothing for 274 of 300 SciFact claims | websearch_to_tsquery ANDs every term; the ts_rank_cd ranking most examples use scored 0.330 even with ORed terms |
Terms ORed and ranked with ts_rank(…, 1): 0.604 (ADR 5) |
| 7 | Single ArguAna full-text queries ran for 3 to 8 seconds | An ORed argument matches almost every document and Postgres ranks every match; one serial pass of one ranker over 1,406 queries takes hours | Four connections, and the three-ranker comparison kept to SciFact (experiments._fts_parallel) |
| 8 | The Hugging Face mirror of BEIR tags every subset with the same licence | A mirror's tag is not the licence of the data | Each original release checked; NFCorpus and NQ could not be confirmed and were left out (NOTICE, ADR 4) |
- One machine. The engines run in Docker's VM on the same host as the client, so there is no real network between application and database, and absolute latency includes host-to-VM forwarding and a Python client. Per-engine floors are published; differences larger than them are the engines.
- Not an idle host. Other applications ran throughout (one used about a core), and a network filter on the host sees the loopback traffic. Interleaved passes and medians blunt this; they do not remove it.
- Everything fits in memory. 381,559 × 384 float32 is 586 MB of raw vectors. No
quantisation (pgvector
halfvec/binary, Qdrant scalar/binary, OpenSearch compression levels), no on-disk indexes and no multi-node setups were measured; those change the picture at larger scales. - Shared parameters, not tuned ones. HNSW is
m = 16, ef_construction = 100in all three; everything else is a default. OpenSearch is force-merged to one segment, which helps its query latency more than a live index with many segments would see; Qdrant keeps its default segment layout. - Queries. ANN latency uses ArguAna arguments as queries: long and passage-like. Question-shaped queries (Touché's 49 topics) are checked for recall only.
- One synthetic filter.
bucketis a hash, uncorrelated with content — the hardest case for a graph index and the cleanest test, but tenant or date filters correlate with content and behave differently. - Hybrid is RRF only,
k = 60over the top 100 of each leg: no score normalisation, no weights, no re-ranker. BM25 comes from OpenSearch only; Postgres BM25 extensions (ParadeDBpg_search) and Qdrant sparse vectors were not tested. - Quality differences are not significance-tested, and Touché's 49 topics make its nDCG noisy.
- Updates are inserts only, from one writer: no updates, deletes or vacuum/compaction under load.
An engine is one class in src/retrieval_bench/engines/ that satisfies the Engine
protocol in base.py:
| method | contract |
|---|---|
build(vectors, buckets, texts=None) |
create the collection from scratch, load rows with ids 0..n-1 and the bucket attribute, build the index; return load and index seconds and sizes |
search(Query) |
top-k row ids, best first; honour ef or probes, bucket_lt and strategy |
strategies() |
the filter strategies it offers, so the filtered runs cover each one |
insert, settle |
the normal write path, and "everything acknowledged is now searchable" |
sizes, ping, drop, close |
footprint as the engine reports it, the cheapest round trip, cleanup |
Then:
- add the service to
docker-compose.ymlwith the sharedx-limits; - register the name in
engines/__init__.py(make) and inexperiments.CONTAINER; - add it to
ENGINESin the Makefile and to the smoke run; make smoke, thenmake ann churn.
If the engine has text search, give it bm25/fts and hybrid methods and add it to
experiments.QUALITY_ENGINES.
Apache-2.0, see LICENSE. Dataset and model licences are in NOTICE; no corpus text is committed.