Skip to main content

cosineScore

@forge/monorepo


@forge/monorepo / backend/src / cosineScore

Function: cosineScore()

cosineScore(a, b): number

Defined in: backend/src/adapters/memory/knowledge.ts:48

Cosine similarity, mapped to 0–1.

Cosine rather than raw dot product, because an embedding's magnitude carries no meaning for most providers and an unnormalised dot product would rank a long chunk above a relevant one. Mapped from [-1,1] to [0,1] so a caller's minScore means the same thing whatever metric an adapter uses underneath.

Parameters

a

readonly number[]

b

readonly number[]

Returns

number