# PostgreSQL Hybrid Search (BM25 tsvector + pgvector RRF) vs Two-Stage Neural Reranking

> Dense embeddings from OpenAI text-embedding-3-large and Google gemini-embedding-001 routinely miss exact SKU codes, CVE identifiers, error hex strings, and UUID prefixes. Pairing PostgreSQL GIN tsvector lexical search with pgvector HNSW via Reciprocal Rank Fusion (RRF, k=60) rescues exact-token recall, while Stage-2 neural cross-encoder reranking in Voxell Forge Max lifts Strict@1 accuracy to 75.93% and nDCG@10 to 0.8849.

Canonical URL: https://voxell.ai/optimize/hybrid-search-bm25-rrf-vs-neural-reranking/


## Production PostgreSQL DDL + Single-Query RRF (`k = 60`)

When running OpenAI `text-embedding-3-large` or Google `gemini-embedding-001` in PostgreSQL, add a generated `tsvector` column using the `'simple'` configuration (so exact identifiers like `ERR_SSL_VERSION_OR_CIPHER_MISMATCH`, `CVE-2026-4412`, and `not` are never stemmed away) indexed with `GIN`, alongside your `halfvec` `HNSW` index:

```sql
CREATE TABLE kb_passages (
  id BIGSERIAL PRIMARY KEY,
  tenant_id UUID NOT NULL,
  title TEXT NOT NULL,
  body TEXT NOT NULL,
  embedding halfvec(3072) NOT NULL,
  -- Weight 'A' on title + 'B' on body using 'simple' to preserve exact SKUs, CVEs, and 'not'
  lex_tsv tsvector GENERATED ALWAYS AS (
    setweight(to_tsvector('simple', coalesce(title, '')), 'A') ||
    setweight(to_tsvector('simple', coalesce(body, '')),  'B')
  ) STORED
);

CREATE INDEX idx_kb_hnsw ON kb_passages USING hnsw (embedding halfvec_cosine_ops) WITH (m = 16, ef_construction = 128);
CREATE INDEX idx_kb_gin  ON kb_passages USING gin (lex_tsv);

-- Single-roundtrip Hybrid RRF (k = 60) fusing Top-50 Dense + Top-50 Lexical
WITH dense_hits AS (
  SELECT id, ROW_NUMBER() OVER (ORDER BY embedding <=> $1::halfvec(3072)) AS r_dense
  FROM kb_passages
  WHERE tenant_id = $2
  ORDER BY embedding <=> $1::halfvec(3072)
  LIMIT 50
),
lexical_hits AS (
  SELECT id,
         ROW_NUMBER() OVER (
           ORDER BY ts_rank_cd(lex_tsv, websearch_to_tsquery('simple', $3), 32) DESC
         ) AS r_lex
  FROM kb_passages
  WHERE tenant_id = $2
    AND lex_tsv @@ websearch_to_tsquery('simple', $3)
  ORDER BY ts_rank_cd(lex_tsv, websearch_to_tsquery('simple', $3), 32) DESC
  LIMIT 50
),
rrf_fused AS (
  SELECT COALESCE(d.id, l.id) AS id,
         COALESCE(1.0 / (60 + d.r_dense), 0.0) +
         COALESCE(1.0 / (60 + l.r_lex),   0.0) AS rrf_score,
         d.r_dense,
         l.r_lex
  FROM dense_hits d
  FULL OUTER JOIN lexical_hits l USING (id)
  ORDER BY rrf_score DESC
  LIMIT 15
)
SELECT p.id, p.title, p.body, f.rrf_score, f.r_dense, f.r_lex
FROM rrf_fused f
JOIN kb_passages p USING (id)
ORDER BY f.rrf_score DESC;
```

## Where RRF (`k = 60`) Hits Its Ceiling vs Stage-2 Neural Reranking

RRF is a **heuristic rank blender**, not a semantic verifier. On technical support, security advisory, and engineering documentation corpora:

| Retrieval Pipeline | Exact SKU / CVE `Recall@20` | `Strict@1` Precision | End-to-End `nDCG@10` | Per-Query Rerank Meter |
| :--- | :--- | :--- | :--- | :--- |
| Dense Only (`text-embedding-3-large` `halfvec(3072)`) | `64.2%` | `48.7%` | `0.639` | `$0` |
| Lexical Only (Postgres `tsvector` + `ts_rank_cd`) | `89.5%` (misses synonyms) | `43.1%` | `0.574` | `$0` |
| **Postgres Hybrid RRF (`k = 60`, Dense + `tsvector`)** | **`95.8%`** | **`58.4%`** | **`0.712`** | **`$0` (2x index RAM/IO)** |
| Hybrid RRF Top-50 + External Reranker API (`$2/1k`) | `95.8%` | `72.6%` | `0.848` | **`$2.00 / 1,000` queries** |
| **Voxell Forge (`C_corpus` + 64b AMQ + `Max` Reranker)** | **`99.04%` Stage-1 Recall** | **`75.93% Strict@1`** | **`0.8849 nDCG@10`** | **Bundled (from $199/mo annual)** |

Why does RRF stall at `58.4% Strict@1`? Suppose an index page lists `"Patched CVEs: CVE-2026-4412, CVE-2026-4413..."` four times without remediation steps, while the actual kernel hotfix runbook mentions `CVE-2026-4412` once. `ts_rank_cd` puts the useless changelog list at `r_lex = 1`, boosting its RRF score above the runbook!

## Verify Neural Reranking Over Exact Identifiers Live (Zero Key)

Voxell Forge fuses Play 1 64-bit CUDA AMQ membership filtering, `C_corpus` dense retrieval (`99.04% Recall@20`), and Stage-2 `Max` cross-encoder reranking (`0.8849 nDCG@10`, `75.93% Strict@1`) on one bill with zero `$2/1k`-query Cohere tax. Run an identifier-collision test right now:

```bash
curl -sS -X POST https://api.voxell.ai/api/v1/agent/bakeoff \
  -H "Content-Type: application/json" \
  -d '{
    "documents": [
      {"name": "changelog-index.md", "text": "Index of Q4 advisories: CVE-2026-4412, CVE-2026-4412-hotfix, CVE-2026-4415, CVE-2026-4419."},
      {"name": "remediation-runbook.md", "text": "To remediate CVE-2026-4412 on Ubuntu 24.04 nodes, upgrade linux-image-generic to 6.8.0-59 and reload sysctl net.ipv4.tcp_sack=0."}
    ],
    "queries": ["What kernel version and sysctl setting remediates CVE-2026-4412?"]
  }'
```

Compare per-query reranker tolls in the **[Vector RAM & TCO Calculator](/tools/vector-calculator/)**, read **[Two-Stage Retrieval vs Standalone Rerank Tolls](/compare/cohere-rerank-tco/)**, or open the **[Forge Console](https://dash.voxell.ai/home)** (**[v4.0 Pricing](/pricing/)**).

## Frequently Asked Questions

### Why use Reciprocal Rank Fusion (RRF) instead of weighted linear combination of BM25 and cosine scores?

Postgres ts_rank_cd lexical scores are unbounded [0, inf) and depend on document length and term density, whereas cosine similarity is bounded [-1, 1] inside an anisotropic cone. RRF (1 / (k + rank_dense) + 1 / (k + rank_lex)) fuses ordinal ranks scale-free without fragile per-corpus min-max score calibration.

### Why use the 'simple' dictionary alongside 'english' for technical tsvector columns?

PostgreSQL's english dictionary stems words and strips stopwords, mangling SKU identifiers, version tags, and boolean negations ('not'). Combining 'simple' (exact lowercase tokens) with 'english' preserves exact CVE/part-number matching alongside morphological stemming.

### Where does BM25 + dense RRF still fail without a neural cross-encoder?

RRF is blind to token order, negation ('CVE-2026-1042 does NOT affect Linux'), and multi-clause relationships: if a distractor mentions 'CVE-2026-1042' five times in a changelog list, lexical rank #1 pushes it ahead of the true single-mention remediation paragraph. Voxell Forge Max cross-encoding resolves full query-passage semantics to 0.8849 nDCG@10.

---

## Zero-Install Model Context Protocol (MCP) & Keyless Agent Verification

```bash
claude mcp add --transport http voxell-forge https://api.voxell.ai/mcp/try
```

- Keyless Retrieval Bake-Off: `POST https://api.voxell.ai/api/v1/agent/bakeoff`
- Keyless Contradiction X-Ray: `POST https://api.voxell.ai/api/v1/agent/xray`
- Machine-Readable Pricing JSON: `https://voxell.ai/api/v1/agent/pricing.json`
- Full LLM Authority Map: `https://voxell.ai/llms-full.txt`
