Skip to content

Add RaBitQ-Library client with HNSW-RaBitQ index - #900

Open
TamimEhsan wants to merge 22 commits into
zilliztech:mainfrom
TamimEhsan:feat/rabitq-hnsw
Open

TamimEhsan wants to merge 22 commits into
zilliztech:mainfrom
TamimEhsan:feat/rabitq-hnsw

Conversation

@TamimEhsan

Copy link
Copy Markdown

Summary

This PR adds an embedded client for RaBitQ-Library (rabitqlib) and its first index type, HNSW-RaBitQ. HNSW-RaBitQ searches an HNSW graph over RaBitQ-quantized codes. The library runs in-process, like the existing zvec and qdrantlocal clients.

pip install vectordb-bench[rabitqlib]
vectordbbench rabitqlibhnsw --path /data/rabitqlib --nbits 9 --m 32 --ef-search 256 \
  --case-type Performance768D1M

How it fits the benchmark's process model

VectorDBBench loads, optimizes and searches in separate processes. An in-process library therefore has to keep all its state in files under --path:

  • Load: insert_embeddings appends each batch to a raw buffer (buffer.vectors.f32 and buffer.ids.i64). The two files stay row-aligned because appends hold a lock, which matters because up to 4 insert threads share one client.

  • Optimize: the whole buffer goes into one HnswIndex.add. The library trains its centroids inside that call, over the full dataset. The client then saves three things:

    • the index;
    • a map from library point IDs to dataset IDs;
    • a manifest of the build parameters.

    The manifest is written last, so its presence marks a complete build. All three files are named after the index type (rabitqlib_hnsw.*), so later index types can share a path.

  • Search: each search process loads the saved index when it unpickles the client (__setstate__). This happens before the concurrent runner's start barrier. Loading in init() would happen after the barrier and count the load time as search time. On GIST1M at concurrency 32, that made reported QPS 23K when the real figure was 55K.

Behaviour and limits

  • Static, unfiltered performance cases only. The index can't filter on scalars, so supported_filter_types = [NonFilter] and filtered cases are rejected up front. Vectors inserted after the build return a NonRetryableInsertError rather than being silently lost.
  • Metrics: L2 and IP. Cosine runs as IP on vectors that VectorDBBench normalizes (need_normalize_cosine returns True).
  • Minimum dimension is 64, a library requirement. Smaller datasets fail at client construction with a clear error.
  • Reuse with --skip-drop-old --skip-load: the client compares the manifest against the requested parameters. Only --ef-search may differ from the build. If any build parameter differs, the client refuses the index instead of reporting results for a different index.
  • drop_old deletes only the buffer and this index type's files, never the rest of the directory.
  • A leftover unbuilt buffer from an interrupted run stops the client with an error instead of loading the data twice.
  • Search runs single-threaded per query (num_threads=1), to match the other clients' per-process concurrency.

Options

Option Default Notes
--path required Holds the buffer, the index and the manifest
--nbits 9 Total bits per coordinate, including the sign bit; 9 (sign + 8) is the fastest kernel
--num-clusters 16 Centroids trained by the library
--m 16 HNSW degree
--ef-construction 200
--ef-search 128 Raised to k when smaller
--seed 100 Rotation and graph seed
--build-threads 0 0 uses every CPU, capped by OMP_NUM_THREADS

Changes

  • vectordb_bench/backend/clients/rabitqlib/: new client, configs and CLI command.
  • backend/clients/__init__.py, api.py: register DB.RaBitQLib and IndexType.RABITQLIB_HNSW.
  • cli/vectordbbench.py: register the rabitqlibhnsw command.
  • pyproject.toml: new rabitqlib optional dependency.
  • tests/test_rabitqlib.py: 20 tests. They cover:
    • concurrent shuffled inserts;
    • recall on L2 and IP;
    • pickle round trip, and that a spawned process loads the index before init;
    • batch and single search returning the same results;
    • index reuse, and rejection when build parameters change;
    • rejection of inserts after the build, a leftover buffer, the wrong dimension, too small a dimension, and filters;
    • drop_old leaving unrelated files alone.
  • README.md: install row and a usage section.

Benchmark: GIST1M (960-d, L2, k=100)

The baseline is Zvec fp32 HNSW, built with the same graph parameters as the RaBitQ index (M=32, ef_construction=200). Both are embedded clients, so they ran under the same process model on the same machine. Machine: 2× Intel Xeon Gold 6418H (96 threads), 1 TB RAM.

RaBitQ: nbits=9, num_clusters=16. RaBitQ built in 106 s; Zvec took about 2 min.

ef_search Index Recall@100 QPS c=1 QPS c=8 QPS c=32
128 RaBitQ HNSW 0.8266 2,565 17,894 54,222
128 Zvec HNSW fp32 0.8262 704 3,424 9,259
256 RaBitQ HNSW 0.9124 1,615 11,567 37,085
256 Zvec HNSW fp32 0.9136 395 2,276 5,856
512 RaBitQ HNSW 0.9582 1,021 7,180 22,859
512 Zvec HNSW fp32 0.9615 237 1,292 3,087
RaBitQ HNSW Zvec HNSW fp32
Index file 1.38 GB 4.0 GB
Memory per search process ~1.6 GB ~4.3 GB

At equal ef_search the two reach the same recall, as expected for the same graph parameters. At equal recall, RaBitQ gives 3.6–7.4× the QPS with about a third of the memory.

To check the client itself, I queried the saved index directly through rabitqlib and scored it against the GIST ground truth. Recall matched VectorDBBench's to four decimals (0.8266 / 0.9124 / 0.9582).

To reproduce, convert GIST1M to a custom parquet dataset and run:

CASE="--case-type PerformanceCustomDataset --custom-case-name GIST1M \
  --custom-dataset-name GIST --custom-dataset-dir $GIST \
  --custom-dataset-size 1000000 --custom-dataset-dim 960 --custom-dataset-metric-type L2 \
  --custom-dataset-file-count 10 --skip-custom-dataset-use-shuffled --custom-dataset-with-gt \
  --k 100 --num-concurrency 1,8,32"

vectordbbench rabitqlibhnsw --path $IDX/rabitqlib_gist1m --nbits 9 --m 32 \
  --num-clusters 16 --ef-construction 200 --ef-search 256 $CASE
vectordbbench zvec --path $IDX/zvec_gist1m --m 32 --ef-construction 200 --ef-search 256 $CASE

Test plan

  • pytest tests/test_rabitqlib.py: 20 passed
  • ruff check / ruff format --check on the changed files
  • OpenAI 50K end to end (Performance1536D50K): recall 0.9538; QPS 3,385 at c=1 and 11,010 at c=4
  • GIST1M end to end against Zvec (table above)
  • Recall checked against direct library queries

@jamesgao-jpg jamesgao-jpg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the contribution! I found a few correctness and integration issues to address:

def _check_manifest(self) -> None:
"""Refuse to reuse an index built with other parameters or data."""
manifest = json.loads(self._file(self.manifest_file).read_text())
if manifest.get("dim") != self.dim or manifest.get("index_param") != self.index_param:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Validate dataset identity and the original metric before reuse

This check accepts any dataset with the same dimension and build parameters, and COSINE and IP both become ip in index_param. I reproduced a COSINE-built manifest being accepted for an IP run; the stored vectors are normalized for COSINE but not for IP. Reusing a different dataset can likewise produce measurements against the wrong data and ground truth. Could the manifest record and validate the dataset identity and original metric/normalization mode, while still allowing search-only parameters such as ef_search to change? Please add mismatch regression tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed the metric part in e319284. The manifest now stores the original metric_type (COSINE / IP / L2), not only the mapped library metric, and reuse is refused when it differs, so a COSINE-built index is no longer accepted for an IP run or the other way round. ef_search can still change on reuse. Regression tests: test_reuse_rejects_cosine_ip_swap (both directions), plus test_reuse_rejects_other_build_params, test_reuse_rejects_other_dim and test_reuse_accepts_other_search_params.

I left dataset identity out on purpose. The runner only gives a client dim, its DB config and case config, and never says which dataset is being loaded, so the client can't check it without changing the assembler/runner interface for every client. No existing client validates the dataset on --skip-load reuse either. If you'd like it, I'm happy to do it in a separate PR that passes the dataset name to clients.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing the COSINE/IP mismatch and adding regression tests. The dataset-identity part is still important for correctness: with a synthetic manifest, I confirmed that a Cohere 1M index is accepted for a Cohere 10M case because the dimension, metric, and index parameters match. Search would then use the wrong indexed data and ground truth.

Since the merge from main, WARM provides a precedent for passing dataset identity to a specific client without changing every client:

extra_db_kwargs = {}
if self.config.db is DB.Warm:
extra_db_kwargs["dataset_identity"] = self.ca.dataset.data.model_dump(mode="json")

Could RaBitQLib also record and validate a stable dataset identity before reuse, with a regression test for two different datasets of the same dimension and metric? Search-only parameters such as ef_search should remain free to change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in db81d47, following WARM's approach. The case runner now passes dataset_identity to RaBitQLib too: the hard-coded DB.Warm checks now read a shared DB.builds_static_index property, true for WARM and RaBitQLib. The client requires it, records it in the manifest and refuses a mismatch on reuse. ef_search stays free to change. Tests: test_reuse_rejects_another_dataset_of_same_dim_and_metric (Cohere 1M index refused for Cohere 10M, ef_search change accepted), test_reuse_rejects_dataset_with_other_settings, test_reuse_rejects_index_without_recorded_dataset, test_requires_dataset_identity and test_case_runner_passes_dataset_identity.

if self._built():
msg = (
f"{self.name} builds its index once, in optimize; vectors inserted after the build "
"are not supported (static performance cases only)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Reject workloads that require searchable incremental inserts

The static-index limitation is not enforced when choosing a case: the assembler currently accepts streaming and capacity workloads for this backend. An insert only writes to the buffer, so a streaming search before optimize fails; the streaming runner catches intermediate search failures and may report zero-valued measurements. Capacity runs instead measure buffer growth and can fill disk without building an index. Could we reject these unsupported case labels before loading or writing data, and add regression tests for both?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in f69dbe0. The rabitqlibhnsw command checks the case label first and refuses anything other than performance cases, before any client is created or file written. Tests: test_cli_rejects_non_performance_cases_before_running (capacity, streaming, label-filter, int-filter, FTS and the cloud cases, checking exit code 2 and that no files are created) and test_cli_accepts_performance_cases.

In the web UI, RaBitQLib only declares inputs for CaseLabel.Performance, but the UI can still offer the other cases. Its only per-database filter is the supportedDbs allow-list on UICaseItem, which today is used only for FTS. Excluding one database from the capacity and streaming items would mean listing every other database on those items. I can do that if you prefer, but it touches shared UI config, so I kept it out.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding the CLI guard. I confirmed it rejects capacity and streaming cases, but UI-generated tasks for both still pass task construction and assembly, so the underlying issue remains for the UI and programmatic callers. Capacity can grow the load buffer without measuring indexed capacity; streaming can search before the index exists.

Since the merge from main, the UI has a supports_case_label hook used for WARM:

def supports_case_label(self, label: "CaseLabel") -> bool:
from ..cases import CaseLabel
return self != DB.Warm or label == CaseLabel.Performance

Could we extend the shared case-support check and task validation to RaBitQLib, so unsupported cases are rejected before data loading or file writes across all entry points? Please add tests for UI and direct task construction as well as the CLI.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 97e24b9. supports_case_label and TaskConfig.validate_supported_workload now use the same builds_static_index property, so RaBitQLib gets WARM's checks. The UI hides capacity and streaming items when RaBitQLib is selected, and constructing a task for an unsupported case raises before any client is created or file written. The CLI check stays, since it fails earlier with exit code 2. Tests: test_ui_offers_only_performance_cases (RaBitQLib alone and mixed with Milvus, across all UI clusters), test_task_construction_rejects_non_performance_cases (capacity, streaming, FTS, cloud insert), test_task_construction_accepts_performance_cases, plus the existing CLI tests.

num_clusters: int = 16
M: int = 16
ef_construction: int = 200
ef_search: int = 128

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Expose HNSW parameters in the web UI

RaBitQLib is selectable in the web UI, but it has no entry in the frontend case-configuration map. The UI therefore shows Auto and generates a task with defaults, leaving users unable to tune ef_search, M, nbits, or the other index parameters. Could we add the applicable performance-case inputs and a focused UI configuration test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 0386946, with fff93ab adding a num_clusters member to CaseConfigParamType and syncing the ranges. RaBitQLib now has performance-case inputs for nbits, num_clusters, M, ef_construction and ef_search, with the library's defaults. seed and build_threads keep their defaults in the UI, as other clients do with their non-tuning settings. Tests in tests/test_rabitqlib_ui_config.py build tasks through generate_tasks, as the Run Test page does, and check that the defaults match the config, tuned values reach the client, and every input's min/max/default matches the CLI option.

Comment thread tests/test_rabitqlib.py Outdated
import numpy as np
import pytest

pytest.importorskip("rabitqlib")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Install the RaBitQLib extra in at least one CI job

CI currently installs .[test], whereas rabitqlib is a separate optional extra, so this import guard skips the entire new client test module in the existing jobs. A local run without the extra reported one skipped module. Could one supported CI environment install .[test,rabitqlib] and run these tests, ideally including the declared minimum supported version?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in d9b0f68. The ubuntu-latest / Python 3.11 job now installs .[test,rabitqlib] pinned to the declared minimum, rabitqlib==0.8.3, and runs both rabitqlib test modules. It sets RABITQLIB_REQUIRED=1, which turns the import guard into a hard import, so a missing or broken install fails the job instead of skipping the module. Other jobs still skip without the extra.

@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: TamimEhsan
To complete the pull request process, please assign jamesgao-jpg after the PR has been reviewed.
You can assign the PR to them by writing /assign @jamesgao-jpg in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

def _build_identity(self) -> dict:
"""What a reused index must match; search parameters such as ef may differ."""
return {
"dataset": self.dataset_identity,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Detect replacement of custom training data before reusing an index

The new identity contains dataset configuration, but no content fingerprint or revision for mutable custom training files. If a custom dataset is replaced in place while its path, name, size and other settings remain unchanged, this comparison accepts the old index for the new data; search can then be evaluated against ground truth for different vectors. I reproduced the acceptance with a synthetic manifest and an in-place file replacement, without a live RaBitQ build. This risk predates the new identity check, but remains a gap in that safeguard. Could reuse require a reliable training-data version or fingerprint, with a regression test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, confirmed: for custom datasets the identity is configuration only, so training files replaced in place under the same path, name and size are accepted. Standard datasets aren't affected, since they're fixed downloads (source_revision covers the Hugging Face ones). As you noted, the gap predates this check, and the same applies to WARM and to server-based clients reusing a collection with --skip-load.

I see four options and would like your preference before implementing:

A. Size and modification time per training file
At build time, record each custom training file's name, byte size and mtime_ns in the manifest, and compare on reuse. The file list comes from CustomDataset.train_files, so the client doesn't duplicate the naming logic and the runner doesn't change.

  • Catches overwriting or regenerating the files, at the cost of a few stat calls.
  • Misses a replacement copied with cp -p or rsync -a, which preserve the modification time. I'd document that.

B. Full content hash per training file
Record a SHA-256 of every training file and recompute it on reuse.

  • Catches any content change.
  • Reads the whole training set on every reuse: about 3.6 GB for GIST1M, tens of GB at 10M rows. That largely defeats --skip-load.

C. A user-supplied revision
Add an optional revision field for custom datasets (like source_revision), stored in the identity and checked on reuse.

  • Exact and free when users set it.
  • Relies on users bumping it, and needs a change to the shared custom-dataset config and UI, so it affects every client.

With A orB, reuse would be refused if the training files are missing, rather than accepting an index that can't be verified. This applies only to custom datasets (is_custom).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Option A works well here: for custom datasets (is_custom), recording each training file's name, byte size, and mtime_ns from CustomDataset.train_files (and refusing reuse if any training file is missing or modified) gives fast startup on --skip-load without multi-GB full-file hashing. Documenting the cp -p / rsync -a preserved-mtime caveat and adding a regression test for in-place training-file replacement sounds good — and it pairs cleanly with narrowing dataset_identity in task_runner.py to training-relevant fields so query-only changes (test_file, gt_file) don't trigger a rebuild.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 5b6698a, using option A. For custom datasets (is_custom), the manifest records each training file's name, byte size and mtime_ns from CustomDataset.train_files. Reuse is refused if any file is missing or has changed. Startup stays fast with --skip-load, since there's no content hashing. The README notes that a copy which preserves size and modification time (cp -p, rsync -a) isn't detected. Tests: test_custom_dataset_reuse_checks_training_files covers in-place replacement and a missing file. I also checked it with a real custom-dataset run: an unchanged reuse is accepted, and reuse after copying over the training file is refused.


extra_db_kwargs = {}
if self.config.db is DB.Warm:
if self.config.db.builds_static_index:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Keep query-only settings out of the index build identity

Passing the entire dataset model into the manifest includes fields such as test_file. I reproduced a reuse rejection after changing only the custom query filename while the training directory, training files and index parameters remained unchanged. This forces an unnecessary index rebuild when evaluating the same vectors with a different query set. Could the identity include the training-data properties that affect the built index, while allowing query-only settings to change, with a regression test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 5b6698a. The client now drops the query, ground-truth and filter-label fields (test_, gt_, with_gt, scalar-label fields) before storing and comparing the identity. Changing the query set no longer forces a rebuild, while any other dataset change is still refused. I did this in the client rather than in task_runner.py, because that line is shared with WARM and test_warm_frontend.py checks that WARM receives the full dump. Tests: test_reuse_accepts_other_query_files, plus the narrowed identity in test_case_runner_passes_dataset_identity.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants