← Back to Pull requests

Add Asymmetric Scalar Hashing (ASH) quantization #796

Closed
unknown closed this pull request without merging on Nov 22, 2026 19:00 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 01:23 UTC
Author

Summary

Adds ASH (Asymmetric Scalar Hashing) quantization, introduced in ASH: Asymmetric Scalar Hashing With Learned Dimensionality Reduction for High-Fidelity Vector Quantization (Tepper and Willke, CIKM 2026). ASH reduces the dimension of database vectors with a learned orthonormal projection, then quantizes each projected dimension to a few bits, while keeping queries in their original form. At the same code size it is more accurate than additive and scalar quantizers, trains and encodes quickly, and scores with SIMD lookups. This PR brings ASH to a graph index for the first time.

Quantizer

  • Training and encoding. AsymmetricHashing trains an ITQ or random projection; encodeAll produces ASHVectors, a CompressedVectors with codes in compact shared pages. Graph indexes use one landmark.

  • Similarity. The similarity is a property of the model, and so of an index that stores it, not a choice made at scoring time as with PQ. AsymmetricHashing.initialize takes DOT_PRODUCT, EUCLIDEAN or COSINE as a required argument, with no default; the model saves it, every scorer of its codes uses it, and a request for any other similarity fails with IllegalArgumentException. CompressedVectors.similarityFunction() and ScoreFunction.similarityFunction() report it (null for PQ, whose caller chooses). Vectors need not be normalized: EUCLIDEAN follows the paper's Euclidean decomposition, storing a scale with each code's offset, and COSINE normalizes vectors and queries, then scores dot products.

  • In-memory graphs. ASHVectors score construction and search. BuildScoreProvider.ashBuildScoreProvider builds by comparing stored codes (symmetric scoring).
  • On-disk indexes

  • Fused ASH. FusedASH (FeatureId.FUSED_ASH) stores neighbors' codes with each adjacency list and the model in the index header, at 1 to 9 bits per dimension, with NVQ or full-precision reranking.

  • Separate ASH codes. An on-disk graph without fused codes can be searched with ASHVectors held in memory, as with PQ.

  • Memory accounting. A fused ASH graph’s ramBytesUsed() includes its ASH model, with nativeBytesUsed() for the native part.

  • Page-aligned records. withPageAlignment(pageBytes) on graph writer builders places base-layer records so none crosses a page boundary, so an index served from storage reads the fewest pages per node. Pages are counted from the file's start, so an index written after other data in a file lines up too. Opt-in; format version 7.
  • Streamed construction

  • StreamingASHIndex indexes vectors as they arrive. Until its first model is trained from a reservoir sample, it records the vectors and answers searches by scoring them exactly. It then inserts the recorded vectors into a graph of ASH codes in MutableASHVectors (thread-safe encode, set and snapshot) while new inserts continue; inserts do not wait for training.

  • Batch encoding. AsymmetricHashing.vectorsBuilder(capacity) encodes batches from any number of threads into an immutable ASHVectors, and its live view lets a graph be built over the codes as they fill in.
  • Queries

  • Query projection. With the native provider, the default auto projects queries in INT8 on x86 processors with VNNI or AMX, then FP16 where the CPU supports it, falling back to FP32. INT8 uses a Highway kernel in libjvector on CPUs with AVX-512 VNNI and the oneDNN add-on on the rest. AsymmetricHashing.setQueryOptions sets precision and batch size in code; the system properties remain the defaults.

  • Shared projection. QueryPreparer/PreparedQuery separate projection from search, and BatchingExecutor queues concurrent searches with bounded admission so that waiting queries share one batched projection.

  • Single-vector scoring (separated codes, streaming indexes and fused upper layers). 1-bit codes use a SIMD masked add over their sign bits, summed in a fixed order. 2- and 4-bit codes use a projection dot that decodes codes in registers: native Highway kernels, or with Panama a contiguous-query kernel on JDK 25+ and the query-gather kernel on earlier JDKs. Offset-binary widths (3 and 5 to 9 bits) use the native nibble-LUT dot; with Panama they are decoded in scalar Java. Fused graphs score base-layer neighborhoods with whole-block kernels.
  • Operations and benchmarking

  • BLAS threads. JVector sets the native BLAS thread count for ASH training (one, or the size of the executor passed in), instead of MKL or OpenBLAS starting a thread per CPU. MKL's count is set per thread; OpenBLAS's is process-wide, so concurrent trainings share one count until the last finishes.

  • BenchYAML. Schema 3 index YAML with explicit pipelines and worker counts; compressed dataset defaults use fused ASH; a launcher runs one experiment in one JVM. New settings cover page alignment, cold-query measurement, streamed and saved in-memory builds, and the upper layers' degree.

  • ASH versus PQ harness. run-ash-pq-study.py reproduces the ASH versus PQ comparison on public 1M datasets, building in one JVM and measuring each query budget in a fresh JVM with only that CPU budget.
  • Experimental, off by default

  • Adaptive termination: GraphSearcher.useAdaptiveTermination(true) stops a top-K search by distance instead of beam width, for dot-product, cosine and Euclidean similarity on vectors of any length. Raising the overquery has so far given more recall at the same throughput, so searches keep the standard rule; graph construction with ASH still uses it.

  • Gathered neighborhood scoring: -Djvector.ash.gatheredScoring=true scores a node's neighbors from in-memory ASH codes as one gathered block, as fused ASH scores its stored neighborhoods. It lowers single-query latency, but with every core busy it has measured 1–6% lower throughput than scoring one node at a time.
  • Release notes: 796.feature.md, 796.enhancement.md. Documentation starts at ASH configuration and defaults and Integrating ASH queries into a database.

    Compatibility

  • On-disk format version 7 adds fused ASH and page alignment, and stores the largest vector length that adaptive dot-product stopping needs (in serialized PQ models and the inline and separated vector headers); serialized ASH models also require it, and store their similarity and, for EUCLIDEAN, a scale unit. JVector 4.0.x rejects version 7 files. CURRENT_VERSION and the writer defaults are now 7.

  • Formats 6 and below are unchanged. A host that passes withVersion(6) and write(out, 6) keeps writing files 4.0.x reads, and a version 6 writer rejects fused ASH and page alignment. A host that passes an explicit version to every write keeps its current format until it chooses version 7. See UPGRADING.md.

  • Compaction. OnDiskGraphIndexCompactor (from #798) writes version 7 by default; withVersion(6) keeps a rollback to 4.0.x possible, and its compressed sidecar is written at the same version. It does not yet compact fused ASH or page-aligned indexes.

  • PQ, BQ and NVQ behavior and their defaults are unchanged, and searches stop by the standard rule unless adaptive termination is turned on. ASH scores use the exact scales: (1 + dot) / 2 without a lower bound for dot product, the scale exact dot-product scoring uses, 1 / (1 + d²) for Euclidean and (1 + cos) / 2 for cosine.

  • The new public ASH types are marked @Experimental.
  • Dependencies

  • New Maven dependencies: dev.ludovic.netlib:blas and dev.ludovic.netlib:lapack 3.0.3 (MIT), which bring net.sourceforge.f2j:arpack_combined_all 0.1 (BSD). They are used only for ASH training, and the published jvector artifact declares them. netlib calls the system BLAS and LAPACK, such as MKL or OpenBLAS, and falls back to Java implementations when none is installed, at a cost in training time.

  • oneDNN 3.14.0 (Apache 2.0) for native FP16 query projection, FP32 batch encoding, and INT8 query projection on CPUs without AVX-512 VNNI. Meson fetches it at a pinned commit, and it is linked statically into a separate add-on library, libjvector_ash_fp16-<arch>.so (19 MB on x86-64), shipped in the native JAR with its license and third-party notices. Building it needs CMake 3.13 or later, so it is opt-in: Maven builds it only with -Dnative.onednn=true, which CI and the release profile set, and default native builds take seconds.

  • Highway is now fetched as a Meson wrap (subprojects/highway.wrap), pinned at the revision of the former git submodule; the native build no longer needs git submodule update.
  • Native interface

  • The native ABI stays at 1. The ASH kernels in libjvector (query projection in FP32 and INT8, symmetric construction scoring, neighborhood and single-vector scoring) are compatible additions under the existing handshake. Java looks each one up separately, so an older native library keeps the Java implementations; an explicitly native ASH benchmark fails instead of measuring a fallback.

  • AVX3_VNNI dispatch tier. A new x86 tier between AVX3 and AVX3_DL (Cascade Lake, Cooper Lake) carries the INT8 projection kernel. JVECTOR_MAX_ISA=avx3_vnni selects it, and JVECTOR_MAX_ISA=avx3 now excludes VNNI kernels.

  • The oneDNN add-on has its own ABI query (jvector_ash_fp16_abi, currently 1) and status codes, and no C++ exception crosses it. It loads only if present and compatible; otherwise FP16 and INT8 projection are unavailable and queries use the Highway FP32 path. Its Java bindings (NativeAshOneDnn) are generated with jextract, and each entry point is checked before its first call, so an add-on that lacks a newer entry point falls back instead of failing. Its INT8 functions use an AVX2 target and are reached only after oneDNN confirms a VNNI or AMX backend. See Native ABI compatibility.
  • Validation

  • CI: all 21 checks pass at the final head, which merges main through #781: JDK 11, 20 and 22 on Linux and Windows; JDK 20 and 24 on x86 with SSE4.2, AVX2 and AVX-512; JDK 24 on ARM with NEON, SVE and SVE2; and the AVX-512 test and compaction jobs.

  • Merge with #798: the compactor, on-disk index, page alignment, streaming ASH and all ASH suites pass with the native provider on JDK 22 (214 tests, no failures).

  • Merge with #781: retained-memory totals, including fused ASH graphs and their native memory, match independent measurements on JDK 11, 22 and 25.

  • Similarity: EUCLIDEAN scores approach exact distances at full resolution and agree across every scorer, and scaling vectors by a power of two changes only the scale unit. COSINE on raw vectors equals dot product on normalized vectors, whatever their lengths, and rejects zero vectors. Both are saved with the model and find their neighbors in graph searches in memory and on disk, and EUCLIDEAN in a streaming index.

  • INT8 projection: the Highway and oneDNN kernels give identical outputs, and the dispatcher reports the AVX3_VNNI tier where the CPU has it.

  • Format versions: round trips for every selectable version (3 through 7, single- and multi-layer), version 6 with fused PQ, NVQ and a hierarchy, rejection of fused ASH at version 6, ASH model version and magic-number checks, and compaction at versions 6 and 7, including fused PQ.

  • BLAS threads: with MKL, ASH training without an executor starts no MKL threads, and with a 48-thread executor it starts 48. With OpenBLAS, trainings on two threads share the process-wide count and restore it.

  • Full suite and rollback reads: at the final head, the full suite with the native provider has no failures on JDK 22 and JDK 25. Files written in widely used existing layouts (format 6 with fused PQ, NVQ and a hierarchy; format 6 with NVQ; format 4 with inline vectors; separate PQ vectors at versions 4 and 6) were read with this branch on both JDKs and with JVector 4.0.0-rc.8-hf1 from Maven Central. Headers, features and all-layer adjacency were identical; top-10 node IDs matched for all 75 searches, and scores differed by at most 1e-6.
  • Benchmarking

    Fused ASH versus fused PQ at the same stored bytes per vector, including ASH's 5-byte header, on three large datasets. ASH builds 2.55 times faster overall and has lower construction time in 6 of 6 configurations, higher recall in 12 of 12 cases and higher QPS in 24 of 24.

    Construction

    Total construction seconds (training, encoding, NVQ, graph build and write); lower is better.

    | Dataset | Compression | PQ | ASH | ASH change |
    |---|---|---:|---:|---:|
    | MPNet 10M | 32x (b=2) | 237.4 | 145.8 | -38.6% |
    | MPNet 10M | 16x (b=4) | 436.8 | 173.2 | -60.3% |
    | Cohere 10M | 32x (b=2) | 380.3 | 154.7 | -59.3% |
    | Cohere 10M | 16x (b=4) | 609.0 | 197.5 | -67.6% |
    | CAP 6M | 32x (b=2) | 216.7 | 109.2 | -49.6% |
    | CAP 6M | 16x (b=4) | 519.0 | 160.5 | -69.1% |
    | Sum | | 2,399.2 | 940.9 | -60.8% |

    Recall and throughput

    Values: PQ → ASH. Rerank 1x and 2x rescore 10 and 20 candidates with NVQ.

    | Dataset | Compression | Rerank | Recall@10 | QPS, 1 core | QPS, 8 cores |
    |---|---|---|---:|---:|---:|
    | MPNet 10M | 32x (b=2) | 1x | 0.5397 → 0.7568 | 8,048 → 9,122 | 58,864 → 74,639 |
    | MPNet 10M | 32x (b=2) | 2x | 0.7122 → 0.8908 | 7,049 → 7,637 | 50,322 → 56,018 |
    | MPNet 10M | 16x (b=4) | 1x | 0.7270 → 0.8124 | 7,682 → 9,422 | 49,934 → 71,735 |
    | MPNet 10M | 16x (b=4) | 2x | 0.8645 → 0.9009 | 6,003 → 7,386 | 40,194 → 55,348 |
    | Cohere 10M | 32x (b=2) | 1x | 0.5333 → 0.5931 | 7,734 → 9,342 | 50,563 → 69,266 |
    | Cohere 10M | 32x (b=2) | 2x | 0.7144 → 0.7665 | 6,175 → 7,296 | 45,679 → 50,390 |
    | Cohere 10M | 16x (b=4) | 1x | 0.6013 → 0.6550 | 6,318 → 8,585 | 45,298 → 61,948 |
    | Cohere 10M | 16x (b=4) | 2x | 0.7605 → 0.7910 | 4,904 → 6,363 | 37,202 → 47,507 |
    | CAP 6M | 32x (b=2) | 1x | 0.4118 → 0.7224 | 5,287 → 7,311 | 42,230 → 57,197 |
    | CAP 6M | 32x (b=2) | 2x | 0.6001 → 0.8858 | 4,951 → 5,713 | 36,763 → 46,288 |
    | CAP 6M | 16x (b=4) | 1x | 0.6624 → 0.8012 | 4,043 → 6,581 | 30,878 → 46,394 |
    | CAP 6M | 16x (b=4) | 2x | 0.8404 → 0.9066 | 3,425 → 4,911 | 26,420 → 38,293 |

    Eight-core QPS varies by up to about 15% between runs of the same index, so small differences are within noise.

    Method

    One Intel Xeon 6985P-C socket (Google Cloud c4-standard-96-lssd: 48 physical cores, two threads per core, two NUMA nodes), JDK 22.0.2, native provider with the oneDNN add-on, ash-dev 25b6d845. On-disk format 7, fused graph, degree 32, efConstruction 100, overflow 1.2, hierarchy and refinement on, NVQ reranking, search pruning off, top 10. ASH: ITQ, one landmark, D/2 projected dimensions, symmetric construction scoring; queries use the default auto projection (INT8 on this CPU), queued execution with batches of up to 8, adaptive termination. PQ: 8-bit subspaces sized to the same bytes, no centering, anisotropic weighting off; direct execution with four caller threads per core, standard termination. Each index was built once, using both threads of all 48 cores with memory interleaved across both nodes. Queries ran against a warm index with held-out queries never seen before, in a separate JVM per rerank depth and core count, on 1 core or 8 cores of one node. One-core QPS is one run; eight-core QPS is the mean of three. PQ and ASH were measured in the same campaign with the same build. Full details: ASH performance. The study can be rerun with Reproducing ASH versus PQ.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: r-devulap Review duration: 18337m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #796"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%