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
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.15)

project(RaBitQLib VERSION 0.3.5 LANGUAGES CXX)
project(RaBitQLib VERSION 0.3.6 LANGUAGES CXX)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
Expand Down
13 changes: 7 additions & 6 deletions docs/docs/index/qg.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ window; `ef` controls the query search window. Python defaults to one thread.
### C++

The C++ API uses the float-only `rabitqlib::symqg::QuantizedGraph` and `QGBuilder`.
`QuantizedGraph` is a non-template class; use `QuantizedGraph` instead of
`QuantizedGraph<float>`. Its implementation is compiled in `src/index/qg.cpp`:
`QuantizedGraph<float>` retains the C++ template API, with its implementation
compiled in `src/index/qg.cpp`. C++17 variable declarations can also omit `<float>`
through class template argument deduction:

```cpp
QuantizedGraph(
QuantizedGraph<float>(
size_t num, size_t dim, size_t max_deg,
MetricType metric_type = METRIC_L2,
RotatorType rotator_type = RotatorType::FhtKacRotator,
size_t quantization_bits = 0
);
QGBuilder(
QuantizedGraph& index, uint32_t ef_build, const float* data,
QuantizedGraph<float>& index, uint32_t ef_build, const float* data,
size_t num_threads = std::numeric_limits<size_t>::max(),
QGInitialization init = QGInitialization::PiPNN
);
Expand All @@ -66,7 +67,7 @@ The builder handles initialization internally.
using namespace rabitqlib::symqg;

// data contains rows * cols floats.
QuantizedGraph qg(rows, cols, 32);
QuantizedGraph<float> qg(rows, cols, 32);
{
QGBuilder builder(qg, 200, data.data(), 32, QGInitialization::PiPNN);
builder.build();
Expand Down Expand Up @@ -99,7 +100,7 @@ C++ search accepts one vector in the original input dimension and writes `k` IDs
and distances:

```cpp
QuantizedGraph qg;
QuantizedGraph<float> qg;
qg.load("qg_example.index");
qg.set_ef(100);

Expand Down
18 changes: 17 additions & 1 deletion include/rabitqlib/index/symqg/qg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class QuantizedQuery {
[[nodiscard]] float g_add() const;
};

class QuantizedGraph {
template <typename T = float>
class QuantizedGraph;

template <>
class QuantizedGraph<float> {
friend class QGBuilder;
friend struct QGConstructionTestAccess;

Expand Down Expand Up @@ -187,4 +191,16 @@ class QuantizedGraph {
);
};

// Preserve C++17 deduction for callers that omit the float template argument.
QuantizedGraph()->QuantizedGraph<float>;
QuantizedGraph(
size_t,
size_t,
size_t,
MetricType = METRIC_L2,
RotatorType = RotatorType::FhtKacRotator,
size_t = 0
)
->QuantizedGraph<float>;

} // namespace rabitqlib::symqg
6 changes: 3 additions & 3 deletions include/rabitqlib/index/symqg/qg_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QGBuilder {
friend struct QGConstructionTestAccess;

private:
QuantizedGraph& qg_;
QuantizedGraph<float>& qg_;
size_t ef_build_; // size of search pool for indexing
size_t num_threads_; // number of threads used for indexing
size_t num_nodes_; // num of data points
Expand All @@ -59,7 +59,7 @@ class QGBuilder {

void initialize_storage(const float* data);

QGBuilder(QuantizedGraph& index, uint32_t ef_build, size_t num_threads)
QGBuilder(QuantizedGraph<float>& index, uint32_t ef_build, size_t num_threads)
: qg_{index}
, ef_build_{ef_build}
, num_threads_{std::max<size_t>(1, std::min(num_threads, total_threads()))}
Expand All @@ -69,7 +69,7 @@ class QGBuilder {

public:
explicit QGBuilder(
QuantizedGraph& index,
QuantizedGraph<float>& index,
uint32_t ef_build,
const float* data,
size_t num_threads = std::numeric_limits<size_t>::max(),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "rabitqlib"
version = "0.3.5"
version = "0.3.6"
description = "RaBitQ Python bindings for HNSW, IVF, and SymQG"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
6 changes: 3 additions & 3 deletions python_bindings/symqg_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SymqgIndex {
}

num_points_ = static_cast<size_t>(data_array.shape(0));
index_ = std::make_unique<rabitqlib::symqg::QuantizedGraph>(
index_ = std::make_unique<rabitqlib::symqg::QuantizedGraph<float>>(
num_points_,
dim_,
max_degree_,
Expand Down Expand Up @@ -167,7 +167,7 @@ class SymqgIndex {

static SymqgIndex load(const std::string& path) {
SymqgIndex wrapper;
wrapper.index_ = std::make_unique<rabitqlib::symqg::QuantizedGraph>();
wrapper.index_ = std::make_unique<rabitqlib::symqg::QuantizedGraph<float>>();
wrapper.index_->load(path.c_str());
wrapper.num_points_ = wrapper.index_->num_vertices();
wrapper.dim_ = wrapper.index_->dimension();
Expand All @@ -194,7 +194,7 @@ class SymqgIndex {
rabitqlib::MetricType metric_ = rabitqlib::METRIC_L2;
size_t quantization_bits_ = 0;
bool built_ = false;
std::unique_ptr<rabitqlib::symqg::QuantizedGraph> index_;
std::unique_ptr<rabitqlib::symqg::QuantizedGraph<float>> index_;
};

} // namespace rabitqlib::python_bindings
Expand Down
2 changes: 1 addition & 1 deletion sample/cpp/symqg_indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "rabitqlib/utils/stopw.hpp"

using PID = rabitqlib::PID;
using index_type = rabitqlib::symqg::QuantizedGraph;
using index_type = rabitqlib::symqg::QuantizedGraph<float>;
using data_type = rabitqlib::RowMajorArray<float>;
using gt_type = rabitqlib::RowMajorArray<uint32_t>;

Expand Down
2 changes: 1 addition & 1 deletion sample/cpp/symqg_querying.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "rabitqlib/utils/stopw.hpp"

using PID = rabitqlib::PID;
using index_type = rabitqlib::symqg::QuantizedGraph;
using index_type = rabitqlib::symqg::QuantizedGraph<float>;
using data_type = rabitqlib::RowMajorArray<float>;
using gt_type = rabitqlib::RowMajorArray<uint32_t>;

Expand Down
Loading