Caution: Custom distance metrics for IVF-flat search are experimental. They live under the
cuvs::neighbors::ivf_flat::experimental::udfnamespace and the associatedCUVS_METRICmacro. APIs and behavior may change without a major release.
You can supply your own CUDA device code that defines how distance accumulates between a query vector and database vectors inside the IVF-flat interleaved scan (the fine search over lists). Technical background on compilation and linking is in Link-time Optimization.
search_params.metric_udf / CUVS_METRIC).<cuvs/neighbors/ivf_flat.hpp> and define a metric with CUVS_METRIC(MyName, { ... }). Set search_params.metric_udf to the string returned by MyName_udf().int8_t / uint8_t as well as wider element types.__half / half) indices at this time; the headers enforce this with a static assertion when applicable.CUVS_METRIC bodiesInside CUVS_METRIC(MyName, { ... }) you write the body of operator()(AccT& acc, point_type x, point_type y). In scope: acc, x, y, template parameters T, AccT, Veclen, and the helpers below. The macro’s full argument list and notes live beside CUVS_METRIC in <cuvs/neighbors/ivf_flat.hpp>.
More examples: cpp/tests/neighbors/ann_ivf_flat/test_udf.cu.