MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / metric_from_func_name

Function metric_from_func_name

nodedb-sql/src/planner/select/helpers.rs:195–203  ·  view source on GitHub ↗

Map a vector distance function name to its `DistanceMetric`. `vector_distance` (and the rewritten `<->` operator) → L2; `vector_cosine_distance` (and `<=>`) → Cosine; `vector_neg_inner_product` (and `<#>`) → InnerProduct. Unknown names default to L2 — callers must gate on a `VectorSearch` search-trigger before invoking this so unknown names cannot leak in.

(name: &str)

Source from the content-addressed store, hash-verified

193/// Unknown names default to L2 — callers must gate on a `VectorSearch`
194/// search-trigger before invoking this so unknown names cannot leak in.
195pub(super) fn metric_from_func_name(name: &str) -> DistanceMetric {
196 if name.eq_ignore_ascii_case("vector_cosine_distance") {
197 DistanceMetric::Cosine
198 } else if name.eq_ignore_ascii_case("vector_neg_inner_product") {
199 DistanceMetric::InnerProduct
200 } else {
201 DistanceMetric::L2
202 }
203}
204
205/// Extract a float array from ARRAY[...], make_array(...), or a JSON-array
206/// string literal like `'[1.0, 0.5, 0.0]'`.

Callers 2

plan_vector_from_whereFunction · 0.85
try_extract_sort_searchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected