Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
c1d3707
docs(formats): draft index file format 2
gouyt13 Nov 6, 2026
04e8192
feat(index): add the format-2 index container
gouyt13 Nov 6, 2026
27f5954
feat(ivf): save and load index format 2
gouyt13 Nov 7, 2026
ad4317d
fix(ivf): migrate the load benchmark and a Windows test path
gouyt13 Nov 7, 2026
8c6951c
test(ivf): build both HNSW routing graphs with one thread
gouyt13 Nov 7, 2026
5b7dd4f
test(persistence): freeze v0.8.3 HNSW-RaBitQ and SymphonyQG fixtures
gouyt13 Nov 7, 2026
c0414e4
feat(index): save and load HNSW-RaBitQ and SymphonyQG in index format 2
gouyt13 Nov 7, 2026
d2b25a1
test(symqg): capture the point count for MSVC
gouyt13 Nov 7, 2026
cdc2dbd
feat(index): raise rabitqlib.FormatError for rejected index files
gouyt13 Nov 7, 2026
da1760c
feat(python): use int64 point IDs with -1 for missing results
gouyt13 Nov 7, 2026
5bf7b1f
fix(index): raise FormatError for the remaining rejected headers
gouyt13 Nov 7, 2026
75c81d4
Merge branch 'main' into feat/format2-container
gouyt13 Nov 8, 2026
61550c2
feat(index): add the cosine metric
gouyt13 Nov 9, 2026
f447910
ci: run the Python workflow for pull requests into dev/0.9
gouyt13 Nov 13, 2026
8894723
Merge branch 'dev/0.9' into feat/format2-container
gouyt13 Nov 13, 2026
6f975a2
Merge pull request #222 from VectorDB-NTU/feat/format2-container
gouyt13 Nov 13, 2026
cb62913
Merge branch 'main' into dev/0.9
gouyt13 Nov 14, 2026
df00663
Merge pull request #238 from VectorDB-NTU/sync/main-into-dev-0.9
gouyt13 Nov 14, 2026
6174cc9
feat(clustering)!: name the QGKMeansParameters fields like the index …
gouyt13 Nov 14, 2026
65da0d4
feat(python)!: remove the 0.7 and 0.8 forms and expose the 0.9 names …
gouyt13 Nov 14, 2026
bcde9eb
test: move the Python tests to the 0.9 forms and check that the remov…
gouyt13 Nov 14, 2026
4d90803
docs(python): name the seed in the HnswIndex.add note on reproducible…
gouyt13 Nov 14, 2026
3685e81
Merge pull request #239 from VectorDB-NTU/feat/python-09-api
gouyt13 Nov 14, 2026
81d96fe
feat(index): add rabitqlib::IvfIndex, the supported C++ IVF API
gouyt13 Nov 15, 2026
9947bbe
refactor(python): build the IvfIndex binding on rabitqlib::IvfIndex
gouyt13 Nov 15, 2026
d9c0570
Merge pull request #240 from VectorDB-NTU/feat/ivf-index
gouyt13 Nov 15, 2026
706bdb1
docs(ivf): say that Python add returns int64 IDs
gouyt13 Nov 15, 2026
8edc630
feat(python)!: accept only "ip" as the inner-product metric name
gouyt13 Nov 15, 2026
aec9df4
Merge pull request #241 from VectorDB-NTU/feat/drop-innerproduct
gouyt13 Nov 15, 2026
ec842cf
fix(python): stop pickle protocols 0 and 1 from aborting the interpreter
gouyt13 Nov 15, 2026
afc0d0e
Merge pull request #242 from VectorDB-NTU/fix/pickle-protocol
gouyt13 Nov 15, 2026
cdb5139
feat(index): add rabitqlib::HnswIndex, the supported C++ HNSW API
gouyt13 Nov 16, 2026
dfdfc56
refactor(python): build the HnswIndex binding on rabitqlib::HnswIndex
gouyt13 Nov 16, 2026
897c41b
Merge pull request #243 from VectorDB-NTU/feat/hnsw-index
gouyt13 Nov 16, 2026
574f100
feat(index): add rabitqlib::SymqgIndex, the supported C++ SymphonyQG API
gouyt13 Nov 16, 2026
da56f6d
refactor(python): build the SymqgIndex binding on rabitqlib::SymqgIndex
gouyt13 Nov 16, 2026
2ea3b22
Merge pull request #244 from VectorDB-NTU/feat/symqg-index
gouyt13 Nov 16, 2026
fba392a
refactor(samples): build the C++ examples on the index classes
gouyt13 Nov 16, 2026
68af377
docs: document the C++ index classes and the move from the 0.8 classes
gouyt13 Nov 16, 2026
16e8f01
Merge pull request #245 from VectorDB-NTU/feat/index-api-docs
gouyt13 Nov 16, 2026
9182190
fix(utils): use a size_t shift operand in ceil_log2
gouyt13 Nov 18, 2026
e19e749
Merge pull request #247 from VectorDB-NTU/fix/ceil-log2-shift
gouyt13 Nov 18, 2026
3789633
fix(clustering): check k-means coordinates against the index bound
gouyt13 Nov 19, 2026
5898c08
Merge pull request #249 from VectorDB-NTU/fix/kmeans-coordinate-bound
gouyt13 Nov 19, 2026
4840663
fix(samples): accept cosine and reject unknown metrics in the indexin…
gouyt13 Nov 19, 2026
85e1388
docs: correct 0.9 pages for cosine, format 2 and search limits
gouyt13 Nov 19, 2026
6f655bc
Merge pull request #250 from VectorDB-NTU/fix/docs-samples-09
gouyt13 Nov 19, 2026
e2d2f7a
docs: cover the remaining 0.9 breaking changes in the migration guide
gouyt13 Nov 19, 2026
fe3e4eb
Merge pull request #251 from VectorDB-NTU/docs/migration-09-gaps
gouyt13 Nov 19, 2026
a3d8b1a
Merge branch 'main' into dev/0.9
gouyt13 Nov 19, 2026
927185a
Merge pull request #252 from VectorDB-NTU/sync/main-into-dev-0.9
gouyt13 Nov 19, 2026
bc2cd25
build(cmake): accept only the same minor version in the package config
gouyt13 Nov 19, 2026
dd4d90f
Merge pull request #253 from VectorDB-NTU/build/cmake-same-minor
gouyt13 Nov 19, 2026
c626bc3
docs(format2): freeze the format-2 specification for 0.9
gouyt13 Nov 19, 2026
7fd4015
fix(format2): escape the stored writer version in error messages
gouyt13 Nov 19, 2026
c456f31
Merge pull request #254 from VectorDB-NTU/fix/format2-spec-freeze
gouyt13 Nov 19, 2026
c5544c4
fix(hnsw): explain how to train an index loaded from an untrained file
gouyt13 Nov 19, 2026
1e24c6b
Merge pull request #255 from VectorDB-NTU/test/hnsw-empty-legacy-fixture
gouyt13 Nov 19, 2026
38664c7
fix(clustering): reject the cosine metric in QGAssigner
gouyt13 Nov 19, 2026
7be124f
Merge pull request #256 from VectorDB-NTU/fix/qgassigner-cosine
gouyt13 Nov 19, 2026
629f92d
docs: describe untrained HNSW files without a release number
gouyt13 Nov 19, 2026
e3364af
ci: list release:breaking PRs first in generated release notes
gouyt13 Nov 19, 2026
848e097
Merge pull request #257 from VectorDB-NTU/docs/hnsw-untrained-wording
gouyt13 Nov 19, 2026
3476830
fix(rotator): make MatrixRotator Haar distributed
gouyt13 Nov 20, 2026
5f27939
Merge pull request #258 from VectorDB-NTU/fix/matrix-rotator-haar
gouyt13 Nov 20, 2026
3184948
fix(index): scale given centroids of cosine indexes to unit length
gouyt13 Nov 20, 2026
9f07dd5
Merge pull request #260 from VectorDB-NTU/fix/cosine-centroids
gouyt13 Nov 20, 2026
5992353
fix(utils)!: remove the evaluation helpers from tools.hpp
gouyt13 Nov 21, 2026
0aac0d8
docs(releases): link the removal of the evaluation helpers to #262
gouyt13 Nov 21, 2026
97eb05e
Merge pull request #262 from VectorDB-NTU/fix/remove-eval-helpers
gouyt13 Nov 21, 2026
9c7c4a5
chore(release): prepare v0.9.0
gouyt13 Nov 20, 2026
0c38beb
test: freeze the index format 2 fixtures of v0.9.0
gouyt13 Nov 20, 2026
f6ff6d5
docs: describe the txtai adapter that works with 0.9
gouyt13 Nov 20, 2026
04941c7
docs: fix 0.9 statements, examples and moved links found by a docs check
gouyt13 Nov 22, 2026
a4d266f
docs(readme): link the license badge to the LICENSE file on GitHub
gouyt13 Nov 22, 2026
4ae1cc5
docs: name txtai 9.15.0 as the first release that works with 0.9
gouyt13 Nov 23, 2026
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
4 changes: 3 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ CheckOptions:
readability-identifier-naming.ProtectedMemberCase: lower_case
readability-identifier-naming.ProtectedMemberSuffix: '_'
readability-identifier-naming.PublicMemberCase: lower_case
# HnswOptions::M, the same HNSW graph-degree setting.
readability-identifier-naming.PublicMemberIgnoredRegexp: '^M$'
# Functions, types, namespaces, constants and macros follow AGENTS.md. The
# ignored names are retained public API or names the standard library requires.
readability-identifier-naming.FunctionCase: lower_case
Expand All @@ -65,7 +67,7 @@ CheckOptions:
readability-identifier-naming.StructIgnoredRegexp: '^rebind$'
readability-identifier-naming.EnumCase: CamelCase
readability-identifier-naming.EnumConstantCase: CamelCase
readability-identifier-naming.EnumConstantIgnoredRegexp: '^(METRIC_L2|METRIC_IP|RECONSTRUCTION|UNBIASED_ESTIMATION|PLAIN)$'
readability-identifier-naming.EnumConstantIgnoredRegexp: '^(METRIC_L2|METRIC_IP|METRIC_COSINE|RECONSTRUCTION|UNBIASED_ESTIMATION|PLAIN)$'
readability-identifier-naming.TypeAliasCase: CamelCase
readability-identifier-naming.TypeAliasIgnoredRegexp: '^(value_type|pointer|reference|difference_type|iterator_category|is_always_equal|other|maxheap|minheap|ex_ipfunc)$'
readability-identifier-naming.TypedefCase: CamelCase
Expand Down
4 changes: 4 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ changelog:
- invalid

categories:
- title: Breaking changes
labels:
- release:breaking

- title: Added
labels:
- release:added
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ["main", "master"]
pull_request:
branches: ["main", "master"]
branches: ["main", "master", "dev/0.9"]

concurrency:
group: ${{ github.event.pull_request.number || github.sha }}-${{ github.workflow }}
Expand Down
14 changes: 12 additions & 2 deletions 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.5 LANGUAGES CXX)
project(RaBitQLib VERSION 0.9.0 LANGUAGES CXX)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
Expand Down Expand Up @@ -84,6 +84,7 @@ endfunction()

set(RABITQ_CORE_SOURCES
src/core/api.cpp
src/core/blob.cpp
src/core/fast_scale_table.cpp
src/core/provisional.cpp
src/utils/cpu_features.cpp
Expand Down Expand Up @@ -247,12 +248,16 @@ if(RABITQ_BUILD_FASTSCAN)
endif()
if(RABITQ_BUILD_INDEX)
add_library(rabitq_index STATIC
src/index/format2.cpp
src/index/hnsw.cpp
src/index/hnsw_index.cpp
src/index/ivf.cpp
src/index/ivf_index.cpp
src/index/ivf_initializer.cpp
src/index/ivf_search.cpp
src/index/qg.cpp
src/index/qg_builder.cpp
src/index/symqg_index.cpp
src/index/pipnn.cpp
src/index/hnsw_dispatch.cpp
src/index/hnsw_search_generic.cpp
Expand All @@ -261,6 +266,10 @@ if(RABITQ_BUILD_INDEX)
)
add_library(rabitqlib::index ALIAS rabitq_index)
target_link_libraries(rabitq_index PUBLIC rabitq_fastscan)
# Index files record the library version that wrote them.
target_compile_definitions(rabitq_index PRIVATE
RABITQ_LIBRARY_VERSION="${PROJECT_VERSION}"
)
set_target_properties(rabitq_index PROPERTIES
EXPORT_NAME index
POSITION_INDEPENDENT_CODE ON
Expand Down Expand Up @@ -317,7 +326,8 @@ configure_package_config_file(
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/rabitqlibConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion
# Before 1.0 a minor release may break the API.
COMPATIBILITY SameMinorVersion
)
install(EXPORT rabitqlibTargets
FILE rabitqlibTargets.cmake
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="https://pypi.org/project/rabitqlib/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rabitqlib.svg?cacheSeconds=300"></a>
<a href="https://pypi.org/project/rabitqlib/"><img alt="Python versions" src="https://img.shields.io/badge/python-3.11--3.14-3776AB.svg?logo=python&amp;logoColor=white"></a>
<a href="https://vectordb-ntu.github.io/RaBitQ-Library/"><img alt="Documentation" src="https://github.com/VectorDB-NTU/RaBitQ-Library/actions/workflows/docs.yml/badge.svg"></a>
<a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-Apache--2.0-blue.svg"></a>
<a href="https://github.com/VectorDB-NTU/RaBitQ-Library/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/license-Apache--2.0-blue.svg"></a>
</p>

</div>
Expand All @@ -27,28 +27,28 @@ approximate nearest-neighbor search. See the [research papers](https://vectordb-

## News

- **v0.9.0:** removes the Python forms 0.8 deprecated, saves index format 2, and adds
the cosine metric, `int64` IDs and C++ index classes that match the Python API
([notes](https://vectordb-ntu.github.io/RaBitQ-Library/releases/0.9.0/)).
- **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/)).

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

## Vector indexes

Use the included indexes when you want construction, search, and save/load in one
library. All three support L2 and inner product; normalize vectors for cosine
search. Their structures, storage costs, and search parameters offer different
library. All three support L2, inner product and cosine, which normalizes vectors
for you. Their structures, storage costs, and search parameters offer different
QPS–recall tradeoffs.

| Index | Search approach | Storage and updates |
| --- | --- | --- |
| [IVF-RaBitQ](https://vectordb-ntu.github.io/RaBitQ-Library/index/ivf/) | Partitioned search with batch scoring. | 1–9-bit codes or raw-vector reranking; add/remove. |
| [HNSW-RaBitQ](https://vectordb-ntu.github.io/RaBitQ-Library/index/hnsw/) | Graph traversal over quantized vectors. | 1–9-bit codes plus graph edges; add/remove and resize. |
| [HNSW-RaBitQ](https://vectordb-ntu.github.io/RaBitQ-Library/index/hnsw/) | Graph traversal over quantized vectors. | 1–9-bit codes plus graph edges; add/remove and reserve. |
| [SymphonyQG](https://vectordb-ntu.github.io/RaBitQ-Library/index/qg/) | Graph search with batched distance estimation. | Raw or 4/8-bit storage; updates require rebuilding. |

[Native clustering methods](https://vectordb-ntu.github.io/RaBitQ-Library/clustering/) prepare centroids and
Expand All @@ -62,7 +62,7 @@ settings, and limitations.
### Python

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

Wheels support CPython 3.11–3.14 on Linux x86-64/ARM64, Windows x86-64,
Expand Down Expand Up @@ -93,8 +93,8 @@ distance, with smaller values first. Without `nprobe`, search probes
Quantization remains approximate even when all clusters are probed.
The [complete quick start](https://vectordb-ntu.github.io/RaBitQ-Library/quick_start/) explains result handling,
measures recall while varying `nprobe`, and shows save/load. Code written for
0.7 still runs in 0.8 with deprecation warnings; see the
[migration guide](https://vectordb-ntu.github.io/RaBitQ-Library/python_migration/).
0.8 may need changes for 0.9; see the
[migration guide](https://vectordb-ntu.github.io/RaBitQ-Library/python_migration/#from-08-to-09).

For other indexes, see the [HNSW-RaBitQ](https://vectordb-ntu.github.io/RaBitQ-Library/index/hnsw/#minimal-workflow) and
[SymphonyQG](https://vectordb-ntu.github.io/RaBitQ-Library/index/qg/#minimal-workflow) examples.
Expand Down Expand Up @@ -159,7 +159,7 @@ listed above.
<a href="https://github.com/antgroup/vsag"><img src="https://github.com/antgroup.png?size=96" width="40" height="40" alt="VSAG logo"><br>VSAG</a>
</td>
<td align="center" width="16%">
<a href="https://github.com/tensorchord/VectorChord"><img src="https://github.com/tensorchord.png?size=96" width="40" height="40" alt="VectorChord logo"><br>VectorChord</a>
<a href="https://github.com/supervc-stack/VectorChord"><img src="https://github.com/tensorchord.png?size=96" width="40" height="40" alt="VectorChord logo"><br>VectorChord</a>
</td>
</tr>
<tr>
Expand All @@ -184,13 +184,13 @@ listed above.
</tr>
<tr>
<td align="center" width="16%">
<a href="https://docs.lancedb.com/indexing/quantization#rabitq-quantization"><img src="https://github.com/lancedb.png?size=96" width="40" height="40" alt="LanceDB logo"><br>LanceDB</a>
<a href="https://docs.lancedb.com/oss/v0-41-0/indexing/vector-index#rabitq-quantization-rq"><img src="https://github.com/lancedb.png?size=96" width="40" height="40" alt="LanceDB logo"><br>LanceDB</a>
</td>
<td align="center" width="16%">
<a href="https://docs.databricks.com/aws/en/oltp/projects/lakebase-vector"><img src="https://github.com/databricks.png?size=96" width="40" height="40" alt="Databricks logo"><br>Databricks</a>
</td>
<td align="center" width="16%">
<a href="https://clickhouse.com/docs/engines/table-engines/mergetree-family/annindexes#quantized-codecs-methods"><img src="https://github.com/ClickHouse.png?size=96" width="40" height="40" alt="ClickHouse logo"><br>ClickHouse</a>
<a href="https://clickhouse.com/docs/reference/engines/table-engines/mergetree-family/annindexes#quantized-codecs-methods"><img src="https://github.com/ClickHouse.png?size=96" width="40" height="40" alt="ClickHouse logo"><br>ClickHouse</a>
</td>
<td align="center" width="16%">
<a href="https://qdrant.tech/articles/turboquant-quantization/#1-bit-rabitq-bit-plane-scoring"><img src="https://github.com/qdrant.png?size=96" width="40" height="40" alt="Qdrant logo"><br>Qdrant</a>
Expand All @@ -208,7 +208,7 @@ listed above.

- [Documentation](https://vectordb-ntu.github.io/RaBitQ-Library/) and [algorithm overview](https://vectordb-ntu.github.io/RaBitQ-Library/rabitq/rabitq/).
- [Papers and citations](https://vectordb-ntu.github.io/RaBitQ-Library/papers/) for the research behind the library.
- [Release notes](https://github.com/VectorDB-NTU/RaBitQ-Library/releases) and [0.7 migration guide](https://vectordb-ntu.github.io/RaBitQ-Library/modular_migration/).
- [Release notes](https://github.com/VectorDB-NTU/RaBitQ-Library/releases), the [Python migration guide](https://vectordb-ntu.github.io/RaBitQ-Library/python_migration/) and the [0.7 migration guide](https://vectordb-ntu.github.io/RaBitQ-Library/modular_migration/).
- [GPU implementation](https://github.com/Stardust-SJF/cuvs_rabitq/tree/cuvs_ivf_rabitq) in cuVS.

## Contributing
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/hotpaths/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Enable `RABITQ_BUILD_BENCHMARKS=ON` in a Release build. Targets follow enabled c
| `rabitq_core_hotpaths` | core only | One-bit compact encoding or raw L2 calls |
| `rabitq_fastscan_hotpaths` | FastScan | Cached standard/HACC batch scoring |
| `rabitq_load_hotpaths` | index | HNSW centroid-sidecar load and validation |
| `rabitq_ivf_add_hotpaths` | index | One IVF `add` call on a freshly loaded index |
| `rabitq_ivf_add_hotpaths` | index | One `IvfIndex::add` call on a freshly loaded index |
| `rabitq_ids_benchmark` module + `ids.py` | Python bindings | Production cluster-ID conversion helper |

No additional production dependencies are introduced. Core/FastScan benchmarks support
Expand Down Expand Up @@ -66,7 +66,8 @@ the deterministic input. Original production indexes are not benchmark fixtures.
- IVF add verifies the expected point counts and samples new points' self-neighbors
outside the timed call, in addition to comparing output hashes across repetitions.
- Inputs use an LCG with seed 42 (query/centroid seed 91 where applicable; IVF add uses
seed 91 for added points and seed 7 for centroids), metric L2.
seed 91 for added points and seed 7 for centroids), metric L2. IVF add fixes the
rotation seed at 42, so its hashes match across processes.
Dimensions for encoding/scoring are multiples of 32. Use 64, 128 and 960 dimensions;
encoding rows 32/4096 and threads 1/4 retain the cases from the original investigation.
- Core encoding times the existing serial template at one thread and OpenMP template
Expand Down
44 changes: 28 additions & 16 deletions benchmarks/hotpaths/ivf_add.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Times one IVF::add() per repetition, each on a freshly loaded copy of the base index.
// Times one IvfIndex::add() per repetition, each on a freshly loaded copy of the base
// index.
#include <algorithm>
#include <chrono>
#include <cmath>
Expand All @@ -12,7 +13,7 @@

#include "common.hpp"
#include "rabitqlib/core/metric.hpp"
#include "rabitqlib/index/ivf/ivf.hpp"
#include "rabitqlib/index/ivf_index.hpp"
#include "rabitqlib/index/types.hpp"

namespace {
Expand Down Expand Up @@ -49,47 +50,58 @@ void run(int argc, char** argv) {
const std::vector<rabitqlib::PID> single_ids(add_n, rabitqlib::PID{0});
const rabitqlib::PID* add_cluster_ids = mode == "single" ? single_ids.data() : nullptr;

rabitqlib::AddOptions add_options;
add_options.num_threads = 1;
{
rabitqlib::ivf::IVF base(base_n, dim, clusters, 4, rabitqlib::METRIC_L2);
base.construct(base_data.data(), centroids.data(), base_assigned.data(), false, 1);
rabitqlib::IvfOptions options;
options.nbits = 4;
options.seed = 42; // a fixed rotation keeps hashes comparable across processes
rabitqlib::IvfIndex base(dim, clusters, options);
base.set_centroids(centroids.data(), 1);
add_options.cluster_ids = base_assigned.data();
base.add(base_data.data(), base_n, add_options);
base.save(path.c_str());
}
add_options.cluster_ids = add_cluster_ids;
rabitqlib::IvfSearchOptions search_options;
search_options.nprobe = clusters;

bench::metadata(dim, base_n, 1);
const char* name = mode == "single" ? "add_single_cluster" : "add_routed";
uint64_t expected = 0;
for (size_t rep = 0; rep <= reps; ++rep) {
rabitqlib::ivf::IVF index;
index.load(path.c_str());
auto index = rabitqlib::IvfIndex::load(path.c_str());

const auto start = bench::Clock::now();
index.add(add_data.data(), add_n, add_cluster_ids, false, 1);
index.add(add_data.data(), add_n, add_options);
const double seconds =
std::chrono::duration<double>(bench::Clock::now() - start).count();

if (index.num_stored_points() != base_n + add_n ||
index.num_points() != base_n + add_n ||
index.max_elements() != base_n + add_n) {
index.num_points() != base_n + add_n) {
throw std::runtime_error("add() did not append the requested points");
}
// Validate known self-neighbors outside timing, independently of prior runs.
for (size_t row = 0; row < std::min(add_n, size_t{3}); ++row) {
rabitqlib::PID id = rabitqlib::kPidMax;
rabitqlib::Id id = rabitqlib::kNoId;
float distance = 0;
index.search(add_data.data() + row * dim, 1, clusters, &id, &distance);
if (id != base_n + row || !std::isfinite(distance)) {
index.search(add_data.data() + row * dim, 1, 1, &id, &distance, search_options);
if (id != static_cast<rabitqlib::Id>(base_n + row) ||
!std::isfinite(distance)) {
throw std::runtime_error("Added point is not searchable with its new ID");
}
}

uint64_t h = 14695981039346656037ULL;
const size_t total = index.max_elements();
const size_t total = index.num_stored_points();
h = bench::hash(&total, sizeof(total), h);
const size_t k = std::min(size_t{10}, index.num_points());
std::vector<rabitqlib::PID> ids(k);
std::vector<rabitqlib::Id> ids(k);
std::vector<float> distances(k);
index.search(base_data.data(), ids.size(), clusters, ids.data(), distances.data());
h = bench::hash(ids.data(), ids.size() * sizeof(rabitqlib::PID), h);
index.search(
base_data.data(), 1, ids.size(), ids.data(), distances.data(), search_options
);
h = bench::hash(ids.data(), ids.size() * sizeof(rabitqlib::Id), h);
h = bench::hash(distances.data(), distances.size() * sizeof(float), h);

if (rep == 0) {
Expand Down
21 changes: 17 additions & 4 deletions benchmarks/hotpaths/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,31 @@ void run(int argc, char** argv) {
if (!std::filesystem::exists(rabitqlib::io_impl::filesystem_path(path + ".hnsw"))) {
rabitqlib::ivf::HNSWInitializer index(dim, count);
index.add_vectors(data.data(), 1);
std::ofstream unused;
index.save(unused, path.c_str());
std::ofstream output(
rabitqlib::io_impl::filesystem_path(path + ".hnsw"), std::ios::binary
);
output.exceptions(std::ios::failbit | std::ios::badbit);
index.write(output);
return;
}
}
bench::metadata(dim, count, 1);
uint64_t expected = 0;
for (size_t rep = 0; rep <= reps; ++rep) {
rabitqlib::ivf::HNSWInitializer index(dim, count);
std::ifstream unused;
const auto start = bench::Clock::now();
index.load(unused, path.c_str());
// Open the graph file inside the timing, as loading an index does.
std::ifstream input(
rabitqlib::io_impl::filesystem_path(path + ".hnsw"),
std::ios::binary | std::ios::ate
);
if (!input) {
throw std::runtime_error("Cannot open the HNSW centroid graph file");
}
const auto bytes =
static_cast<uint64_t>(static_cast<std::streamoff>(input.tellg()));
input.seekg(0);
index.read(input, bytes);
const double seconds =
std::chrono::duration<double>(bench::Clock::now() - start).count();
uint64_t h = 14695981039346656037ULL;
Expand Down
Loading
Loading