From 629f92d8867773ca3cdb6577bd598cfa43199450 Mon Sep 17 00:00:00 2001 From: gouyt13clear Date: Thu, 19 Nov 2026 21:51:03 +0800 Subject: [PATCH 1/2] docs: describe untrained HNSW files without a release number An HNSW-RaBitQ file saved before training loads untrained. Comments, docstrings, the stub, hnsw.md and the release notes named 0.7 or 0.8 for it inconsistently, and some said "trained or loaded" where such a loaded index is not trained. They now say "a file saved before training" or "an index loaded from an untrained file", and HnswIndex.load and search say what they return and require. The release notes also say "all three" samples, give the RuntimeError type, and move the CMake find_package bullet to the end of the C++ section, so the migration table follows the new-class bullets again. --- docs/docs/index/hnsw.md | 9 +++++---- docs/docs/releases/unreleased.md | 7 ++++--- include/rabitqlib/index/hnsw_index.hpp | 10 +++++----- python_bindings/__init__.pyi | 17 +++++++++-------- python_bindings/hnsw_bindings.cpp | 13 +++++++------ src/index/hnsw_index.cpp | 4 ++-- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/docs/docs/index/hnsw.md b/docs/docs/index/hnsw.md index 4fd2543f..3b489230 100644 --- a/docs/docs/index/hnsw.md +++ b/docs/docs/index/hnsw.md @@ -182,8 +182,9 @@ See the shared [concurrency contract](usage.md#threading-and-file-paths). ## Updating an index -A trained or loaded index supports `add()`, `reserve()` and `remove()` without -the original data. `save` always writes index format 2; see +A trained index supports `add()`, `reserve()` and `remove()` without the original +data. Every loaded index is trained, except one loaded from a file saved before +training (see below). `save` always writes index format 2; see [persistence](#persistence). ```c++ @@ -305,8 +306,8 @@ IDs, so do not open such a file with them. `save` writes [index format 2](https://github.com/VectorDB-NTU/RaBitQ-Library/blob/main/docs/formats.md#index-format-2), which also records the construction seed, so `seed` survives a reload. Releases up to 0.8 cannot read these files; every earlier file still loads, without a recorded seed, and saving it writes format 2. -The C++ API of releases before 0.8 could also save an index before training it. Such a -file from 0.7 loads untrained, with `num_clusters` 16; without a recorded seed its first `add` +The C++ API of earlier releases could also save an index before training it. Such a +file loads untrained, with `num_clusters` 16; without a recorded seed its first `add` cannot train it, so call `train` or `set_centroids` before `add`. New HNSW-RaBitQ indexes pad dimensions to multiples of 32 for all supported bit widths. diff --git a/docs/docs/releases/unreleased.md b/docs/docs/releases/unreleased.md index 556b9008..fee04db7 100644 --- a/docs/docs/releases/unreleased.md +++ b/docs/docs/releases/unreleased.md @@ -55,7 +55,7 @@ - Loading a format-2 file keeps the `seed` of every index, and `ef_construction` and `init` of SymphonyQG. They were `None` after `load`, and still are for files from releases up to 0.8. - With a recorded seed, `cp.seed` after `load` follows it as for a new index; for an HNSW-RaBitQ file whose seed exceeds 32 bits, which only C++ can write, it is the low 32 bits. It was the k-means default. -- An HNSW-RaBitQ file that the 0.7 C++ API saved before training loads untrained, with `num_clusters` 16. Without a recorded seed its first `add` cannot train it, so `add`, `search`, `remove` and `save` raise `HnswIndex loaded from an untrained file must be trained before add; call train or set_centroids` (naming the operation) until `train` or `set_centroids` runs. +- An HNSW-RaBitQ file saved before training, which the C++ API of earlier releases allowed, loads untrained, with `num_clusters` 16. Without a recorded seed its first `add` cannot train it, so `add`, `search`, `remove` and `save` raise `RuntimeError: HnswIndex loaded from an untrained file must be trained before add; call train or set_centroids` (naming the operation) until `train` or `set_centroids` runs. - A new exception, `rabitqlib.FormatError`, subclasses both `ValueError` and `RuntimeError`: - Every index `load` raises it for a truncated, corrupt, mismatched or unsupported file, in format 2 and in every earlier layout. These were `RuntimeError`, which still catches them. A file that cannot be opened still raises a plain `RuntimeError`. - `quant.FormatError` is now the same class. It was a subclass of `ValueError` only, which still catches it. @@ -88,7 +88,6 @@ - `search` takes a `GraphSearchOptions` struct. Without an `ef_search` it uses `max(k, 64)`, a smaller value is raised to `k`, and an explicit 0 throws; `symqg::QuantizedGraph` rejects an `ef_search` below `k`. - `seed()`, `ef_construction()` and `init()` have no value for a file of a release up to 0.8. - `IvfIndex`, `HnswIndex` and `SymqgIndex` are the supported and documented C++ index API from 0.9. `ivf::IVF`, `hnsw::HierarchicalNSW`, `symqg::QuantizedGraph` and `symqg::QGBuilder` stay installed at their paths and keep their interfaces apart from the changes listed below, but they leave the documentation and carry no compatibility promise. -- The installed CMake package satisfies `find_package(rabitqlib X.Y[.Z])` only when the major and minor versions match: `find_package(rabitqlib 0.8)` no longer finds 0.9, which `SameMajorVersion` compatibility allowed, and a version range must stay within one minor release, such as `0.9...<0.10`. Before 1.0 a minor release may break the API. Move to the new classes as follows: @@ -105,7 +104,7 @@ Move to the new classes as follows: Four differences are not renames: `HnswIndex::add` uses every CPU unless `num_threads` is set; `HnswIndex::search` writes all `k` slots, padding with `kNoId` and `+inf`, where `HierarchicalNSW::search` returns only the pairs found; a seed is drawn unless given, where `HierarchicalNSW` defaults to 100; and default thread counts are capped by `OMP_NUM_THREADS`. The new classes do not offer the matrix rotator, rebuilding with `IVF::construct`, shrinking with `HierarchicalNSW::resize`, `HierarchicalNSW::cluster_id_of`, `QuantizedGraph::search_with_scratch` with its warm-start hint, `QGBuilder`'s multi-pass `build(n)`, `reset`, `refine`, `avg_degree`, `check_dup` and `cache_vectors`, or `padded_dim()`; use the existing classes for them. -- The C++ examples in `sample/cpp` and the IVF `add` hot-path benchmark use the new classes. `symqg_indexing` takes `nbits` (32 for raw vectors, 4 or 8, default 32) and still reads 0 as raw vectors; it no longer prints stage times or the average degree. Its optional thread count 0 selects every available CPU. The default thread counts of `symqg_indexing` and `ivf_rabitq_indexing` are now capped by `OMP_NUM_THREADS`, which they ignored. `ivf_rabitq_indexing`, `hnsw_rabitq_indexing` and `symqg_indexing` accept `cosine` as the metric and reject unknown metric names; both used to build an L2 index silently. +- The C++ examples in `sample/cpp` and the IVF `add` hot-path benchmark use the new classes. `symqg_indexing` takes `nbits` (32 for raw vectors, 4 or 8, default 32) and still reads 0 as raw vectors; it no longer prints stage times or the average degree. Its optional thread count 0 selects every available CPU. The default thread counts of `symqg_indexing` and `ivf_rabitq_indexing` are now capped by `OMP_NUM_THREADS`, which they ignored. `ivf_rabitq_indexing`, `hnsw_rabitq_indexing` and `symqg_indexing` accept `cosine` as the metric and reject unknown metric names; all three used to build an L2 index silently. - `qgkmeans::QGKMeansParameters` uses the Python names (#233): `graph_degree` becomes `max_degree`, `ef_build` becomes `ef_construction`, and `quantization_bits` (0, 4 or 8) becomes `nbits` (32, 4 or 8, with 32 for raw float32). The fields keep their order and types. An `nbits` of 0 is rejected, so code that initialized the field positionally with 0 must pass 32. `QGAssigner` keeps its constructor, including `quantization_bits` with 0 for raw storage. - Messages follow the names: `QGKMeans nbits must be 4, 8, or 32`, `QGKMeans max_degree must be a positive multiple of 32`, `QGKMeans requires more centroids than max_degree` and `QGKMeans ef_construction and ef_search must be positive`. @@ -127,3 +126,5 @@ Four differences are not renames: `HnswIndex::add` uses every CPU unless `num_th - The vendored hnswlib adds `saveIndex(std::ostream&)` and `loadIndex(std::istream&, size_t bytes, ...)`; the path overloads are unchanged. - `rabitqlib::ceil_log2` in `rabitqlib/utils/tools.hpp` shifts a `size_t`, so an input of 2^32 or more is no longer undefined on 64-bit Windows, where `unsigned long` has 32 bits (#247). The library does not call it. + +- The installed CMake package satisfies `find_package(rabitqlib X.Y[.Z])` only when the major and minor versions match: `find_package(rabitqlib 0.8)` no longer finds 0.9, which `SameMajorVersion` compatibility allowed, and a version range must stay within one minor release, such as `0.9...<0.10`. Before 1.0 a minor release may break the API. diff --git a/include/rabitqlib/index/hnsw_index.hpp b/include/rabitqlib/index/hnsw_index.hpp index 22bf22ce..83c5255b 100644 --- a/include/rabitqlib/index/hnsw_index.hpp +++ b/include/rabitqlib/index/hnsw_index.hpp @@ -61,9 +61,9 @@ class HnswIndex { HnswIndex& operator=(const HnswIndex&) = delete; ~HnswIndex(); - // Load an index saved by any release. An empty, untrained file saved by 0.7 loads - // untrained, with 16 clusters to train; without a recorded seed, it needs train or - // set_centroids before add. + // Load an index saved by any release. A file saved before training loads untrained, + // with 16 clusters to train; without a recorded seed, it needs train or set_centroids + // before add. static HnswIndex load(const char* filename); // Requires at least one stored point. Releases up to 0.8 cannot read the file. @@ -114,8 +114,8 @@ class HnswIndex { * existing centroids, which do not move. Capacity grows to fit the points, at least * doubling, after the points and cluster IDs are checked. A failure while linking may * leave part of the batch in the index, which stays safe to search, save and destroy. - * An index loaded from an empty, untrained file saved before 0.8 has no seed, so - * add does not train it; call train or set_centroids first. + * An index loaded from a file saved before training has no seed, so add does not + * train it; call train or set_centroids first. * * @param data New points (num_points * dim) * @param num_points Number of new points diff --git a/python_bindings/__init__.pyi b/python_bindings/__init__.pyi index 370f424e..36b34e53 100644 --- a/python_bindings/__init__.pyi +++ b/python_bindings/__init__.pyi @@ -414,8 +414,8 @@ class HnswIndex: ----- The first add trains an untrained index on the added vectors. Call train on a sample, or set_centroids, first to choose the training data or the - centroids. Loaded indexes are trained, except empty files saved untrained - by 0.7. Capacity grows automatically + centroids. Loaded indexes are trained, except one loaded from a file saved + before training. Capacity grows automatically on add; reserve can preallocate it. Concurrent reads are supported; an overlapping mutation raises RuntimeError. Data, centroids and queries must be finite float32 values within the index @@ -474,8 +474,8 @@ class HnswIndex: ----- The first add trains an untrained index on the added vectors. Call train on a sample, or set_centroids, first to choose the training data or the - centroids. Loaded indexes are trained, except empty files saved untrained - by 0.7. Capacity grows automatically + centroids. Loaded indexes are trained, except one loaded from a file saved + before training. Capacity grows automatically on add; reserve can preallocate it. Concurrent reads are supported; an overlapping mutation raises RuntimeError. Data, centroids and queries must be finite float32 values within the index @@ -615,8 +615,9 @@ class HnswIndex: num_clusters then reports the row count. An empty first add raises RuntimeError. With num_threads None, training uses cp.num_threads. Passing cluster_ids to an untrained index raises - RuntimeError, as does add on an untrained index loaded from a 0.7 file; - call train first. If the call fails, the index stays untrained and empty. The first + RuntimeError, as does add on an index loaded from an untrained file; + call train or set_centroids first. If the call fails, the index stays untrained + and empty. The first add into an empty index links vectors with their exact coordinates; later adds link through the stored codes, so add most vectors in the first call. Capacity grows geometrically when needed. Removed IDs are not reused. @@ -675,7 +676,7 @@ class HnswIndex: Notes ----- - Requires a trained or loaded index. Returns (ids, distances), in that + Requires a trained index. Returns (ids, distances), in that order. Missing neighbors have ID -1 and distance inf; test np.isfinite(distances) to find them. Array shapes and value ranges are checked at runtime, not by static type checkers. @@ -709,7 +710,7 @@ class HnswIndex: Returns ------- index : HnswIndex - A trained index ready for search. + The loaded index, trained unless the file was saved before training. """ def reserve(self, num_points: SupportsIndex) -> None: diff --git a/python_bindings/hnsw_bindings.cpp b/python_bindings/hnsw_bindings.cpp index 62701cf6..543b1a89 100644 --- a/python_bindings/hnsw_bindings.cpp +++ b/python_bindings/hnsw_bindings.cpp @@ -298,8 +298,8 @@ Notes ----- The first add trains an untrained index on the added vectors. Call train on a sample, or set_centroids, first to choose the training data or the -centroids. Loaded indexes are trained, except empty files saved untrained -by 0.7. Capacity grows automatically +centroids. Loaded indexes are trained, except one loaded from a file saved +before training. Capacity grows automatically on add; reserve can preallocate it. Concurrent reads are supported; an overlapping mutation raises RuntimeError. Data, centroids and queries must be finite float32 values within the index @@ -348,8 +348,9 @@ train(data) does; with fewer rows it trains one centroid per row, and num_clusters then reports the row count. An empty first add raises RuntimeError. With num_threads None, training uses cp.num_threads. Passing cluster_ids to an untrained index raises -RuntimeError, as does add on an untrained index loaded from a 0.7 file; -call train first. If the call fails, the index stays untrained and empty. The first +RuntimeError, as does add on an index loaded from an untrained file; +call train or set_centroids first. If the call fails, the index stays untrained +and empty. The first add into an empty index links vectors with their exact coordinates; later adds link through the stored codes, so add most vectors in the first call. Capacity grows geometrically when needed. Removed IDs are not reused.)doc"; @@ -457,7 +458,7 @@ distances : ndarray of float32, shape (n_queries, k) Notes ----- -Requires a trained or loaded index. Returns (ids, distances), in that +Requires a trained index. Returns (ids, distances), in that order. Missing neighbors have ID -1 and distance inf; test np.isfinite(distances) to find them. Array shapes and value ranges are checked at runtime, not by static type checkers.)doc" @@ -543,7 +544,7 @@ path : str, bytes, bytearray, or os.PathLike Returns ------- index : HnswIndex - A trained index ready for search.)doc" + The loaded index, trained unless the file was saved before training.)doc" ) .def( "__repr__", diff --git a/src/index/hnsw_index.cpp b/src/index/hnsw_index.cpp index 3a8570e8..16818dfd 100644 --- a/src/index/hnsw_index.cpp +++ b/src/index/hnsw_index.cpp @@ -24,7 +24,7 @@ namespace rabitqlib { namespace { using rabitqkmeans::RaBitQKMeansParameters; -// What an empty, untrained file saved before 0.8 trains, as a new index does by default. +// What a file saved before training trains, as a new index does by default. constexpr size_t kDefaultNumClusters = 16; // Grow the capacity to fit num_points more points, at least doubling it. The points are @@ -252,7 +252,7 @@ void HnswIndex::check_trained(const char* operation) const { if (index_->is_trained()) { return; } - // Only an empty file saved before 0.8 loads untrained, and it lacks the seed that + // Only a file saved before training loads untrained, and it lacks the seed that // lets the first add train. if (!index_->seed().has_value()) { throw std::logic_error( From e3364af1fab3b0ba30a779933fc7b8be7659aa89 Mon Sep 17 00:00:00 2001 From: gouyt13clear Date: Thu, 19 Nov 2026 21:51:03 +0800 Subject: [PATCH 2/2] ci: list release:breaking PRs first in generated release notes The release categories had no place for breaking changes, so breaking PRs appeared under Added. A manual release:breaking label now maps to a first category, Breaking changes; the title classifier does not manage it, so it stays on the PR alongside the automatic category. --- .github/release.yml | 4 ++++ docs/maintaining.md | 3 +++ 2 files changed, 7 insertions(+) diff --git a/.github/release.yml b/.github/release.yml index 98db5107..a393bb93 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -5,6 +5,10 @@ changelog: - invalid categories: + - title: Breaking changes + labels: + - release:breaking + - title: Added labels: - release:added diff --git a/docs/maintaining.md b/docs/maintaining.md index ff9dc959..38aa468f 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -229,6 +229,9 @@ Use lowercase prefixes, a space after the colon and a nonempty summary, for exam `fix(ivf): update only affected clusters`. A scope and a `!` marker before the colon are optional. The marker does not change the category or authorize a breaking change; compatibility decisions still follow the project rules. +Add the manual label `release:breaking` to a merged breaking change: its category, +Breaking changes, comes first, so the PR is listed there instead of under its +automatic category. For dependency-only changes, use `deps:` rather than `chore(deps):`. The workflow creates its repository labels as needed and updates only the