Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,18 @@ require the full [static analysis check](../docs/development.md#static-analysis)
Tests and examples are intentionally excluded from CI clang-tidy; use focused
local analysis for substantial logic changes.
For a first contribution, the formatting check and the affected tests are
enough to open a PR. If a check needs a tool, compiler or CPU you do not have
(for example clang-tidy 23 or a particular SIMD instruction set), say so in the
PR and a maintainer will run it. See [CI routing](../docs/maintaining.md#checks-selected-by-changed-files)
enough to open a PR. Code PRs must be built and tested locally: CI does not
replace building the code you change and running its affected tests. If another
check needs a tool, compiler or CPU you do not have (for example clang-tidy 23 or
a particular SIMD instruction set), say so in the PR and a maintainer will run it.
See [CI routing](../docs/maintaining.md#checks-selected-by-changed-files)
for details.

You are responsible for every change you submit, including changes produced
with automated tools: verify it yourself, report the results, and respond to
review. Code PRs that were not built and tested locally, or that are updated
without addressing review feedback, are closed.

## If setup fails

| Problem | What to check |
Expand Down Expand Up @@ -184,7 +191,9 @@ are small, self-contained tasks that say where to start and when they are done;
[help wanted](https://github.com/VectorDB-NTU/RaBitQ-Library/labels/help%20wanted)
issues are larger. The [roadmap issue](https://github.com/VectorDB-NTU/RaBitQ-Library/issues/220)
lists the goals for the next releases. Comment on an issue before starting so work
is not duplicated.
is not duplicated. When claiming a code issue, say how you will verify the change
locally, such as the tests or benchmark you will run. A maintainer may unassign an
issue when review feedback goes unanswered.

## Feedback and further reading

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)

project(RaBitQLib VERSION 0.8.4 LANGUAGES CXX)
project(RaBitQLib VERSION 0.8.5 LANGUAGES CXX)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ approximate nearest-neighbor search. See the [research papers](https://vectordb-

## News

- **v0.8.5:** accepts the names 0.9 will use (`capacity`, `routing`, `ef_search`,
k-means `nbits`) and deprecates the 0.8 spellings they replace
([notes](https://vectordb-ntu.github.io/RaBitQ-Library/releases/0.8.5/)).
- **v0.8.4:** input validation reads each batch once instead of twice
([notes](https://vectordb-ntu.github.io/RaBitQ-Library/releases/0.8.4/)).
- **v0.8.3:** provisional `rabitqlib.quant` module: rotate, quantize, pack and score
RaBitQ codes stored outside an index
([notes](https://vectordb-ntu.github.io/RaBitQ-Library/releases/0.8.3/)).
- **v0.8.2:** three lines to an index: the first `add` trains, `nbits` defaults to 7
and search settings are optional; faster IVF-RaBitQ `add`
([notes](https://vectordb-ntu.github.io/RaBitQ-Library/releases/0.8.2/)).

Earlier versions: [all releases](https://github.com/VectorDB-NTU/RaBitQ-Library/releases).

Expand Down Expand Up @@ -62,7 +62,7 @@ settings, and limitations.
### Python

```bash
python -m pip install --upgrade "rabitqlib>=0.8.4"
python -m pip install --upgrade "rabitqlib>=0.8.5"
```

Wheels support CPython 3.11–3.14 on Linux x86-64/ARM64, Windows x86-64,
Expand Down
12 changes: 7 additions & 5 deletions benchmarks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def build_index(cfg, base, path):
from rabitqlib import IvfIndex

# The library's default training: QGKMeans above 2,000 clusters, then add
# routes each vector with the index's centroid initializer.
# routes each vector with the index's routing strategy.
index = IvfIndex(
dim, cfg["nlist"], nbits=cfg["bits"], metric=cfg["metric"], seed=42
)
Expand All @@ -141,7 +141,7 @@ def build_index(cfg, base, path):
"assignment": "add routing",
}
elif method == "rabitq-hnsw":
from rabitqlib import FinalAssignmentMode, HnswIndex, RaBitQKMeans
from rabitqlib import HnswIndex, RaBitQKMeans

cluster_count = cfg["hnsw_clusters"]
kmeans = RaBitQKMeans(
Expand All @@ -152,7 +152,7 @@ def build_index(cfg, base, path):
spherical=cfg["metric"] == "ip",
seed=42,
min_points_per_centroid=1,
final_assignment=FinalAssignmentMode.Exact,
final_assignment="exact",
)
stage_start = time.perf_counter()
kmeans.train(base)
Expand All @@ -167,7 +167,7 @@ def build_index(cfg, base, path):
metric=cfg["metric"],
seed=42,
)
index.resize(n)
index.reserve(n)
index.set_centroids(kmeans.centroids)
index.add(base, cluster_ids=kmeans.assignments, num_threads=cfg["threads"])
indexing_s = time.perf_counter() - stage_start
Expand Down Expand Up @@ -259,7 +259,9 @@ def search(index, cfg, queries, threads):
if method == "rabitq-ivf":
return index.search(queries, k=k, nprobe=cfg["nprobe"], num_threads=threads)
if method in ("rabitq-hnsw", "rabitq-symqg"):
return index.search(queries, k=k, ef=cfg["ef_search"], num_threads=threads)
return index.search(
queries, k=k, ef_search=cfg["ef_search"], num_threads=threads
)
raise ValueError(f"unsupported benchmark method: {method}")


Expand Down
10 changes: 5 additions & 5 deletions benchmarks/run_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_base(cfg):

def train_python(method, x, k, threads, seed):
if method == "qgkmeans":
from rabitqlib import FinalAssignmentMode, QGKMeans
from rabitqlib import QGKMeans

start = time.perf_counter()
model = QGKMeans(
Expand All @@ -74,13 +74,13 @@ def train_python(method, x, k, threads, seed):
num_threads=threads,
seed=seed,
spherical=False,
quantization_bits=0,
graph_degree=32,
ef_build=240,
nbits=32,
max_degree=32,
ef_construction=240,
ef_search=16,
graph_build_iterations=1,
early_stop_threshold=0.0,
final_assignment=FinalAssignmentMode.Exact,
final_assignment="exact",
)
model.train(x)
total = time.perf_counter() - start
Expand Down
8 changes: 6 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,13 @@ of 32. These settings are not interchangeable.

Public names and Python keywords are compatibility contracts. For example,
`Cluster::num()`, the protected `Initializer::num_cluster_`, QG's
`degree_bound()`/`set_ef()`, Python's `ef`, and `QGKMeansParameters::ef_build`
`degree_bound()`/`set_ef()` and `QGKMeansParameters::ef_build`
retain their existing spellings, as do the Python vocabulary `random_seed`/`seed`,
`train`/`build`, `obj`, `nsplit`, `final_obj` and `niter`. C++ parameter names may be clarified without
`train`/`build`, `obj`, `nsplit`, `final_obj` and `niter`. Python's search breadth is
`ef_search` since 0.8.5; `ef` is deprecated and removed in 0.9 (#232). Python's `QGKMeans`
and `QGKMeansParameters` take `nbits`, `max_degree` and `ef_construction` since 0.8.5;
`quantization_bits`, `graph_degree` and `ef_build` are deprecated there and removed in
0.9 (#233), while the C++ struct keeps them until 0.9. C++ parameter names may be clarified without
changing types, order or defaults. Keep declarations, definitions and comments
in agreement; do not rename methods or literals by textual substitution.

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/benchmarks/kmeans.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ search. Centroids are not normalized.

| Method | Additional settings |
| --- | --- |
| `rabitqlib.QGKMeans` | `quantization_bits=0`, degree 32, `ef_build=240`, `ef_search=16`, one graph refinement, `early_stop_threshold=0`, `FinalAssignmentMode.Exact` |
| `rabitqlib.QGKMeans` | raw centroid storage (`nbits=32`; `quantization_bits=0` before 0.8.5), degree 32, `ef_construction=240` (`ef_build` before 0.8.5), `ef_search=16`, one graph refinement, `early_stop_threshold=0`, exact final assignment |
| `faiss.Kmeans` | CPU, `nredo=1`, `max_points_per_centroid=N`, `spherical=False`, `early_stop_threshold=0`; exact final `index.search(x, 1)` |
| `superkmeans.SuperKMeans` | v0.2.0, `quantizer="f32"`, `hierarchical=False`, `sampling_fraction=1`, `angular=False`, `use_blas_only=False`, `early_termination=True`, `tol=1e-4`; exact final `assign(x, centroids)` |

Expand Down
33 changes: 20 additions & 13 deletions docs/docs/clustering.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ per centroid; the classes below default to training on every vector.
| Class | Assignment | Recommended use | Cluster count |
| --- | --- | --- | --- |
| [RaBitQKMeans](#rabitqkmeans) | Flat RaBitQ scan | Small cluster counts | `n >= k >= 1` |
| [QGKMeans](#qgkmeans) | SymphonyQG centroid graph | Larger cluster counts | `n >= k > graph_degree` (default 32) |
| [QGKMeans](#qgkmeans) | SymphonyQG centroid graph | Larger cluster counts | `n >= k > max_degree` (C++ `graph_degree`; default 32) |

## Python

Expand Down Expand Up @@ -101,7 +101,7 @@ Set Python keyword arguments or fields of the corresponding C++ parameter type:
| `min_points_per_centroid` | `39` | Warn below this training-points-per-centroid ratio when verbose. |
| `max_points_per_centroid` | `0` | When positive, train on a random sample above `k * max_points_per_centroid` vectors; `0` trains on all vectors. See [sampling](#training-set-sampling). |
| `verbose` | `false` | Print training progress and warnings. |
| `final_assignment` | `Approximate` | Use the selected method for final labels, or `Exact` for nearest-centroid labels. |
| `final_assignment` | `'approximate'` (C++ `Approximate`) | Use the selected method for final labels, or `'exact'` (C++ `Exact`) for nearest-centroid labels. |

`num_threads` sets an upper limit, not a fixed worker count for every stage.
QGKMeans may use fewer workers to build small centroid graphs. That additional
Expand Down Expand Up @@ -164,18 +164,21 @@ encodes new vectors around it.

Each iteration compares every training point with every centroid. The batch size of 32
is not a cluster-count limit. This method uses one-bit point codes throughout;
it has no graph parameters or `quantization_bits` setting.
it has no graph parameters or `nbits` (C++ `quantization_bits`) setting.

### QGKMeans

QGKMeans builds a SymphonyQG graph over the centroids and uses previous
assignments as search hints. Its additional parameters are:
assignments as search hints. Its additional parameters are below, under their Python
names since 0.8.5. C++ and Python before 0.8.5 name the first three
`quantization_bits` (with `0` for raw storage), `graph_degree` and `ef_build`; in
Python those names still work, with a `DeprecationWarning`, until 0.9.

| Parameter | Default | Meaning |
| --- | --- | --- |
| `quantization_bits` | `0` | Graph centroid storage: raw, or `4`/`8` bits. |
| `graph_degree` | `32` | A positive multiple of 32, strictly smaller than `k`. |
| `ef_build`, `ef_search` | `240`, `16` | Positive graph construction and search window sizes. |
| `nbits` | `32` | Graph centroid storage: `32` for raw vectors, or `4`/`8` bits. |
| `max_degree` | `32` | A positive multiple of 32, strictly smaller than `k`. |
| `ef_construction`, `ef_search` | `240`, `16` | Positive graph construction and search window sizes. |
| `graph_build_iterations` | `1` | PiPNN initialization followed by one refinement; values ≥2 request that many graph passes, ending in refinement. Independent of `niter`. |

The seed also controls fallback neighbors; PiPNN uses fixed internal seeds.
Expand All @@ -194,9 +197,8 @@ their sum (WCSS); spherical mode sums `1 - inner_product`. `obj` and
`iteration_stats` record objectives before each centroid update; Python
`train()` returns the last such objective.

`FinalAssignmentMode.Approximate` (default) uses the selected class's assignment
algorithm. The legacy name `FinalAssignmentMode.SymphonyQG` remains an alias for
`Approximate`. Labels need not identify the exact nearest centroids, but reported
`final_assignment='approximate'` (default) uses the selected class's assignment
algorithm. Labels need not identify the exact nearest centroids, but reported
distances and WCSS remain exact for those labels. Without sampling, quantized
QGKMeans final assignment retains a point's last-iteration label when it is
closer. After sampling, most points have no such label, so every point uses the
Expand All @@ -205,12 +207,17 @@ same graph search. Approximate training objectives need not decrease monotonical
To require exact nearest-centroid **final** assignments with either class:

```python
from rabitqlib import FinalAssignmentMode, RaBitQKMeans
from rabitqlib import RaBitQKMeans

kmeans = RaBitQKMeans(d, 16, final_assignment=FinalAssignmentMode.Exact)
kmeans = RaBitQKMeans(d, 16, final_assignment="exact")
kmeans.train(x)
```

Python takes the strings `'approximate'` and `'exact'` since 0.8.5. The
`FinalAssignmentMode` members `Approximate`, `Exact` and the legacy alias `SymphonyQG`
are still accepted until 0.9, and `cp.final_assignment` reads back as a member
until then; importing `FinalAssignmentMode` raises a `DeprecationWarning`.

In C++, set `parameters.final_assignment` to
`rabitqlib::rabitqkmeans::FinalAssignmentMode::Exact` or
`rabitqlib::qgkmeans::FinalAssignmentMode::Exact`; both names refer to the same
Expand Down Expand Up @@ -240,7 +247,7 @@ C++ callers that change `centroids` or graph parameters cause one rebuild on
the next call. Each call still validates the `k * d` centroid coordinates.

For the training vectors, `assign` reproduces `assignments` and `distances`
with `FinalAssignmentMode.Exact`, for RaBitQKMeans, and whenever training
with exact final assignment, for RaBitQKMeans, and whenever training
sampled the input, because the sampled final pass is the same assignment.
Unsampled approximate QGKMeans training also uses previous labels as graph
search hints, so its final labels can differ.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cpp_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ The core example is built as the `core_example` CMake target. For the GIST bench

The [core quantization v1 API](rabitq/core_api.md) has a C++ source-compatibility contract.
Other C++ APIs may evolve, and no cross-version C++ binary ABI is promised.
Pin the `v0.8.4` release and include RaBitQ-Library as a Git submodule:
Pin the `v0.8.5` release and include RaBitQ-Library as a Git submodule:

```bash
git submodule add https://github.com/VectorDB-NTU/RaBitQ-Library.git third_party/rabitqlib
git submodule update --init --recursive
git -C third_party/rabitqlib checkout v0.8.4
git -C third_party/rabitqlib checkout v0.8.5
git add third_party/rabitqlib
```

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ estimation into your own <span class="nowrap">C++</span> search engine.</p>
</div>

```bash
python -m pip install "rabitqlib>=0.8.4"
python -m pip install "rabitqlib>=0.8.5"
```

[Installation and supported platforms](installation.md) ·
Expand Down Expand Up @@ -112,5 +112,5 @@ on your own dataset when choosing an index.
## Explore further

- [Algorithm overview](rabitq/rabitq.md) for the rotation, encoding, and scoring workflow.
- [RaBitQ Library 0.8.4 release notes](releases/0.8.4.md) for the latest changes and upgrade guidance.
- [RaBitQ Library 0.8.5 release notes](releases/0.8.5.md) for the latest changes and upgrade guidance.
- [Papers and citations](papers.md) for the original RaBitQ method, its multi-bit extension, and SymphonyQG.
Loading
Loading