Skip to content

routier-collection


routier-collection / core/src / cosineDistance

Function: cosineDistance()

cosineDistance(left, right): number

Defined in: core/src/plugins/query/similarity.ts:28

Distance in [0, 2], or Infinity for a value that cannot be compared.

Infinity covers three cases, and they all sort LAST, which is what PostgreSQL does too: a missing value (NULL sorts last under ASC by default), a zero-magnitude vector (pgvector's <=> yields NaN, which PostgreSQL orders after every real number), and a stored vector of the wrong width.

The width case cannot happen on a native vector(n) column — the engine rejects the write — so it only arises on a backend storing JSON, where the data was written by something other than this schema. Sorting it last rather than throwing keeps one corrupt row from failing a query that is otherwise answerable.

Parameters

left

readonly number[]

readonly number[]

Returns

number

Released under the MIT License.