Skip to content

Stream BenchYAML builds with PQ or full precision as well as ASH - #852

Open
tlwillke wants to merge 3 commits into
mainfrom
streaming-builds-pq-fp
Open

tlwillke wants to merge 3 commits into
mainfrom
streaming-builds-pq-fp

Conversation

@tlwillke

Copy link
Copy Markdown
Collaborator

Stream BenchYAML builds with PQ or full precision as well as ASH

BenchYAML's construction.streaming: Yes built only ASH indexes. In-progress PQ codes, which a database uses while it builds an index, could be timed only with a JMH benchmark. This change lets any streaming case use ASH, PQ or no compression. In-progress PQ builds can then be benchmarked from a YAML file, and PQ and ASH compared for live graph builds that might one day replace full-precision ones. One use is checking a fix for #845 on both PQ paths.

Each construction compression defines how a streaming index starts and what an insert does:

  • ASH: unchanged. A StreamingASHIndex starts warm (coldStartSize: [0]) or cold, and may train while vectors arrive.
  • PQ: the PQ model is trained first. Each arriving vector is encoded into MutablePQVectors and then added to the graph, which scores with those codes. With refineAfter: [N], once N vectors have arrived, inserts wait while the codebook is fine-tuned on them (ProductQuantization.refine), the codes so far are re-encoded, and the graph's edges are rescored (GraphIndexBuilder.rescore). This is what a compaction that inherits a codebook does.
  • None: each arriving vector is added to the graph with exact scores.

The rest is shared: one insert thread per construction worker in file order, the timings, the memory report, and the onDisk write and reload. Searches use the codes the index built. For ASH and PQ, those codes are stored beside the index, both on disk and in the saved-index cache, and reloaded with it. The codes file gains a PQ format for this, and batch builds still store only ASH codes, as before. onDisk None indexes are searched with search.compression, as other on-disk builds are.

PQ and None take no cold start: coldStartSize and trainWhileStreaming are rejected unless omitted, [0] or No. refineAfter requires PQ and is 0 or at least the PQ k, so every centroid is refined from its own vectors. BQ streaming is rejected, because MutableBQVectors is not safe for concurrent writes.

Also:

  • Fixes the guide's cold-start description: a cold ASH index searches its recorded vectors exactly and builds its graph only once its first model is ready.
  • Adds the examples index-parameters/streaming-pq (cohere-english-v3-1M, PQ with D/8 subspaces, with and without a refinement after 128,000 vectors) and index-parameters/streaming-fp (the same build with exact scores).

Streaming times are comparable only with other streaming runs: insert order and threads differ from batch builds.

Tests

  • TestGridASHIntegration:
    • PQ codes built on arrival match one-pass encoding.
    • After a refinement, every code comes from the refined model and nodes added before it stay reachable.
    • PQ and None stream, then search, in memory and on disk; on disk, PQ is searched with the reloaded codes.
    • PQ codes round-trip through the codes file, and only for indexes that built them.
    • Cold starts outside ASH, refineAfter outside PQ or below k, and BQ are rejected.
    • The examples parse.
    • The existing ASH streaming tests are unchanged.
  • The io.github.jbellis.jvector.example tests (56) pass on Ice Lake (8 cores) with JDK 22 and JDK 25.

Each codec defines how a streaming index starts and what an insert does; PQ encodes into mutable codes on arrival.
Streaming PQ indexes keep their codes beside the index; refineAfter fine-tunes the codebook once and rescores the graph.
@github-actions

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.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants