Skip to content

Fix NVQParameters.idStringFor format string - #780

Open
tlwillke wants to merge 1 commit into
mainfrom
779-nvqparametersidstringfor-throws-missingformatargumentexception
Open

tlwillke wants to merge 1 commit into
mainfrom
779-nvqparametersidstringfor-throws-missingformatargumentexception

Conversation

@tlwillke

@tlwillke tlwillke commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #779.

NVQParameters.idStringFor passed two arguments to a three-placeholder format string ("NVQ_%s_%d_%s"), so it threw MissingFormatArgumentException. The trailing _%s is removed, so the cache key is now NVQ_<dataset>_<nSubVectors>, matching the PQ key's style.

Nothing constructs NVQParameters today, so behavior doesn't change; this removes a latent failure for when NVQ is wired up as a compressor option.

Testing: adds CompressorParametersTest, which checks the NVQ cache key.

@tlwillke tlwillke self-assigned this Nov 2, 2026
@tlwillke tlwillke added bug Something isn't working 4.1.0 Release Label labels Nov 2, 2026
@tlwillke tlwillke linked an issue Nov 2, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented Nov 2, 2026

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.

@MarkWolters MarkWolters left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@MarkWolters

Copy link
Copy Markdown
Contributor

Cached NVQ compressors would be reloaded as PQ (fixed in #776)

The key fix here is right, but it makes NVQ caching reachable, and the load path can't read what it saves. With idStringFor working, supportsCaching() == true takes effect: Grid.getCompressor saves the NVQuantization to pq_cache/NVQ_<ds>_<n>. On the next run, Grid.loadFromCache reads every cache file with ProductQuantization.load. NVQ's layout starts with a version int, which PQ reads as a v0 centroid length, so you'd get an exception or a corrupt ProductQuantization where an NVQuantization was expected. The test here only checks the key string, never a save and reload, so it doesn't catch this.

loadFromCache is code that #776 (mine) moves and rewrites, so I've fixed it there rather than ask for it here:

  • Adds CompressorParameters.loadCompressor(RandomAccessReader). The default throws UnsupportedOperationException, like idStringFor. PQParameters uses ProductQuantization.load and NVQParameters uses NVQuantization.load.
  • Grid.loadFromCache now calls cp.loadCompressor(...) instead of always ProductQuantization.load.
  • Includes the same idStringFor change as this PR ("NVQ_%s_%d"), because NVQ caching can't be exercised without it.
  • Adds TestCompressorCaching, which round-trips PQ and NVQ through loadCompressor and checks the NVQ key.

How the two interact:

  • Either order merges cleanly. The idStringFor line is identical in both, and your test is a new file under jvector-examples/src/test, separate from the new one in Refactor grid #776.
  • No broken window in between. Nothing constructs NVQParameters outside tests yet, and the YAML compression types don't include NVQ. So if this merges first, the PQ-load path can't be reached before Refactor grid #776 lands.
  • Your test's supportsCaching() assertion is accurate once Refactor grid #776 is in.

So this can merge as is, or you can close it in favour of #776. Either works for me.

@jshook jshook mentioned this pull request Nov 4, 2026

@r-devulap r-devulap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.1.0 Release Label bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NVQParameters.idStringFor throws MissingFormatArgumentException

3 participants