GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Disable graph search pruning by tlwillke · Pull Request #686 · datastax/jvector

Conversation

@tlwillke

@tlwillke tlwillke commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator
  • Forward-port of the fix from Disable TopK/filtered pruning, preserve legacy threshold behavior #682 (originally resolving Search pruning via usePruning can be too aggressive for non-hierarchical graph indices #678).
  • Added comments for clarity

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tlwillke added 2 commits June 24, 2026 18:51
@tlwillke
Permanently disable pruning while retaining non-zero threshold search…
d6a9489
… behavior.
@tlwillke
Added comments based on reviewer feedback.
9692b14
@tlwillke tlwillke self-assigned this Jun 24, 2026
@tlwillke
tlwillke requested review from MarkWolters, ashkrisk and jshook as code owners June 24, 2026 19:04
@tlwillke tlwillke added the bug Something isn't working label Jun 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026 •
edited by ashkrisk
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Before you submit for review:

  • Does your PR follow guidelines from CONTRIBUTIONS.md?
  • Did you summarize what this PR does clearly and concisely?
  • Did you include performance data for changes which may be performance impacting?
  • Did you include useful docs for any user-facing changes or features?
  • Did you include useful javadocs for developer oriented changes, explaining new concepts or key changes?
  • Did you rebase your branch onto the latest main for regression testing and PR submission?
  • Did you trigger regression testing via Run Bench Main and review results?
  • Did you adhere to the code formatting guidelines (TBD)
  • Did you group your changes for easy review, providing meaningful descriptions for each commit?
  • Did you ensure that all files contain the correct copyright header?
  • Did you add documentation for this feature to the release notes directory?

If you did not complete any of these, then please explain below.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlwillke
Adding release notes.
a3a7590
jshook
jshook approved these changes Jun 24, 2026
View reviewed changes

@jshook jshook left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing found of concern

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tlwillke tlwillke mentioned this pull request Jun 24, 2026
Disable TopK/filtered pruning, preserve legacy threshold behavior #682
Closed
ashkrisk
ashkrisk approved these changes Jun 25, 2026
View reviewed changes

@ashkrisk ashkrisk left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves #678

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ashkrisk ashkrisk linked an issue Jun 25, 2026 that may be closed by this pull request
Search pruning via usePruning can be too aggressive for non-hierarchical graph indices #678
Closed
MarkWolters
MarkWolters approved these changes Jul 6, 2026
View reviewed changes

@MarkWolters MarkWolters left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The only quibble I would have is that we are now maintaining a "dead" option. If the plan is to re-use pruneSearch in the future to implement new functionality it could be marked as such with //TODO, but this is a minor concern.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tlwillke
tlwillke merged commit f094cc7 into main Jul 7, 2026
18 of 19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@tlwillke
tlwillke deleted the forward-port/disable-pruning branch July 7, 2026 19:31
@ergunkezer1 ergunkezer1 mentioned this pull request Aug 13, 2026
[FEATURE] Correctly wire up graph pruning and evaluate improvements opensearch-project/opensearch-jvector#670
Closed
@fh-ms fh-ms mentioned this pull request Sep 18, 2026
GigaMap/jvector: update jvector to 4.0.0-rc.9 eclipse-store/store#826
Merged
fh-ms added a commit to eclipse-store/store that referenced this pull request Sep 18, 2026
@fh-ms
GigaMap/jvector: update jvector to 4.0.0-rc.9 (#826)
1991761
* GigaMap/jvector: update jvector to 4.0.0-rc.9

jvector 4.0.0-rc.8 initialises GraphSearcher.pruneSearch to true, enabling a TopK and filtered-search pruning heuristic that upstream classified as recall-destructive and permanently disabled in 4.0.0-rc.8-hf1 (datastax/jvector#682), carried forward into rc.9 (datastax/jvector#686). Both of this module's search invocations run the affected paths: the TopK path searches with threshold 0, and the on-disk path with deletions searches under restrictive accept bits, which is the case upstream's defect report names explicitly.

rc.9 supersedes the hf1 hotfix rather than merely matching it, so the intermediate bump is skipped. In rc.9 the pruneSearch field is initialised to false, usePruning(boolean) ignores its argument and is deprecated, and the field is never read on the search path.

The bump is a one-line change with no source change and no on-disk migration. OnDiskGraphIndex.CURRENT_VERSION is 6 and MAGIC is -62111 in both versions, and the class diff is purely additive, so an index written by either version loads and searches correctly under the other and a rollback stays readable.

Adopting rc.9 was previously blocked by a deterministic failure of VectorIndexDiskTest#testShutdownDoesNotRebuildGraphInIncrementalMode. That was not an rc.9 regression. Under rc.8 the shutdown path was about to write a zero-vector graph over a valid one, and jvector's header writer threw a NullPointerException on the null entry node of an empty graph, which the shutdown path swallowed into an ERROR log; the bad write never reached the file and the test passed for the wrong reason. rc.9 supports empty graphs, so the write succeeded and the test correctly failed. The underlying defect is fixed by 958e060, so the test now passes on rc.9 for the right reason.

Verified on this change: 245 tests green on the default profile and 133 with -P slow-tests, no failures, and gigamap/codegen-test, demos/product-recommendations and examples/gigamap all still build.

A recall probe across both versions (4000 vectors, dim 256, degree 16, clustered data, 100 queries, recall@10 against brute force) measured no difference beyond noise, so this is prevention rather than the repair of a regression observable at these scales. Upstream observed the damage at larger scales and other score distributions, which is the regime GigaMap targets.

* GigaMap/jvector: align the architecture notes with the bumped jvector version

The module documentation pinned 4.0.0-rc.8 in two places, so the bump left it contradicting the version the build actually resolves.
@fh-ms fh-ms mentioned this pull request Sep 21, 2026
GigaMap/jvector: compression formats, in-memory PQ scoring, and jvector 4.0.0-rc.9 eclipse-store/store#834
Merged
fh-ms added a commit to eclipse-store/store that referenced this pull request Sep 21, 2026
@fh-ms
GigaMap/jvector: compression formats, in-memory PQ scoring, and jvect…
7d5f4cf
…or 4.0.0-rc.9 (#834)

* GigaMap/jvector: update jvector to 4.0.0-rc.9 (#826)

jvector 4.0.0-rc.8 initialises GraphSearcher.pruneSearch to true, enabling a TopK and filtered-search pruning heuristic that upstream classified as recall-destructive and permanently disabled in 4.0.0-rc.8-hf1 (datastax/jvector#682), carried forward into rc.9 (datastax/jvector#686). Both of this module's search invocations run the affected paths: the TopK path searches with threshold 0, and the on-disk path with deletions searches under restrictive accept bits, which is the case upstream's defect report names explicitly.

rc.9 supersedes the hf1 hotfix rather than merely matching it, so the intermediate bump is skipped. In rc.9 the pruneSearch field is initialised to false, usePruning(boolean) ignores its argument and is deprecated, and the field is never read on the search path.

The bump is a one-line change with no source change and no on-disk migration. OnDiskGraphIndex.CURRENT_VERSION is 6 and MAGIC is -62111 in both versions, and the class diff is purely additive, so an index written by either version loads and searches correctly under the other and a rollback stays readable.

Adopting rc.9 was previously blocked by a deterministic failure of VectorIndexDiskTest#testShutdownDoesNotRebuildGraphInIncrementalMode. That was not an rc.9 regression. Under rc.8 the shutdown path was about to write a zero-vector graph over a valid one, and jvector's header writer threw a NullPointerException on the null entry node of an empty graph, which the shutdown path swallowed into an ERROR log; the bad write never reached the file and the test passed for the wrong reason. rc.9 supports empty graphs, so the write succeeded and the test correctly failed. The underlying defect is fixed by 958e060d, so the test now passes on rc.9 for the right reason.

Verified on this change: 245 tests green on the default profile and 133 with -P slow-tests, no failures, and gigamap/codegen-test, demos/product-recommendations and examples/gigamap all still build.

A recall probe across both versions (4000 vectors, dim 256, degree 16, clustered data, 100 queries, recall@10 against brute force) measured no difference beyond noise, so this is prevention rather than the repair of a regression observable at these scales. Upstream observed the damage at larger scales and other score distributions, which is the regime GigaMap targets.

* GigaMap/jvector: align the architecture notes with the bumped jvector version

The module documentation pinned 4.0.0-rc.8 in two places, so the bump left it contradicting the version the build actually resolves.

* GigaMap/jvector: express the on-disk format as two configuration dimensions (#827)

* GigaMap/jvector: express the on-disk format as two configuration dimensions

The on-disk format is about to grow a second dimension. Today enablePqCompression is a single boolean, which can say whether Product Quantization codes are fused into the graph but nothing about how the vectors beside them are stored. A boolean cannot carry that, so the setting becomes two enums: vectorStorage for how each vector is stored, and approximateScoring for how traversal scores candidates. They are independent and every combination is legal.

enablePqCompression becomes a deprecated literal delegate for approximateScoring(b ? FUSED_PQ : NONE), writing the very same field. That is what makes mixing the two spellings a non-question rather than a precedence rule to document: the last call wins, whichever it was. The accessor reports FUSED_PQ specifically, not merely "some compression", because that is what it has always meant.

Each constant carries an explicit int code that is deliberately not its ordinal. These codes are written into the index metadata file in a later change, so an existing constant's code must never move and a new one is appended; using ordinals would silently remap every file already on disk the moment a constant were inserted anywhere but at the end. An unrecognised code resolves to null rather than throwing, which is what a file written by a newer version looks like, so it can be rejected and rebuilt rather than misread.

The part with teeth is schema evolution. A VectorIndexConfiguration round-trips through EclipseStore as part of the index, and EclipseStore fills a field added by schema evolution with the zero value - null, for a reference. A configuration persisted before these enums existed therefore loads with both of them null, carrying its setting only in the legacy boolean, which is why that field is retained rather than replaced. The accessors derive from it instead of reporting the enum defaults; without that, every existing PQ-enabled index would silently lose PQ on upgrade. A test forces exactly that shape by reflection, since the builder cannot produce it, and it fails without the guard.

No behaviour changes here. The engine still reads the deprecated accessor, so an index built with either spelling writes the same graph it did before. NVQ appears in the enum and its javadoc but is not yet implemented; the following change adds it.

This is the first of two parts, split out because the API surface and its persistence compatibility are worth reviewing on their own.

* GigaMap/jvector: make the compact preset actually the smallest, and correct two contracts

forCompactLargeDataset set FUSED_PQ alongside NVQ, which made it larger than the plain uncompressed configuration it claims to improve on: fused codes are duplicated maxDegree times per node, so at dimension 768 and maxDegree 32 they cost 6144 bytes against the 800 the quantized vector occupies - about 7080 bytes per node against 3208. It now sets NONE, which is 936. What it gives up is traversal speed rather than accuracy: without fused codes each hop reads its candidates' own stored vectors, which are 800 bytes rather than 3072, and reranking becomes exact because the search path compares against the vectors in the GigaMap rather than the graph's quantized copy. The test pins the result against the node layout instead of restating the setting.

nvqSubvectors() documented a return of 0 for auto while the accessor resolves 0 to 1, so callers never saw the value the contract promised. It now documents the effective value and points at pqSubspaces(), which deliberately returns its raw sentinel instead.

The deprecated enablePqCompression() still promised full-precision inline vectors and exact reranking whenever true. With storage now a separate dimension that holds only for INLINE; under NVQ the graph carries quantized vectors and reranking compares against those. Both claims are qualified by storage mode.

* GigaMap/jvector: correct why the legacy compression boolean is kept

The comment claimed the field is retained so a build predating the enums can still read a configuration written by this one. It cannot. Once this build has persisted a configuration, VectorStorage and ApproximateScoring are in the type dictionary, and the older build fails to open the storage at all with a missing runtime type for the required type handler - reproduced by restarting a storage across the two module versions.

The field is still right to keep, for the reason the accessors actually use it: a configuration written before the enums existed carries its setting in this boolean, and approximateScoring() derives the enum from it when the enum fields come back null. No downgrade path is promised, and the comment should not imply one.

* GigaMap/jvector: fix two prose-vs-code mismatches in the compression javadoc

The 'NVQ saves nothing' warning computed its size from the effective subvector count but logged the raw field, so a configuration left at the auto sentinel reported '0 subvectors' for a figure derived from one.

The memory discussion under enablePqCompression() described reranking reading inline vectors and the resident cost of full-precision storage. That held while the flag implied INLINE; now that NVQ and FUSED_PQ compose it is wrong for a combination the API permits. The paragraph is scoped to INLINE and the NVQ case stated separately.

* GigaMap/jvector: tie the NVQ accuracy note to the scoring mode

The NVQ trade-off was stated as a flat "reranking compares against dequantized rather than full-precision vectors", which is only true in one of the two scoring modes. The reranker reads from the graph's quantized copy when the graph also carries fused codes; with ApproximateScoring.NONE it still reranks exactly, and in incremental mode it is exact by rule so the disk and in-memory halves merge on one score scale. Say all three cases instead of the one.

The indexDirectory() file layout had the same shape of problem: it promised full-precision inline vectors in the .graph unconditionally, and named the deprecated boolean as what decides whether fused codes are present. It now refers to vectorStorage() and approximateScoring(), and records that the .meta carries both settings.

* GigaMap/jvector: keep VectorIndexConfiguration implementable across the release

The three new format accessors and their three builder mutators were abstract, so an application carrying its own implementation of either interface would stop compiling on upgrade. That is an avoidable break: the module already treats this as a concern, VectorIndex.isPqCompressionActive() being a default returning false for exactly this reason, and VectorIndexConfiguration itself already has backgroundPersistence() and backgroundOptimization() as defaults.

The accessors get defaults. vectorStorage() returns INLINE and nvqSubvectors() returns 1, since an implementation predating those methods describes an inline graph with the recommended subvector count. approximateScoring() derives from the deprecated flag rather than returning a constant, because such an implementation expresses the same setting through enablePqCompression(); returning NONE would misreport a PQ-enabled configuration as having no approximate scoring.

The builder mutators get defaults too, but they throw. A builder that cannot carry the setting must not accept the call and then hand back a configuration that says something else, so failing loudly is the only honest option - the default exists to preserve linkage, not to make the setting optional.

Two tests hold this in place. They are written against stub implementations that declare none of the six new methods, so the file stops compiling if any of them becomes abstract again, and they pin the derivation: a legacy configuration with PQ enabled reports FUSED_PQ.

* GigaMap/jvector: store quantized vectors in the on-disk graph (#828)

* GigaMap/jvector: store quantized vectors in the on-disk graph

PR #825 established that FusedPQ makes the .graph file larger, not smaller: it duplicates each node's PQ code maxDegree times on top of the full-precision inline vectors, buying traversal speed and page locality at the cost of space. Nothing on offer made the index smaller, which is the constraint that actually binds once an index outgrows memory.

JVector's NVQ feature does. It stores 8-bit non-uniformly quantized vectors inline in place of full precision, costing 4 + dimension + 28 * nvqSubvectors bytes per node against dimension * 4. At dimension 768 and maxDegree 32 that is 936 bytes per node against 3208, so roughly a million vectors occupy 0.89 GB rather than 3.0 GB.

What that costs in accuracy depends on the other dimension, because that is what decides where the reranking pass reads from. Paired with NONE the graph carries no fused codes, the rerank reads the vectors held in the GigaMap, and quantization affects only which candidates traversal visits rather than how the final top-k is ordered. Paired with FUSED_PQ the rerank reads the graph's own quantized copy and the ordering is computed from dequantized vectors; measured recall@10 was 0.921 there against an exact baseline of 0.923. Either way it is safe with respect to the data itself, because the .graph is a derived artifact rebuilt from the vectors held in the GigaMap whenever its metadata is rejected. Quantizing the graph's copy costs recall, never durability.

The .meta file moves to version 5, replacing the v4 PQ boolean with the two format codes the previous change introduced. A boolean could record whether fused codes were written but not whether the vectors beside them were full-precision or quantized. A code this build does not know resolves to null and is treated as a mismatch, so a file written by a newer version is rejected and rebuilt rather than misread, which is why a future storage or scoring mode will need no further version bump.

Both compression managers are now fed by one training sample. Collecting per manager would walk the whole GigaMap twice, and in embedded mode call the user's Vectorizer once per entity twice, on the first persist of any index with both dimensions configured. The two-phase choreography is unchanged: collect under the GigaMap monitor, train with no locks held. No new locks and no new lock order.

NVQ training differs from PQ in three ways that each remove machinery rather than adding it. It cannot decline on data shape, since a mean is defined for any non-empty sample, so its witness guards only against an outright exception. It is cheap enough to need no collect/train split of its own. And retraining is harmless, because every persist rewrites the whole graph together with the quantizer in its header, where a new PQ codebook would not match codes already fused into an existing graph.

The quantizer is computed from the collected sample via NVQuantization.create rather than NVQuantization.compute. compute walks every ordinal of a RandomAccessVectorValues, which would mean handing it the null-safe view used for the disk write: it probes ordinal 0 for the dimension, which is a placeholder whenever ordinal 0 is a deletion hole, and it walks the whole corpus instead of the capped sample.

The disk search path becomes a dispatch over both dimensions. An NVQ graph without fused codes traverses on its quantized vectors and reranks exactly from the GigaMap, which was previously unreachable: the old gate returned the exact provider whenever the graph lacked fused codes, so an NVQ graph would have scored every visited node through a GigaMap lookup. One rule is new and subtle: in incremental mode the disk-side reranker must be the exact one, because searchIncremental merges the disk and in-memory halves by raw score and the in-memory half is always exact, so an NVQ-dequantized disk half would sit on a different scale and bias every merge.

Existing behaviour is deliberately untouched where it would otherwise drift. The plain INLINE graph with no fused codes keeps its feature-less fast path and writes byte-identical files. forLargeDataset keeps producing exactly the graph it produced before; a new forCompactLargeDataset preset opts into the compact format instead. An on-disk INLINE graph with no fused codes also still scores from the GigaMap rather than from the vectors in its own mapping, which the new dispatch could change for free but which belongs in its own change with its own staleness argument.

Verified: 266 tests on the default profile and 142 with -P slow-tests, no failures. The size claim is asserted against the closed-form node layout rather than a recorded number, and recall is measured across five seeds against brute-force ground truth at the same floor as the PQ path.

The configuration surface this builds on landed in #827.

* GigaMap/jvector: state what NVQ actually costs, and prove it

The documentation said NVQ makes reranking approximate whenever the graph also carries fused codes. Measuring it says otherwise, and the measurement is the interesting part: a test asserting that an NVQ index returns exact scores passed in both scoring modes, which it should not have if the fused branch reranked from the graph's quantized copy.

The branch that does so is real but unreached. It sits behind incremental == false, and an on-disk index does not currently enter that state: tryLoad enters incremental mode on load, and every persist ends in reenterIncrementalMode. Instrumenting the non-incremental disk search and running the whole slow suite confirms it - 142 tests, not one of them reaches it. So in every path a live index takes, the disk-side rerank is the exact GigaMap one, and NVQ costs traversal quality rather than the scores: a candidate traversal never reaches cannot be recovered by reranking, but a candidate it does reach is ordered exactly.

The branch is kept rather than removed, because it is the correct behaviour if that state ever becomes reachable, and its javadoc now says that it is unreached rather than implying it runs.

The dispatch is restructured so each path computes only the reranker it uses. It previously built the graph reranker up front and then discarded it on the NVQ-without-fused-codes path, which called view.rerankerFor a second time - a wasted allocation per query on the very configuration the feature exists for, and the structure that made the code read as though NVQ reranked from the graph.

The test measures score deviation rather than recall, because recall cannot distinguish the two rerankers at a scale the suite can afford, and it searches a reopened index so the query runs against the graph on disk rather than one the writing builder still holds. Both matter: an earlier draft did neither and would have passed against either implementation.

* GigaMap/jvector: make a changed quantization count take effect

The metadata recorded which storage and scoring modes a graph was written with, but not the two counts that shape the blocks within those modes. Changing either over an existing index directory was therefore accepted as a clean load, and the consequence is worse than a stale file: the quantizer is adopted from the loaded graph rather than retrained, so the old one stayed in place and every later persist kept writing the old shape. The new setting was not merely deferred, it was silently ignored.

Both counts are now recorded and verified, on the same reasoning the mode codes already carried: nothing else in the file reveals them, and removeIndex() leaves files behind, so a setting changed over an existing directory has to invalidate the graph.

They are recorded in effective form rather than as configured. The automatic sentinel and the value it resolves to are the same setting, and a count means nothing in a mode that does not encode with it, so both are normalized before being written - a count the format does not use is stored as zero. Without that, spelling out dimension / 4 instead of leaving pqSubspaces automatic would have forced a rebuild that changes nothing in the file.

No version bump. Version 5 has not shipped; it exists only on this integration branch, so the layout is still free to grow.

The test asserts both directions, because only the negative half is obvious: two configurations that describe the same graph must still load, or the fix trades a silent miss for a pointless cold start. It fails without the validation, on the NVQ subvector case.

* GigaMap/jvector: finish correcting the NVQ accuracy claim

The previous commit rewrote the prose explaining what NVQ costs but left three statements of the old claim standing: the summary bullet on the constant itself, the README's limitations list, and the compact preset's javadoc, which gave the absence of fused codes as the reason reranking stays exact when the real reason is that no reachable path reranks from the graph at all.

The dispatch javadoc now says the same thing where it is easiest to check, next to the branch it describes: incremental is never false for an on-disk index, so the graph-backed reranker below it is unreached, and it is kept for correctness rather than because it runs.

Also fixes a sentence that parsed only on a second reading.

* GigaMap/jvector: cover and document the NVQ storage mode (#829)

* GigaMap/jvector: cover and document the NVQ storage mode

Completes the NVQ work with the tests and documentation it was missing, and corrects two claims made for it that do not survive measurement.

The incremental merge rule now has a test. A query in incremental mode searches the disk graph and the in-memory builder separately and merges the two by raw score, so the disk half must be reranked exactly or the two sides sit on different scales. Asserting this through recall proved useless: the quantization error rarely reorders a top-k, so the test passed whether or not the rule was in place. It asserts the invariant directly instead, comparing each returned score against the similarity JVector itself would compute. With the rule removed the deviation measures 7.9e-4 against a 1e-4 threshold, which is float-arithmetic noise on one side and quantization on the other. Note the configuration this needs: with NVQ storage and no fused codes the reranker is exact by construction, so only NVQ together with FUSED_PQ exercises the choice at all. That combination is also the only place the choice is made, since the non-incremental disk search the other branch belongs to is unreachable - so this rule is the whole reason an NVQ graph returns exact scores.

The mean-pollution argument for training from the dense sample rather than the ordinal-spaced view was overstated, and the comment and test claiming it have been corrected. Deliberately halving the global mean left search results unchanged, because NVQ recentres and then scales each subvector by its own min and max, and that range absorbs a shifted mean almost entirely. The reasons to avoid NVQuantization.compute are the other two: it probes ordinal 0 for the dimension, which is a placeholder whenever ordinal 0 is a deletion hole, and it walks the whole corpus rather than the capped sample. Mean pollution is defence in depth rather than the motivation.

The encode cost is now measured rather than estimated, and it changes a recommendation. At 20,000 vectors of dimension 768 with maxDegree 32, persisting takes 3.6 s with full-precision vectors and 11.1 s with quantized ones, about 3x. Under the parallel writer the same pair is 4.0 s and 4.8 s, about 1.2x, because the per-node encode runs on the writer's worker threads instead of in one pass. Pairing NVQ with parallelOnDiskWrite is therefore the documented advice rather than an aside. The same run confirms the size claim end to end: 64.2 MB against 18.8 MB, a ratio of 3.41 against the 3.43 the node layout predicts.

New tests cover the production-dimension size ratio, NVQ under the parallel writer with concurrent searches, sparse ordinals with null embeddings, and rejection of both an unknown format code and a previous format version. The unknown-code case is what allows a future storage or scoring mode to be added without another version bump, so it is pinned directly.

The documentation gains an NVQ section carrying these measurements, a storage column in the use-case matrix, and a compact large-dataset recipe. Four statements that were already stale before this work are corrected: the metadata does record configuration, it is no longer five fields, the format version is no longer 4, and a configuration change does now trigger a rebuild. Examples move off the deprecated setter.

Verified: 267 tests on the default profile and 147 with -P slow-tests, no failures.

* GigaMap/jvector: make two NVQ tests exercise what they claim

Both tests passed, and both would have passed against an implementation without the behaviour they were written for.

The parallel-write test submitted every search only after persistToDisk() returned, so it measured concurrent reads of a finished graph rather than searches overlapping the write. The point of the test is that NVQ encodes per node from a supplier the writer calls on its own worker threads, which makes NVQuantization.encode - and the encodeTo it delegates to - concurrently invoked, with nothing upstream exercising it that way. The searchers now loop until the persist returns, a latch holds the writer until all of them are running, and the number of searches that completed during the write is asserted, so the test fails rather than quietly degrading if the overlap ever stops happening.

The sparse-ordinal test never left ordinal 0 empty: it added a vector before every null, so the first entity always carried an embedding. Ordinal 0 is the one ordinal NVQuantization.compute probes for the dimension, which is the edge case the test exists for, so the implementation it guards against would have passed it. A null entity now goes in first, and the fixture asserts that ordinal 0 both exists and carries no vector rather than assuming it.

Also corrects the javadoc that named encodeTo as the method the supplier calls. It calls encode, which creates an empty QuantizedVector and delegates - verified in the rc.9 bytecode.

* GigaMap/jvector: align the NVQ docs with the two-dimension format

Three inconsistencies, all pointing the same way.

The metadata description was written before the two quantization counts were added to it, so it listed five content witnesses and the two mode settings but neither count. It now lists both, and the loading section says why a changed count rebuilds where a reader might expect it merely to be deferred: the quantizer is adopted from the loaded graph rather than retrained, so without the check the new setting would be silently ignored rather than applied late. The effective-form comparison is stated there too, since that is what keeps an automatic sentinel from rebuilding against the value it stands for.

The per-node inventory and the large-scale recipe still described NVQ as making reranking approximate. It does not on any path a live index takes; that was established by measurement in the preceding change. Both now say that the storage block affects how traversal scores candidates rather than how the final top-k is ordered.

The summary matrix recommended NVQ for the RAG and image-search recipes, neither of which sets it - both leave vectorStorage at INLINE. A summary that disagrees with the configuration above it is worse than no summary, so the cells now match the recipes. Recommending NVQ there would be a change to what those recipes advise, which wants its own reasoning rather than arriving through a table.

* GigaMap/jvector: test the NVQ encode concurrency where it can actually be observed

The parallel-write test still could not see what it claimed, even after the previous attempt to fix it. doPersistToDisk holds builderLock.writeLock() across the whole of phase 2 including writeIndex, and search needs the read lock, so no query can run while NVQ.encode does - the code says as much where it releases the parentMap monitor but keeps the write lock. The searches counted as concurrent were running in the windows before and after it.

Comparing a parallel-written graph against a sequential one byte for byte does not work either, which took a control to establish rather than an argument: two sequential writes of the same vectors with the same seed already differ. Graph construction is not deterministic, so that comparison cannot separate an unsafe encoder from an ordinary run-to-run difference. An earlier probe at 500 vectors came out identical and was simply luck.

What is left is to assert the property against the quantizer directly. Eight threads encode the same 200 vectors repeatedly against one shared NVQuantization and compare every result with the single-threaded one, which is the access pattern the parallel writer produces, concentrated. It pins the property rather than reproducing a known failure - but it is the only one of the three formulations that runs the code concurrently at all.

The integration-level claim keeps its own test, narrowed to what it can carry: the parallel writer completes, and its output loads and answers queries.

Two size claims were also asserted nowhere. The production-dimension test documented the eight-subvector case at about 2.8x but measured only the default single-subvector setting, so the measure helper takes an explicit count and the lower end is measured too. And the suite ran five-seed recall for three of the four storage/scoring combinations while the documentation claimed all four; the missing uncompressed baseline is the one that decides whether the other three are near it or merely near each other, so it is now run rather than assumed.

* GigaMap/jvector: quote the footprint the large-scale recipe actually gets

The recipe enables NVQ alongside FUSED_PQ and annotated the result as a 3.4x smaller graph. That figure is the whole-node ratio without fused codes. Fused codes are unaffected by the storage mode and, at this recipe's dimension 768, maxDegree 32 and 48 subspaces, they are 1,536 bytes of the node on their own. The node goes from 4,744 bytes to 2,472, which is 1.9x - the vector block does shrink 3.8x, but it is no longer most of the node.

Both numbers are now given, along with what dropping FUSED_PQ as well would cost, since 936 bytes against 3,208 is where the 3.4x in the rest of the documentation comes from and a reader comparing the two pages should not have to work out why they disagree.

* GigaMap/jvector: repair three tests that stopped proving their point

The unknown-format-code test had been silently disarmed by the two counts added to the metadata in the preceding change. Its helper addressed the storage and scoring codes as the last two ints in the file, which they no longer are, so both mutations landed on pqSubspaces and nvqSubvectors instead. The load was then rejected on a count mismatch before fromCode ever saw the unknown value, and the test went on passing while covering nothing. The helper now anchors its offsets at the start of the record and asserts the total length, so the next field added breaks it loudly rather than retargeting it. Confirmed the repaired test fails when fromCode is made to map unknown codes onto a known constant, which it did not before.

The concurrent-encode test submitted its workers without a start barrier, so the pool was free to run one to completion before starting the next and a stateful encoder could have slipped through. The threads now meet at a latch before any of them encodes.

The incremental merge test asserted only that some disk-resident entity came back. If a query set ever returned nothing from the in-memory half, the two score scales would never meet and the test would quietly narrow to a check on the disk reranker. It now requires results from both halves.

* GigaMap/jvector: name the right source for each reranking path

Reranking is exact under every format, but it does not always read the same vectors, and saying it reads the GigaMap either way describes the implementation wrongly. With INLINE storage and fused codes the reranker reads the full-precision vectors from the memory-mapped graph, which is the point of keeping them there - it costs no parentMap lookup, and in embedded mode no vectorize() call, per reranked candidate. Only when the graph holds quantized vectors, and so has no full-precision copy, does the rerank fall back to the GigaMap.

Both the per-node inventory and the two-phase search description now say which source applies to which storage mode. The second mattered more than it looks: the NVQ section states that every combination of the two dimensions is valid, which brings NVQ + FUSED_PQ under a paragraph that claimed reranking always uses the graph's inline vectors.

Also fixes a sentence that lost a verb.

* GigaMap/jvector: give the compact preset the write mode it needs

forCompactLargeDataset chose the quantized format and then inherited parallelOnDiskWrite=false from builderForLargeDataset, so it handed out the NVQ encode cost without the mitigation documented two paragraphs away: about 3x the persist wall time sequentially against about 1.2x under the parallel writer, because the per-node encode then runs on the writer's worker threads. A preset exists to make a coherent choice, and that one was not.

Also corrects the deprecated flag's javadoc, which still said an NVQ graph reranks against its quantized vectors. It reranks against the full-precision vectors in the GigaMap - exact, but one lookup per reranked candidate, where an inline graph reads them from its own mapping for free. That difference is the reason worth documenting, and it is the opposite of what was written.

* GigaMap/jvector: correct what VectorIndices.add says about reusing an index directory

The contract told callers that the metadata records none of the tuning settings and that they must delete the .graph and .meta files by hand between removeIndex and add. Neither has been true since the format settings went into the metadata: a changed storage mode, scoring mode or quantization count is detected on load, and the graph is rebuilt from the parent map rather than served under the new configuration.

Left as it was, the advice costs a rebuild nobody needed - and, worse, teaches that the check does not exist.

The distinction the contract should draw is a different one, so it now draws that instead: settings that change what a reader must know to interpret the file are recorded and verified, while those that only shape how the graph was built - maxDegree, beamWidth, alpha, neighborOverflow, the similarity function - are not. A graph built under a previous value of one of those still loads, because nothing in the file contradicts the new configuration. Deleting the two files is the way to force those to take effect, which is the case the old advice was reaching for.

* GigaMap/jvector: stop the sparse-ordinal test depending on an unstable ranking

It compared the ordered top five from two independently built graphs and required them to be identical. Graph construction is not deterministic - established while reworking the parallel-write test, where two sequential writes of the same vectors already differed - and NVQ traversal is approximate on top of that, so a legitimate variation could have failed this for a reason unrelated to null embeddings.

What the holes must not do is change which vectors are candidates, so that is what is asserted: the exact match ranks first in both, no null-embedding entity appears, and the two result sets agree on all but at most one entry. Ordering within the set is left alone, because it was never the claim.

* GigaMap/jvector: give the search phases a table instead of a sentence

The prose kept getting one of the four format combinations wrong, in both directions: first that reranking always reads the graph's inline vectors, then that it always reads the GigaMap. Neither holds, and a sentence that has to carry four cases with two exceptions was the wrong shape for it.

The four combinations are now a table with the traversal source and the reranking source for each. Two entries are worth knowing and neither was stated before: FUSED_PQ traversal reads its codes whatever the storage block holds, so switching storage does not change how candidates are found in that mode; and the default INLINE + NONE reranks from the GigaMap even though full-precision vectors are sitting in its own mapping, because scoring them from the mapping would change the behaviour of the default on-disk configuration and that is deliberately left alone.

The per-node inventory drops its reranking claim entirely and says only when the storage block is read during traversal, which is the thing a reader is looking at that list to find out.

* GigaMap/jvector: tighten three test claims to what the tests establish

The merge test counted disk-half and memory-half results across the whole query set, which does not establish that any single merge compared the two score scales: one query could contribute every disk hit and another every memory hit. It now requires at least one result set holding both.

The compact preset's new parallelOnDiskWrite default was asserted nowhere, so a later refactor could drop the mitigation for NVQ's encode cost while every factory test still passed. Pinned, with the measurement as the reason.

The sparse-ordinal fixture claimed more than it can show. Putting a hole at ordinal 0 does cover the ordinal that gets special treatment in the training path, but a test that asserts on search results cannot distinguish training from the collected sample from training over the ordinal space: NullSafeVectorValues hands out a placeholder of the right dimension, so NVQuantization.compute would not fail on it, and the placeholders only shift the mean - which the mean-pollution experiment already showed the per-subvector scaling absorbs. The comment now states the end-to-end claim it does establish.

* GigaMap/jvector: finish the reranking and metadata corrections in the public javadoc

Three places still contradicted what the search path does, all of them reachable from a user's IDE rather than from the documentation site.

enablePqCompression carried a second NVQ paragraph, further down than the one corrected earlier, still saying reranking compares against quantized vectors. It reads the full-precision vectors in the GigaMap - the accuracy is unchanged and the cost is a lookup per reranked candidate, which is the part worth knowing.

indexDirectory inventoried the .meta without the two quantization counts, so the javadoc listed fewer rebuild triggers than the file has.

VectorIndices.add overstated the correction it received in the previous commit twice. A change to a recorded setting is a mismatch, but the counts are compared in effective form, so changing pqSubspaces while scoring is NONE - or nvqSubvectors while storage is INLINE - changes nothing in the file and triggers nothing. And the older sentence promising that removeIndex followed by add re-indexes every entity is no longer true for an on-disk index whose files survive validation, which is precisely what the new paragraph describes.

The per-node inventory in advanced.adoc stops restating the search rules for a third time and points at the table that already holds all four cases.

* GigaMap/jvector: measure the sparse-ordinal case against ground truth

The previous attempt traded an exact-ordering comparison between two independently built graphs for an overlap bound between them, which is the same dependency with a looser constant. Nothing bounds how far two valid approximate graphs may diverge from one another, so the threshold was arbitrary and a legitimate variation could still fail it for a reason unrelated to null embeddings.

Brute force does not move. Both indices are now measured against the true nearest neighbours instead of against each other, which is what the test meant all along: interleaving holes into the ordinal space must not cost the sparse index recall the dense one has.

* GigaMap/jvector: qualify what NVQ costs by the scoring mode

Correcting the claim that NVQ makes reranking approximate left a different over-generalisation in its place: that it costs traversal quality. That holds only when traversal reads the stored block, which is the NONE case. Under FUSED_PQ the fused codes drive traversal and the quantized vectors are not consulted, so candidate selection is exactly what it would be with INLINE storage - the cost there is the footprint saving and a GigaMap lookup per reranked candidate, nothing to do with recall.

It read worst where it was attached to a recipe that enables FUSED_PQ, telling a reader to raise the search beam against an effect that configuration does not have.

Stated per mode now in VectorStorage, which is where the explanation belongs, and the seven other places that carried some form of it either say the same thing or point at the table rather than restating it - the README twice, index.adoc, configuration.adoc, use-cases.adoc, the vectorStorage accessor and a test javadoc. Two of those were not flagged in review; they carried the same sentence and would have surfaced one round at a time.

Also fixes two descriptions that predate the storage dimension: the .graph inventory still listed inline vectors and fused codes as the only contents, and the two-phase walkthrough described the FUSED_PQ path as though it were the only one, directly below a section stating that all four combinations are valid.

* GigaMap/jvector: make the summaries agree with the search path, and flag the similarity-function hazard

The last of the contradictions between the short descriptions and the detailed ones, in both directions: the overviews in advanced.adoc and index.adoc, the README feature list and the VectorStorage decision table all still said NVQ trades recall unconditionally, while vectorStorage() and the enum-level table said storage decides how exact reranking is. Neither survives the search path. Reranking is exact under all four combinations, and candidate recall moves only in the modes that traverse on the stored block.

The VectorIndices contract also listed the similarity function beside maxDegree and beamWidth as a setting that is not recorded and whose graph can simply be reused. The first half is true and the second is not safe. Edges are built by searching with that function, so a graph built under one metric and reopened under another keeps neighbour lists chosen for the old one: queries still return, and their scores are computed with the new metric and are correct in themselves, but traversal follows edges optimised for the wrong distance and recall degrades with nothing reporting it. The contract now says to delete the files when changing it. Recording it in the metadata is the real fix and is filed separately - it needs a format field and its own review, not an edit at the end of a documentation change.

Also: the README still claimed format version 4 and said null vectors are never accepted, which the Vectorizer.allowsNullVectors() opt-in has made untrue and which this branch adds tests for; and three runnable examples still used the deprecated enablePqCompression(true), two of them in javadoc where an IDE offers them for copying.

* GigaMap/jvector: correct what removeIndex followed by add does to the on-disk files

The contract said the new index loads the files the old one left behind if they still describe the data and the configuration, and told callers to delete them by hand when changing the similarity function. Review checked it against a running index: that reuse never happens. The index that add() creates is a new instance, so its structural modification counter starts at zero, while any .meta that was ever written carries at least one. The load is refused on that witness before the recorded settings are reached, and the graph is rebuilt every time.

So the manual-deletion advice was work nobody needed, and the paragraph describing which settings are recorded was attached to the wrong path. Those settings do matter, just on the other one: an index that comes back through storage keeps its counter, its content witnesses agree, and the configuration is then what decides.

The similarity-function hazard is rewritten rather than removed. Nothing in the file would contradict a changed metric, so a graph built under a previous one would be served under it if the two were ever brought together - it is the counter witness that keeps that from arising, since presenting a graph under a different configuration means building a new index and a new index adopts nothing. Recording the function in the metadata is still worth doing, so that the protection is by design rather than by consequence, and that is filed separately.

* GigaMap/jvector: give the format witnesses the reason they actually have

The justification carried everywhere was that removeIndex() leaves the files behind, so without the format codes a graph built under the previous setting would be reused. The measurement behind the preceding commit disproves it: that path is refused on the structural modification counter, since a new index starts at zero and any written .meta carries at least one, so the codes are never consulted there.

They are not redundant, they were explained by the wrong case. The one that reaches them is a downgrade. A new storage or scoring mode ships without a format version bump - that is the stated point of the stable codes - so an index persisted by a newer build and opened by an older one presents a matching version and matching content witnesses, being the same index in the same store. An unrecognised code is then the only thing separating that file from one this build wrote, and fromCode returning null is what turns it into a rebuild rather than a misread.

Corrected in advanced.adoc, which review flagged, and in the four other places carrying the same sentence: the metadata section of ARCHITECTURE.md, both halves of DiskIndexManager, and the dispatch javadoc in VectorIndex.

Comments and documentation only.

* GigaMap/jvector: score from an in-memory PQ blob instead of fused codes (#830)

* GigaMap/jvector: score from an in-memory PQ blob instead of fused codes

FUSED_PQ buys fast approximate traversal by writing each node's code into every neighbour that references it, so the cost is pqSubspaces * maxDegree bytes per node on disk - 6144 at dimension 768, maxDegree 32 and the automatic subspace count, which is what makes a compressed graph nearly three times the size of an uncompressed one. The codes themselves are far smaller than that; the duplication is the price of having them inline.

PQ_IN_MEMORY buys the same traversal by keeping one flat array instead. The codes go into a .pqv sidecar beside the graph and are read into heap on load, costing pqSubspaces bytes per ordinal once. The graph is left byte-for-byte what ApproximateScoring.NONE produces, which a test asserts directly. Combined with NVQ storage this is the smallest on-disk configuration available: measured at dimension 256, it is under half the uncompressed baseline and under a quarter of today's compressed one.

The heap cost is linear and has no ceiling, so it is stated rather than implied. It is pqSubspaces bytes for every ordinal up to the highest in use - deletion holes included, because the codes are indexed by entity id - resident for as long as the index is open. Roughly 192 MB per million vectors at dimension 768, and roughly 19 GB at a hundred million. The configuration logs the per-ordinal rate when the mode is selected, the documentation carries the worked figures, and a test pins the accounting against the ordinal space rather than the vector count.

No metadata version bump was needed. PQ_IN_MEMORY is simply a new scoring code, and a build that does not know it rejects the file rather than misreading it, which is the property the explicit non-ordinal codes exist for. The Stage 1 test that pinned code 3 as unknown now pins it as PQ_IN_MEMORY and moves the unknown-code assertion to 4 - the mechanism working as designed.

The commit order is sidecar, then graph, then meta last, so the metadata only becomes visible once everything it describes is in place. A missing sidecar is a rejection rather than a degrade: the metadata asserts that this index traverses on PQ codes, so serving it exactly instead would leave the configuration describing something the index is not doing. Rejecting rebuilds from the store, which restores both files. The codebook lives in the sidecar too, since this mode writes no fused feature and the graph header therefore carries none.

One test earns its place by construction. Every other test here passes whether or not the search path consults the codes, because the codes only choose which candidates traversal visits and reranking is exact either way - with enough beam width the same top-k comes back regardless. So testPqInMemoryCodesActuallyDriveTraversal swaps in a sidecar encoded from unrelated vectors, which the metadata does not describe and therefore does not reject, and asserts that retrieval degrades. With the scoring branch disabled the honest and aliased runs both measure 0.97 and the test fails; with it in place the aliased run drops far enough to prove the codes are what traversal follows.

Two notes for anyone extending this. PQVectors.writeSidecarHeader is not the writer for a sidecar despite the name - it emits the codebook and counts only, for a caller that streams the chunks itself - so the symmetric write/load pair is used instead. And an index registered against an empty GigaMap never loads its disk files at all, because the metadata witnesses reject on the count; tests that mean to exercise the disk path have to round-trip through EmbeddedStorage.

Verified: 267 tests on the default profile and 156 with -P slow-tests, no failures.

* GigaMap/jvector: stop a too-small PQ_IN_MEMORY index rebuilding on every restart

PQ training needs 256 embeddings. Below that the persist writes no codebook and therefore no sidecar, but the metadata still records the configured scoring mode - as it must, since recording what the write achieved would have the loader reject its own output and rebuild forever. The load then found no sidecar, treated it as loss, and rejected. The forever-rebuild arrived by the other route: an index under the threshold paid a cold start on every restart for as long as it stayed small, silently.

The count witness separates the two cases, and it is already read and verified a few lines above. Below the threshold there are no codes to be missing, so the graph loads and traversal scores exactly - the same fallback a FusedPQ graph whose training declined already gets. At or above it, a missing sidecar is still loss and still rebuilds.

Failing the persist instead would turn an ordinary small index into an error, which is worse than the behaviour it replaces.

The test asserts through tryLoad rather than end to end. Written the obvious way first, it passed with the fix disabled: a rejected load rebuilds from the store and the index answers queries either way, so nothing observable at that level distinguishes them. Only the manager's own return value does.

Also corrects a test javadoc claiming the graph is byte-for-byte what NONE produces. It asserts size and feature set, which is what the claim is actually about, and byte equality would be the wrong assertion anyway since graph construction is not deterministic.

* GigaMap/jvector: check a loaded sidecar describes the graph beside it

The metadata witnesses cover what a torn write can produce, since the metadata commits last and pqSubspaces is itself a witness. They do not cover a sidecar that arrived from somewhere else - copied in, restored from another backup generation, truncated outside this code - and reaching the score function with one of those is worse than rebuilding: a code array shorter than the graph's ordinal space fails on a lookup during a search rather than at load, when there is still something sensible to do about it.

The two checkable mismatches are now rejected at load: a code length other than the configured subspace count, and fewer ordinals than the highest entity id in use. Content is not checkable and the javadoc says so - a correctly shaped sidecar full of the wrong codes passes, which is exactly what testPqInMemoryCodesActuallyDriveTraversal relies on to prove the codes are consulted at all. Detecting that would need a checksum the format does not carry.

Writing the check found a second defect. effectivePqSubspaces gated on usesFusedPq, so a PQ_IN_MEMORY index recorded a subspace count of zero in its metadata: the witness added to make a changed pqSubspaces take effect was inert for the mode this change introduces, and the first assertion of the new test - that an index loads its own sidecar - failed against a count that was never written. It now gates on usesPq, which covers both modes.

* GigaMap/jvector: decide the sidecar question from what was indexed, not what was counted

The discriminator that separates a legitimately absent sidecar from a lost one used expectedVectorCount, which counts entities rather than embeddings. In embedded mode an entity without an embedding is counted but not indexed, so a map of 300 entities holding 100 vectors reads as over the training threshold while PQ training saw 100 and declined. The load then read the absent sidecar as loss and rejected, the rebuild declined again, and the next restart repeated it - the rebuild-every-restart loop the previous commit removed, restored for exactly the corpus shape that made training decline in the first place.

The graph is already open at that point and its node count is what was actually written, nulls excluded. That is now what decides.

The regression test needs an embedded vectorizer to reach the corner at all: with a computed one the count follows the stored vectors and the two agree, which is why the first version of this test failed on its own precondition rather than on the behaviour.

* GigaMap/jvector: say per ordinal where the cost is per ordinal, and cover the second rejection

The heap cost was described as bytes per vector in the places a reader meets first - the constant's cost line and summary, and the opening of the advanced section - while the paragraph that puts numbers on it correctly says per ordinal. The codes are indexed by entity id, so a deletion hole costs its bytes like any other ordinal, and per vector understates exactly the term the documentation is warning about.

The sidecar rejection test claimed to cover both checkable mismatches and exercised one. It copied a smaller sidecar in, which is the too-few-ordinals case; the wrong-code-length branch had no test at all. It does now, from an index built with half the subspace count, and I checked both cases fail with their own branch disabled.

* GigaMap/jvector: stop a sidecar outliving the graph it was written for

Review reproduced the hole: an index persists with a codebook, a later persist declines training and writes none, and the old .pqv stays on disk beside the new graph. Every check it had passed - present, right code length, enough ordinals - so the next start loaded it and reported PQ active while traversing on codes describing vectors the graph no longer held. Silent, and worst precisely when the vectors changed in between, which is the situation that put the index there.

Both halves of the fix are needed and each is verified to fail on its own.

A persist that writes no sidecar now deletes any existing one, in the same step and before the graph becomes visible, so the pair on disk stays consistent at every point a crash can stop at.

And the sidecar carries the structuralModCount of the persist that wrote it, in a trailer after JVector's payload so its format is untouched. A file that survives by a route the delete does not cover - a crash between the sidecar and graph renames, a file restored by hand - is then recognisable rather than merely plausible, and that closes the rename window as a side effect.

The witness alone would have been worse than nothing: it would reject the stale file, the rebuild would decline training again, leave the same file in place again, and the index would rebuild on every restart - the loop the previous two commits removed twice already.

* GigaMap/jvector: allow PQ-compressed scoring for in-memory indices (#831)

* GigaMap/jvector: allow PQ-compressed scoring for in-memory indices

An in-memory index performs about 2,000 vector lookups per insertion while building the graph, and well over a thousand distinct lookups per query while searching it. The per-query cache dedupes repeat visits to the same node but not the distinct ones, and both counts grow with the data set. Scoring from in-heap PQ codes removes them: measured, an insertion after the switch costs under 20 vectorizer calls against 1818 before it.

An index cannot start compressed. GraphIndexBuilder takes its BuildScoreProvider at construction and a codebook needs 256 vectors, so the switch is a rebuild - train, encode every ordinal, build a fresh builder against the codes, replay the nodes, swap. That is O(n), so it happens at optimization, which already pays an O(n) cost, and nowhere else. build() therefore requires optimizationIntervalMs > 0 for this mode; triggering it from a mutation would put a full retrain and rebuild inside whichever add crossed the threshold.

The switch runs in three phases, each holding exactly one lock and never two.

Phase one reads the GigaMap under the parentMap monitor: whether training is pending, the training sample, the vectors to replay, the ordinal-space warning, the change counter. Phase two holds no lock at all and is where the cost is - k-means and the replay both work only from what phase one captured, so neither needs one. Phase three takes builderLock.writeLock() and swaps pointers.

The split is not an optimisation, it is what ARCHITECTURE.md section 11 requires: acquire parentMap before builderLock, never the reverse, because a thread holding the write lock and then waiting for the monitor deadlocks against internalRemoveAll, which holds the monitor and waits for that lock. Nothing reachable from phase three may touch the monitor, which rules out collectStoredVectors (it iterates the GigaMap) and anything reading getVectorCount or getHighestEntityId. Both were called from there during development and both reopened the cycle.

Releasing the monitor before the replacement is built means the index can move on while it is being built, and a replacement from the older picture would undo whatever moved. Rather than reconcile, phase three checks structuralModCount again and discards a replacement that no longer describes the index. The switch is deferred to the next optimization, never applied to a stale picture: the data wins, the switch waits.

The heap cost is the sidecar mode's, with the same shape: pqSubspaces bytes for every ordinal up to the highest in use, deletion holes included, because the codes are indexed by entity id and removals never compact the array. A map whose id space has churned past its live count pays for the gap, so the switch warns when the ordinal space exceeds the live count fourfold - counting graph nodes rather than entities, since in embedded mode the entity count includes those with no embedding and would keep the warning quiet on exactly the shape it is about.

Construction under compressed scoring does no reranking, so graph quality can drop. Measured recall@10 stays above 0.90 on clustered data at the default beam width; the documentation says to raise beamWidth for this mode if a given data set comes in lower.

Verified: 268 tests on the default profile and 168 with -P slow-tests, no failures.

* GigaMap/jvector: cover the in-memory PQ switch where it can actually be observed

Most of what this mode does is invisible from the outside. A correct graph comes back whether the builder scored from codes or from vectors, and the search path uses the codes either way, so a test that only checks results passes against an implementation that never switched at all. Each test here is therefore aimed at something that changes when the behaviour changes, and each was checked to fail without the code it covers.

insertsAfterTheSwitchScoreFromTheCodes counts vectorizer calls for insertions made after the switch: under 20 per node with the codes, 1818 without. It measures insertions rather than the switch itself because optimize() runs cleanup() on the old exact-provider builder first, and that alone costs a couple of hundred reads per node, swamping the signal. An earlier version measured across optimize() and reported that cleanup as a failure.

aMutationWhilePreparingDiscardsTheSwitchRatherThanTheMutation drives a mutation into the window between the plan and the swap, through the same kind of seam the persist-window regression test uses, and asserts the switch is discarded, the mutation survives, and the next optimization switches. It runs with eventual indexing, because that is what routes the mutation through a background callback holding only the read lock - the path that can overtake the plan - and it drains the queue before asserting, since map.set only enqueues there. An earlier version did neither and passed for a reason unrelated to what it claimed.

removeAllLetsTheIndexSwitchAgain covers the state reset: the codes describe a graph that removeAll destroys, and because the switch returns early when they are present, an index emptied and refilled would otherwise have reported compressed scoring against a codebook for data it no longer held, permanently.

compressedScoringCollapsesVectorLookupsPerQuery and recallStaysHighAfterTheSwitch cover the two halves of the bargain - that traversal really does use the codes, and that graph quality survives construction without reranking. mutationsAfterTheSwitchStayConsistent and its exact-index control cover add, remove and update once the switch has happened.

* GigaMap/jvector: describe PQ_IN_MEMORY as heap codes, not as a sidecar file

The mode was documented from the on-disk side throughout, because that is where it started: codes in a .pqv sidecar, read into heap on load. For an in-memory index none of that is true. There is no persist to write a sidecar at, so there is no sidecar; the codes are built in heap during the optimization that switches the index over, and rebuilt the same way after a restart. A reader following the enum documentation, the configuration reference or the README would look for a file that is never written.

All four now say where the codes come from in each case rather than describing one and implying it covers both.

The advanced-guide example also left minChangesBetweenOptimizations at its default of 1000 while showing an index that switches at optimization. An index of a few hundred vectors never reaches that threshold, so the example configured exactly the case build() warns about and demonstrated a switch that would not happen.

* GigaMap/jvector: correct a search-path comment left describing the removed design

The gate on the in-memory search path explained itself by contrast with a build-path gate that no longer works that way: the codes used to be published empty and filled by a replay, so the two sites needed different conditions and the comment said why. The switch now encodes everything before anything is swapped in, so a published store is always a populated one.

The count check stays - an empty store would mean there is nothing to score from, and falling back to exact is then right rather than a missed optimisation - but it is now a defensive check rather than the load-bearing distinction the comment described.

* GigaMap/jvector: let the switch own its compression manager, and report from what is published

Phases two and three run outside the monitor, and both reached this.pqManager. That field is not stable across them: closeInternalResources nulls it and initializeIndex installs a new one, so internalRemoveAll running alongside a switch could leave phase two training a manager the index had already discarded, or a null one. The discard path was worse - it reset whichever manager happened to be installed when it ran, which for a teardown followed by a successful second switch means clearing a codebook that was in use.

The plan now carries the manager it was made for. Phase two trains that one, phase three refuses to publish unless it is still the index's, and the discard resets it only when it is. Ownership rather than re-reading, which is the same discipline the deferred builder ops already follow for the builder field.

isPqCompressionActive() reported from the codebook, which is set at the start of a transition that then encodes every ordinal and rebuilds the graph with no lock held. For as long as that took, the index answered that compressed scoring was in effect while search was still selecting the exact provider - and that method's whole contract is to report what the index is doing rather than what it was asked to do. For an in-memory index it now reports the published codes, which appear at the same instant as the graph that scores from them.

The test for that needed a seam of its own. The existing one fires before training, where a codebook does not exist yet and the old implementation would have read false too - so the first version of this test passed against the very bug it was written for. The new seam fires once the replacement is built and before the swap, which is the only stretch where the two witnesses disagree.

Also scopes the on-disk requirement on the builder's approximateScoring setter to FUSED_PQ, matching the accessor and the validation it documents.

* GigaMap/jvector: close five races around the in-memory PQ switch

structuralModCount is the witness phase three revalidates against before adopting a replacement, and it was a plain field. Mutations bump it holding only the parentMap monitor while that check runs under builderLock with the monitor released, so the write lock supplies no happens-before edge between them and the switch could read a stale count and adopt a graph built before a mutation it never saw. Volatile now.

Phase two read the manager's isTrained() and getPQ() as two separate calls. A teardown between them leaves the second returning null, and MutablePQVectors fails on it before the identity guard in phase three could decline the switch. The codebook …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jshook jshook jshook approved these changes
@MarkWolters MarkWolters MarkWolters approved these changes
@ashkrisk ashkrisk ashkrisk approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@tlwillke tlwillke

Labels

bug Something isn't working

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Search pruning via usePruning can be too aggressive for non-hierarchical graph indices

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@tlwillke @jshook @MarkWolters @ashkrisk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.