@nhtio/adk/batteries/vector/helpers
Helper utilities for the vector storage provider battery.
Type Aliases
| Type Alias | Description |
|---|---|
| ScoreKind | Whether a raw backend score is a similarity (higher = closer) or a distance (lower = closer). |
Functions
| Function | Description |
|---|---|
| clamp01 | Clamp n into the inclusive [0, 1] range. |
| dimensionsMatch | true if vector's length matches expected (or expected is undefined). |
| isFiniteVector | true if vector is an array of finite numbers (no NaN/Infinity). |
| mapMetric | Look up the adapter-specific value for metric in a complete metric→value map. |
| normalizeScore | Normalize 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. |
| sanitizeMetadata | Strip __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. |