Development

Deciding Whether a New Embedding Model Earns a Full Reindex

Antonio Evans9 min read

A hand at a workbench holds a checklist reading compare on the golden set and price the backfill, with a tray of judged query cards beside a large graph of connected nodes feeding a gauge for hours and storage.
Key points

Key points

  1. 1An HNSW index is built around one embedding model's vectors, so changing models means rebuilding the whole index, and that rebuild is the real cost you need to price.
  2. 2Run the candidate and the incumbent on the same judged golden set and compare recall@k and nDCG@k at the k you actually serve before touching production.
  3. 3Estimate the backfill as rows times new dimension for embedding volume, then add graph build time and a re-run of the same evaluation.
  4. 4Commit only when the recall gain is large enough to show up in product metrics and you can serve the new index as a shadow collection before flipping traffic.

Why a model swap forces a full rebuild

An approximate nearest neighbor index is not a neutral container for numbers. It is a graph or a set of clusters that encodes the distance relationships between the exact vectors you gave it. Change the embedding model and every vector changes, so the graph you tuned describes a space that no longer exists. HNSW specifically builds a multi-layer proximity graph where each node is a vector and edges connect near neighbors; the hierarchy makes search cost grow logarithmically with row count rather than linearly the Crunchy Data explainer. Feed it vectors from a different model and the edges point at the wrong neighbors.

The same logic applies to the incumbent's tuning. Build parameters set a ceiling on achievable recall, and search-time parameters only let you approach that ceiling; moving the ceiling means rebuilding the index the Qdrant recall tutorial. You cannot mix old and new vectors in one graph and expect either model's geometry to hold.

This is why the decision is not "is the candidate better on a leaderboard" but "is the candidate better enough, on my data, to justify rebuilding every vector and every edge." Public benchmark rankings lose predictive value when your corpus has domain vocabulary, unusual document lengths or fine-grained labels that differ from the benchmark corpora the Openlayer benchmarking guide. The only trustworthy judge is your own judged queries.

One nuance before you start: in HNSW systems a rebuild is not always a from-scratch job. Research on index merging shows that billion-scale HNSW construction can take days or weeks, and that merging sub-indexes built in parallel is a way to shorten that, though merge performance has historically been the bottleneck the HNSW-Merger paper. For a model swap, though, there is nothing to merge, because the existing graph holds the old model's vectors. Plan for a true backfill.

Build the golden set before you build anything else

A golden set is a fixed collection of test cases with known good answers that you run every candidate against. For retrieval, that means queries from your real users (or realistic ones), each paired with judged relevance labels for documents in your corpus. Teams commonly start with 50 to 200 query-document pairs drawn from the actual corpus and expected queries the DataAIHub retrieval evaluation guide. For a model-swap decision, aim higher: a few hundred judged queries gives you enough to see a real difference between two models.

Three rules make the set usable:

  1. Judge relevance, not similarity. Binary "relevant or not" labels are enough for recall; graded labels (0 to 3) let you compute nDCG. A valid benchmark needs real production queries, ground truth relevance labels and identical inputs across every candidate model the Openlayer guide.
  2. Keep it fixed. A golden set is the fixed set of cases you run before every meaningful change, so it must be versioned and never edited to make a candidate look good the Langfuse golden dataset guide.
  3. Sample from the workload you serve. A representative sample of query vectors from your workload, embedded with the same model your collection uses, is the standard practice for recall tests the Qdrant recall tutorial.

Split the set. Use roughly two thirds for the go/no-go comparison and hold back the rest to confirm the winner after the rebuild. This protects you from picking a model that happens to fit your sample.

Measure both models the same way, at the same k

The evaluation procedure is simple to state and easy to get wrong. For each query in the golden set, retrieve the top k results from the incumbent index and from a candidate index built on the same corpus, then compute the metrics. The critical constraint is that k must be the number you actually serve, whether that is the top 8 passages into a prompt or the top 50 into a reranker. Recall at a k you never use tells you nothing.

Recall@k is the fraction of the true exact neighbors that the approximate index returned, and production targets are typically 0.95 or higher the BigData Boutique comparison. For model swaps you want two different recall numbers:

  • Index recall, measured against exact search on the same model's vectors. This tells you whether your HNSW parameters are healthy, not whether the new model is better.
  • Retrieval recall, measured against the judged relevance labels. This is the number that should drive the decision.

A degraded ANN index never fails loudly. It returns k plausible neighbors and never mentions that it left out several of the good ones, with no error and no log entry, which is why recall has to be measured against exact ground truth rather than inferred from latency or user complaints the pg_recall_guard documentation.

For ranking quality, add nDCG@k, which accounts for graded relevance and gives you a fuller picture when some results are more relevant than others, and MRR if the first result matters most to your product the Openlayer guide. A useful caution: recall@k measures overlap with the exact neighbor set, and studies show downstream task quality can stay stable even when recall@k drops significantly, because closeness in distance matters more than identifier matches the ANN Recall What Matters paper. Treat recall as one input, and let your judged labels and product metrics arbitrate.

A worked comparison, with numbers invented for illustration:

Metric at k=10IncumbentCandidate ACandidate B
Retrieval recall@10 (judged)0.710.790.74
nDCG@100.640.700.66
ANN recall@10 vs exact search0.970.960.95
p95 query latency18 ms21 ms19 ms
Dimension7681024768
Vector storage per row3.0 KB4.0 KB3.0 KB

The decision rule this table suggests: Candidate B gains almost nothing for a full rebuild, so drop it. Candidate A gains 8 points of judged recall and 6 points of nDCG, which is large enough to plausibly move answer quality, but it costs a third more vector storage and one extra latency millisecond. Candidate A is worth pricing; B is not.

Set a threshold before you look at results. A reasonable starting point is that the candidate must beat the incumbent by at least 3 to 5 points of judged recall@k, and must not regress nDCG. Write it down so the decision is not negotiated after the numbers arrive.

Price the backfill before you commit

Now the arithmetic. Three quantities drive the cost: embedding volume, graph build time and evaluation time.

Embedding volume is rows times dimension, in floating point numbers, then converted to bytes. At 4 bytes per float32 value:

volume_bytes = rows * dimension * 4

A 10 million row corpus at 1,536 dimensions is 61.4 GB of raw float32 vectors. At 1,024 dimensions it is 41 GB. If you store a half-precision type instead, halve it; pgvector users facing large builds are advised to consider the halfvec type or binary quantization with re-ranking to reduce index size the pgvector issue thread.

Graph build time is the part teams underestimate. HNSW builds are slower and more memory-hungry than list-based indexes, and raising the build parameters slows the build drastically while primarily improving accuracy the Crunchy Data explainer. Parallel builds changed the picture substantially: a parallel HNSW index build improved build time by a factor of 30 in tests on a 10 million row, 1,536-dimension dataset on a 64 vCPU, 512 GB RAM instance Neon's write-up of the benchmark.

Memory availability decides whether you get near that figure. When the graph no longer fits into maintenance_work_mem, pgvector warns that the build will take significantly time and advises raising that setting; one reported build on 40 million row partitions was still under 30 percent complete after more than a day, and the fix included removing LOCAL from the SET commands so the setting applied outside the transaction, using the default ef_construction of 64 for faster builds, and lowering the vector type the pgvector issue thread.

A simple estimator you can run on a sample:

-- Build a 1 percent sample and time the index creation
CREATE TABLE sample_vectors AS
  SELECT * FROM documents USING sample (1);

\timing on
CREATE INDEX ON sample_vectors
  USING hnsw (embedding vector_cosine_ops)
  WITH (m = 16, ef_construction = 64);
\timing off

Multiply the sample build time by 100 for a first-order estimate, then add 30 to 50 percent for the superlinear behavior that shows up as the graph grows. Do not skip the sample: a naive estimate that ignores the memory-fit warning can be off by an order of magnitude.

Evaluation time is the cheap line item and the one people forget. Rerunning the golden set takes minutes, but re-embedding a few hundred queries and re-judging any results whose label status changes can take a day of human time. Budget it.

The backfill cost table:

Cost lineFormulaExample (10M rows, 1,536 to 1,024 dims)
Raw embedding volumerows * dim * 4 bytes41 GB
Embedding callsrows / batch size10M rows, batched by API limits
Sample build timetimed on 1 percent sample20 min
Estimated full buildsample * 100 * 1.4about 47 hours
Golden set re-runminutes, plus judging2 to 6 hours of human time
Shadow serving periodyour risk appetite1 to 2 weeks

Two operational costs often missing from pricing pages are reindexing and embeddings, which can double real production spend when they are not planned the Actian pricing analysis. Put both on your cost sheet before you approve the project.

If you are evaluating several candidates, sending every corpus through one interface saves a lot of plumbing. Quanta Inference exposes text, image, video, audio and embedding models through a single OpenAI-compatible API key with prepaid US dollar pricing, so the candidate comparison and the eventual backfill use the same client code.

Run the new index as a shadow before switching traffic

A clean backfill lands in a parallel collection or table, never in place. Serve the candidate index to a slice of read traffic or to internal users while the incumbent handles everyone else, then compare judged recall, nDCG and click or answer-accuracy metrics between the two. Gate the switch on the shadow matching or beating the offline numbers.

Practical rules for the shadow period:

  • Keep both indexes current. Dual-write new and updated rows to both collections for the duration, or the candidates diverge and the comparison becomes meaningless.
  • Automate the recall check. The same helper that compares approximate and exact results can be wired into CI and fail the job when recall falls below your target, which catches regressions from embedding model swaps before they reach production the Qdrant tutorial.
  • Record the baseline you accept. Tools exist that approve a recall number and then report when it drifts; a degraded index gives no other signal the pg_recall_guard documentation.
  • Watch memory and latency, not just quality. Compression levels and workload modes trade recall and latency for memory, and a candidate that needs 2 to 5 times the memory of a list-based index changes your hosting bill even when quality improves the BigData Boutique comparison, the OpenSearch memory optimization docs.

Decide the rollback in advance: keep the old collection for at least one full business cycle after the switch, and record the exact model, dimension, build parameters and evaluation run that produced the approved index so a future rebuild is a repeatable operation rather than archaeology.

The decision rule, in one place

Combine the two halves into a single gate. Run it in order, and stop at the first failure:

  1. Golden set exists and is judged. Few hundred queries, relevance labels, held-out split. No set, no evaluation.
  2. Candidate beats incumbent on judged recall@k and nDCG@k by your pre-registered margin, measured at the k you serve.
  3. Candidate does not regress index recall measured against exact search, and does not blow your latency budget.
  4. Backfill estimate is acceptable: embedding volume, sample-based build projection, evaluation time, shadow period, and the storage or memory delta.
  5. Shadow run confirms the offline gain on a slice of traffic.
  6. Rollback plan and recorded baseline exist before traffic moves.

If step 2 fails, keep the current index and revisit when a candidate clears the bar. Most candidates will not, and that is the system working. It is far cheaper to reject ten models on a few hundred judged queries than to rebuild a production index ten times.

If the work of maintaining the golden set, the CI recall gate and the shadow harness is more than your team can staff, that is a signal about scope rather than quality. Quanta Intelligence builds sites, apps and internal tools with a specialist who works alongside you, which covers the evaluation dashboard and shadow-comparison plumbing without pulling engineers off the product. For the narrower case of specialist retrieval work, an AI expert for your line of business can own the golden set and the reindex runbook.

FAQ

FAQ

How many judged queries do I need in the golden set?

Start with a few hundred for a model-swap decision, well above the 50 to 200 pair range commonly recommended for general retrieval gates DataAIHub. The larger set is because you are comparing two systems with small differences, and small samples produce noisy differences. Keep a held-out slice of roughly a third to confirm the winner after the rebuild.

Can I reuse the existing HNSW index if the new model outputs the same number of dimensions?

No. Matching dimension means the storage type fits, not that the geometry carries over. The graph's edges encode neighbor relationships from the old model's vectors, and a different model places the same text in a different location in space. You need a rebuild, though the identical dimension does simplify the schema migration.

What recall improvement justifies a full backfill?

Set the threshold before you look at results, and anchor it to product metrics. A margin of 3 to 5 points of judged recall@k with no nDCG regression is a defensible starting bar, but the real question is whether the gain would be visible in answer quality or click metrics. If you cannot imagine a user noticing the difference, the rebuild does not pay for itself.

How do I estimate build time without running the full build?

Time an index build on a 1 percent sample of the corpus with your target parameters, multiply by 100, then add 30 to 50 percent for superlinear growth. Watch for maintenance_work_mem warnings during the sample build, because if the graph does not fit in memory the build slows dramatically and your projection will be far too optimistic the pgvector issue thread.

What is the difference between index recall and retrieval recall?

Index recall measures how closely approximate search matches exact search on the same vectors, so it tests your index parameters. Retrieval recall measures how many of the judged relevant documents land in the top k, so it tests your embedding model and chunking together. A model swap decision should be driven by retrieval recall, with index recall as a health check on each candidate's index configuration.

Sources

Sources

  1. HNSW Indexes with Postgres and pgvector | Crunchy Data Blog
  2. Measuring ANN Recall
  3. How to Benchmark Embedding Models for Your Use Case ...
  4. Efficient Vector Index Merging in Vector Databases
  5. RAG Retrieval Evaluation: Metrics & Methods | DataAIHub
  6. Golden dataset evaluation: build and maintain LLM test sets
  7. HNSW vs IVFFlat: How to Choose the Right Vector Index - BigData Boutique
  8. pg_recall_guard 0.2.4: Watch vector indexes for recall drift ...
  9. ANN Search: Recall What Matters
  10. HNSW index creation is stuck on dozens millions entries #822 - GitHub
  11. pgvector: 30x Faster Index Build for your Vector Embeddings
  12. The Hidden Cost of Vector Database Pricing Models
  13. Memory-optimized vectors
About the author

About the author

Antonio Evans
Antonio Evans

Antonio Evans is the founder of Quanta Intelligence and a fractional CTO who builds HIPAA-ready AI systems for health and life-science companies. Before that he was technical co-founder of FriendsEAT for twenty years, CEO of Socialdraft, and a data engineer at IBM. Antonio lives with his dog Santino in Lisbon, Portugal.

All articles