You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wraps the IVF-SQ C API (added in v26.06) in the Rust crate, mirroring
the cagra module structure: IndexParams and SearchParams builders,
Index with build / search / search_with_filter (cuvsFilter bitset) /
extend / serialize / deserialize, and the NLists/Dim/Size getters.
cuvsIvfSqIndexGetCenters is deliberately not wrapped, matching cagra
and ivf_pq. rust/cuvs-sys/src/bindings.rs regenerated (additive).
9 GPU tests: params builders, build + self-neighbor search, repeated
search, getters, extend from an empty index, bitset-filtered search
(verifies exclusion), serialize/deserialize round-trip (re-verifies
search on the loaded index), interior-NUL path rejection.
Copy file name to clipboardExpand all lines: rust/cuvs-sys/src/bindings.rs
+176Lines changed: 176 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1765,6 +1765,182 @@ unsafe extern "C" {
1765
1765
index:cuvsIvfFlatIndex_t,
1766
1766
) -> cuvsError_t;
1767
1767
}
1768
+
#[doc = " @defgroup ivf_sq_c_index_params IVF-SQ index build parameters\n @{\n/\n/**\n @brief Supplemental parameters to build IVF-SQ Index\n"]
1769
+
#[repr(C)]
1770
+
#[derive(Debug,Copy,Clone)]
1771
+
pubstructcuvsIvfSqIndexParams{
1772
+
#[doc = " Distance type."]
1773
+
pubmetric:cuvsDistanceType,
1774
+
#[doc = " The argument used by some distance metrics."]
1775
+
pubmetric_arg:f32,
1776
+
#[doc = " Whether to add the dataset content to the index, i.e.:\n\n - `true` means the index is filled with the dataset vectors and ready to search after calling\n `build`.\n - `false` means `build` only trains the underlying model (e.g. quantizer or clustering), but\n the index is left empty; you'd need to call `extend` on the index afterwards to populate it."]
1777
+
pubadd_data_on_build:bool,
1778
+
#[doc = " The number of inverted lists (clusters)"]
1779
+
pubn_lists:u32,
1780
+
#[doc = " The number of iterations searching for kmeans centers (index building)."]
1781
+
pubkmeans_n_iters:u32,
1782
+
#[doc = " The number of data vectors per cluster to use during iterative kmeans building.\n The index uses at most `n_lists * max_train_points_per_cluster` rows for training."]
1783
+
pubmax_train_points_per_cluster:u32,
1784
+
#[doc = " By default, the algorithm allocates more space than necessary for individual clusters\n (`list_data`). This allows to amortize the cost of memory allocation and reduce the number of\n data copies during repeated calls to `extend` (extending the database).\n\n The alternative is the conservative allocation behavior; when enabled, the algorithm always\n allocates the minimum amount of memory required to store the given number of records. Set this\n flag to `true` if you prefer to use as little GPU memory for the database as possible."]
#[doc = " @brief Allocate IVF-SQ Index params, and populate with default values\n\n @param[in] index_params cuvsIvfSqIndexParams_t to allocate\n @return cuvsError_t"]
#[doc = " @defgroup ivf_sq_c_index IVF-SQ index\n @{\n/\n/**\n @brief Struct to hold address of cuvs::neighbors::ivf_sq::index and its active trained dtype\n"]
#[doc = " @brief Get the cluster centers corresponding to the lists [n_lists, dim]\n\n @param[in] index cuvsIvfSqIndex_t Built Ivf-SQ Index\n @param[out] centers Preallocated array on host or device memory to store output, [n_lists, dim]\n @return cuvsError_t"]
1888
+
pubfncuvsIvfSqIndexGetCenters(
1889
+
index:cuvsIvfSqIndex_t,
1890
+
centers:*mutDLManagedTensor,
1891
+
) -> cuvsError_t;
1892
+
}
1893
+
unsafeextern"C"{
1894
+
#[must_use]
1895
+
#[doc = " @defgroup ivf_sq_c_index_build IVF-SQ index build\n @{\n/\n/**\n @brief Build an IVF-SQ index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/ivf_sq.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n\n // Create default index params\n cuvsIvfSqIndexParams_t index_params;\n cuvsError_t params_create_status = cuvsIvfSqIndexParamsCreate(&index_params);\n\n // Create IVF-SQ index\n cuvsIvfSqIndex_t index;\n cuvsError_t index_create_status = cuvsIvfSqIndexCreate(&index);\n\n // Build the IVF-SQ Index\n cuvsError_t build_status = cuvsIvfSqBuild(res, index_params, &dataset, index);\n\n // de-allocate `index_params`, `index` and `res`\n cuvsError_t params_destroy_status = cuvsIvfSqIndexParamsDestroy(index_params);\n cuvsError_t index_destroy_status = cuvsIvfSqIndexDestroy(index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index_params cuvsIvfSqIndexParams_t used to build IVF-SQ index\n @param[in] dataset DLManagedTensor* training dataset\n @param[out] index cuvsIvfSqIndex_t Newly built IVF-SQ index\n @return cuvsError_t"]
1896
+
pubfncuvsIvfSqBuild(
1897
+
res:cuvsResources_t,
1898
+
index_params:cuvsIvfSqIndexParams_t,
1899
+
dataset:*mutDLManagedTensor,
1900
+
index:cuvsIvfSqIndex_t,
1901
+
) -> cuvsError_t;
1902
+
}
1903
+
unsafeextern"C"{
1904
+
#[must_use]
1905
+
#[doc = " @defgroup ivf_sq_c_index_search IVF-SQ index search\n @{\n/\n/**\n @brief Search an IVF-SQ index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`.\n Types for input are:\n 1. `queries`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32` or 16\n 2. `neighbors`: `kDLDataType.code == kDLInt` and `kDLDataType.bits = 64`\n 3. `distances`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/ivf_sq.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor queries;\n DLManagedTensor neighbors;\n DLManagedTensor distances;\n\n // Create default search params\n cuvsIvfSqSearchParams_t search_params;\n cuvsError_t params_create_status = cuvsIvfSqSearchParamsCreate(&search_params);\n\n // Search the `index` built using `cuvsIvfSqBuild`\n cuvsError_t search_status = cuvsIvfSqSearch(\n res, search_params, index, &queries, &neighbors, &distances, (cuvsFilter){});\n\n // de-allocate `search_params` and `res`\n cuvsError_t params_destroy_status = cuvsIvfSqSearchParamsDestroy(search_params);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] search_params cuvsIvfSqSearchParams_t used to search IVF-SQ index\n @param[in] index ivfSqIndex which has been returned by `cuvsIvfSqBuild`\n @param[in] queries DLManagedTensor* queries dataset to search\n @param[out] neighbors DLManagedTensor* output `k` neighbors for queries\n @param[out] distances DLManagedTensor* output `k` distances for queries\n @param[in] filter cuvsFilter input filter that can be used\n to filter queries and neighbors based on the given bitset."]
1906
+
pubfncuvsIvfSqSearch(
1907
+
res:cuvsResources_t,
1908
+
search_params:cuvsIvfSqSearchParams_t,
1909
+
index:cuvsIvfSqIndex_t,
1910
+
queries:*mutDLManagedTensor,
1911
+
neighbors:*mutDLManagedTensor,
1912
+
distances:*mutDLManagedTensor,
1913
+
filter:cuvsFilter,
1914
+
) -> cuvsError_t;
1915
+
}
1916
+
unsafeextern"C"{
1917
+
#[must_use]
1918
+
#[doc = " @defgroup ivf_sq_c_index_serialize IVF-SQ C-API serialize functions\n @{\n/\n/**\n Save the index to file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @code{.c}\n #include <cuvs/neighbors/ivf_sq.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsIvfSqBuild`\n cuvsIvfSqSerialize(res, \"/path/to/index\", index);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the file name for saving the index\n @param[in] index IVF-SQ index"]
1919
+
pubfncuvsIvfSqSerialize(
1920
+
res:cuvsResources_t,
1921
+
filename:*const::std::os::raw::c_char,
1922
+
index:cuvsIvfSqIndex_t,
1923
+
) -> cuvsError_t;
1924
+
}
1925
+
unsafeextern"C"{
1926
+
#[must_use]
1927
+
#[doc = " Load index from file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the name of the file that stores the index\n @param[out] index IVF-SQ index loaded from disk"]
1928
+
pubfncuvsIvfSqDeserialize(
1929
+
res:cuvsResources_t,
1930
+
filename:*const::std::os::raw::c_char,
1931
+
index:cuvsIvfSqIndex_t,
1932
+
) -> cuvsError_t;
1933
+
}
1934
+
unsafeextern"C"{
1935
+
#[must_use]
1936
+
#[doc = " @defgroup ivf_sq_c_index_extend IVF-SQ index extend\n @{\n/\n/**\n @brief Extend the index with the new data.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] new_vectors DLManagedTensor* the new vectors to add to the index\n @param[in] new_indices DLManagedTensor* vector of new indices for the new vectors. If the index\n is empty, this can be NULL to imply a continuous range `[0...n_rows)`.\n @param[inout] index IVF-SQ index to be extended\n @return cuvsError_t"]
1937
+
pubfncuvsIvfSqExtend(
1938
+
res:cuvsResources_t,
1939
+
new_vectors:*mutDLManagedTensor,
1940
+
new_indices:*mutDLManagedTensor,
1941
+
index:cuvsIvfSqIndex_t,
1942
+
) -> cuvsError_t;
1943
+
}
1768
1944
unsafeextern"C"{
1769
1945
#[must_use]
1770
1946
#[doc = " @defgroup ann_refine_c Approximate Nearest Neighbors Refinement C-API\n @{\n/\n/**\n @brief Refine nearest neighbor search.\n\n Refinement is an operation that follows an approximate NN search. The approximate search has\n already selected n_candidates neighbor candidates for each query. We narrow it down to k\n neighbors. For each query, we calculate the exact distance between the query and its\n n_candidates neighbor candidate, and select the k nearest ones.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] dataset device matrix that stores the dataset [n_rows, dims]\n @param[in] queries device matrix of the queries [n_queris, dims]\n @param[in] candidates indices of candidate vectors [n_queries, n_candidates], where\n n_candidates >= k\n @param[in] metric distance metric to use. Euclidean (L2) is used by default\n @param[out] indices device matrix that stores the refined indices [n_queries, k]\n @param[out] distances device matrix that stores the refined distances [n_queries, k]"]
0 commit comments