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
53 changes: 45 additions & 8 deletions docs/docs/cpp_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,36 @@ git add third_party/rabitqlib
## Install the C++ library

Installation is useful for package managers, container images, and shared server
environments. Disable native optimization for use on other CPUs:
environments. Configure from the library source directory with native optimization
disabled for use on other CPUs.

=== "Default"

```bash
cmake -S . -B build \
-DRABITQ_BUILD_SAMPLES=OFF \
-DRABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$HOME/.local"
```

=== "Apple Silicon (Homebrew)"

With AppleClang, point CMake to Homebrew's OpenMP runtime.

```bash
brew install libomp
cmake -S . -B build \
-DOpenMP_ROOT="$(brew --prefix libomp)" \
-DRABITQ_BUILD_SAMPLES=OFF \
-DRABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$HOME/.local"
```

Build and install the configured library.

```bash
cmake -S . -B build \
-DRABITQ_BUILD_SAMPLES=OFF \
-DRABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$HOME/.local"
cmake --build build --parallel
cmake --install build
```
Expand All @@ -113,10 +135,25 @@ API, so only the same minor release, at or above a requested patch, satisfies th
0.9.x does, 0.8 and 0.10 do not. A version range must stay within one minor release, for
example `0.9...<0.10`.

For a non-system prefix, point CMake to the installation:
From your application's source directory, point CMake to the library installation.

=== "Default"

```bash
cmake -S . -B build -DCMAKE_PREFIX_PATH="$HOME/.local"
```

=== "Apple Silicon (Homebrew)"

The application discovers OpenMP in its own CMake build directory, so pass
the Homebrew prefix here too.

```bash
cmake -S . -B build -DCMAKE_PREFIX_PATH="$HOME/.local" \
-DOpenMP_ROOT="$(brew --prefix libomp)"
```

```bash
cmake -S . -B build -DCMAKE_PREFIX_PATH="$HOME/.local"
cmake --build build --parallel
```

Expand Down
26 changes: 16 additions & 10 deletions docs/docs/index/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,28 @@ the index classes do not expose a rotator choice.
With `metric="cosine"` (C++ `METRIC_COSINE`), every index scales data and queries to
unit length, stores the inner-product codes of the scaled vectors, and returns
`1 - cos` as the distance, the inner-product distance `1 - dot` of unit vectors.
Centroids passed to `set_centroids` are scaled the same way, because the codes are
residuals against them: centroids far from the unit sphere, such as the means of
unscaled data, would ruin the estimates. `train`, and the first `add` that trains,
IVF-RaBitQ and HNSW-RaBitQ also scale centroids passed to `set_centroids`.
Their codes represent residuals against these centroids, so centroids far from
the unit sphere, such as the means of unscaled data, would distort the estimates.
`train`, and the first `add` that trains,
compute centroids from the scaled vectors with spherical k-means and use them as
computed. Results equal those of a `metric="ip"` index built from the same vectors,
and given the same centroids, after this scaling. A zero vector stays zero, as in
hnswlib and Faiss: its true distance to every vector is 1, which quantized storage
estimates like any other distance.

The index checks the original coordinates first, as above. Because it then trains on
scaled copies, invalid training data is reported as `IVF training data ...` or
`HNSW training data ...` rather than with the k-means message of the other metrics.
`train`, `add` and construction scale a copy of their whole input, so they briefly
need memory for one more float32 copy of it. To bound that for very large data, call
`train` on a sample and `add` the data in several calls. Queries are scaled one at a
time.
Every index checks the original coordinates before scaling them. Because IVF-RaBitQ
and HNSW-RaBitQ then train on scaled copies, invalid training data is reported as
`IVF training data ...` or `HNSW training data ...` rather than with the k-means
message of the other metrics.
Each `train` or `add` call temporarily needs a float32 copy of its input for
normalization. To limit that memory, call `train` on a representative sample,
then `add` the vectors in batches. IDs continue across `add` calls, so adding the
batches in order gives each vector its row number as ID.

[SymphonyQG](qg.md) builds its graph in a single `add` call. Pass the entire
dataset at once and allow for a temporary float32 copy of all vectors during
normalization.

The metric is stored in the [index file](#index-file-compatibility), so a loaded index
keeps scaling its inputs. Releases up to 0.8 have no cosine metric: there, normalize
Expand Down
9 changes: 7 additions & 2 deletions sample/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ detect replaced or reordered vectors. See [QGKMeans](../../docs/docs/clustering.
and [RaBitQKMeans](../../docs/docs/clustering.md#rabitqkmeans) for input limits and assignment
behavior.

For inner product, pass `--metric ip` to every stage and provide normalized
vectors. Use queries and ground truth prepared for the same metric.
For inner-product search, pass `--metric ip` to the IVF, HNSW or SymphonyQG indexing
script. If you run `kmeans_clustering.py` separately, pass `--metric ip` there too.
The query scripts search with the metric stored in the index (the `--metric` option
of `symqg_querying.py` only labels its output). Run them with the index, queries and
matching inner-product ground truth. For cosine
similarity via inner product, normalize both the base vectors and the queries.

`--num-threads 0` uses the library's available logical CPU count, capped by
`OMP_NUM_THREADS`; each stage accepts its own limit. See
[threading](../../docs/docs/index/usage.md#threading-and-file-paths) for affinity
Expand Down