Skip to content
1 min read · 208 words

@nhtio/adk/batteries/vector/helpers

Helper utilities for the vector storage provider battery.

Type Aliases

Type AliasDescription
ScoreKindWhether a raw backend score is a similarity (higher = closer) or a distance (lower = closer).

Functions

FunctionDescription
clamp01Clamp n into the inclusive [0, 1] range.
dimensionsMatchtrue if vector's length matches expected (or expected is undefined).
isFiniteVectortrue if vector is an array of finite numbers (no NaN/Infinity).
mapMetricLook up the adapter-specific value for metric in a complete metric→value map.
normalizeScoreNormalize a backend's raw score into a [0, 1] similarity where higher is closer, accounting for the distance metric and whether the raw value is a similarity or a distance.
sanitizeMetadataStrip __proto__/prototype/constructor keys from caller-supplied metadata before an adapter spreads or assigns it onto a record bound for storage. Every adapter's own-object targets ({} literals) are already immune to prototype reassignment, but a stray __proto__-keyed record would otherwise round-trip verbatim through storage and back out to a caller — this keeps the stored shape honest regardless.