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
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
31 changes: 21 additions & 10 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,18 @@ IVF search defaults to HACC for 4–9 bits and standard FastScan for 1–3 bits

#### SymphonyQG storage

SymphonyQG supports raw storage (`quantization_bits == 0`) and quantized storage at 4 or 8 bits.
SymphonyQG supports raw storage (`quantization_bits == 0` in `QuantizedGraph`, `nbits == 32` in
`SymqgIndex` and Python) and quantized storage at 4 or 8 bits.

### Change an index API

The supported C++ index API is `IvfIndex`, `HnswIndex` and `SymqgIndex` in
`include/rabitqlib/index/*_index.hpp`, with the names, defaults and behaviour of the Python
classes, and their messages where those do not name Python values; the bindings wrap them.
`ivf::IVF`, `hnsw::HierarchicalNSW`, `symqg::QuantizedGraph` and `QGBuilder` stay installed for
these classes and for `QGAssigner`, without documentation or a compatibility promise. Samples and
docs use the supported classes.

Update the C++ declaration/implementation, the corresponding file in `python_bindings/`, Python
type stubs, tests, samples, and the relevant page under `docs/docs/index/`. Preserve public signatures where
possible; add a forwarding overload when evolving an API compatibly. Index construction
Expand Down Expand Up @@ -712,21 +720,24 @@ its upper and base layers use `upper_layer_max_degree_` and
of 32. These settings are not interchangeable.

Public names and Python keywords are compatibility contracts. For example,
`Cluster::num()`, the protected `Initializer::num_cluster_` and QG's
`degree_bound()`/`set_ef()` retain their existing spellings, as do the Python
vocabulary `seed`, `train`, `obj`, `nsplit`, `final_obj` and `niter`. Since 0.9, Python
`Cluster::num()`, the protected `Initializer::num_cluster_`, QG's `degree_bound()` and its
`set_ef()`, which the installed `QGAssigner` calls, retain their existing spellings, as do the
Python vocabulary `seed`, `train`, `obj`, `nsplit`, `final_obj` and `niter`. Since 0.9, Python
spells each concept one way on the index and k-means classes: `ef_search`,
`ef_construction`, `max_degree`, `nbits` (32 for raw storage), `routing` and `capacity`
(#232, #233). `QGKMeansParameters` has the same field names in C++, converting
`nbits == 32` to the 0 that `QGAssigner` and QG take as `quantization_bits`. 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.
(#232, #233). The C++ index classes and `QGKMeansParameters` use the same names; the index
classes also take `Id` (`int64_t`) IDs with `kNoId` for an empty result slot, and
`num_threads == 0` for every available CPU, capped by `OMP_NUM_THREADS`.
`QGKMeansParameters` and `SymqgIndex` convert `nbits == 32` to the 0 that `QGAssigner` and
QG take as `quantization_bits`. 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.

Storage-mode parameters also retain their contracts: IVF/HNSW use `nbits()`
with separate internal `ex_bits_`; IVF additionally accepts 32 for raw-vector
reranking. QG uses `quantization_bits()` with 0 for raw storage and 4/8 for packed
vectors. Naming work does not change these values, allocation sizes, numeric
operations, serialized field order, or ownership.
vectors; `SymqgIndex::nbits()` reports 32 for raw storage. Naming work does not change
these values, allocation sizes, numeric operations, serialized field order, or ownership.

### Numerical module variable names

Expand Down
4 changes: 3 additions & 1 deletion docs/docs/cpp_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ for Linux ARM64, Windows, and Apple Silicon.
## C++ examples

ANN example executables are written to `bin/`. Their source demonstrates complete
indexing and querying workflows:
indexing and querying workflows with the index classes `IvfIndex`, `HnswIndex` and
`SymqgIndex` from `rabitqlib/index/ivf_index.hpp`, `hnsw_index.hpp` and
`symqg_index.hpp`, which `rabitqlib::index` provides:

- [IVF-RaBitQ](https://github.com/VectorDB-NTU/RaBitQ-Library/blob/main/sample/cpp/ivf_rabitq_indexing.cpp)
- [HNSW-RaBitQ](https://github.com/VectorDB-NTU/RaBitQ-Library/blob/main/sample/cpp/hnsw_rabitq_indexing.cpp)
Expand Down
Loading
Loading