Documentation
Classes
VectorUtils

Class: VectorUtils

Utilities for working with vectors/embeddings.

Constructors

new VectorUtils()

new VectorUtils(): VectorUtils

Returns

VectorUtils

Methods

cosineSimilarity()

static cosineSimilarity(a, b): number

Calculate the cosine similarity between two vectors.

Parameters

ParameterType
anumber[]
bnumber[]

Returns

number

Source

src/datastore/utils/vectors.ts:4 (opens in a new tab)


dotProduct()

static dotProduct(a, b): number

Calculate the dot product of two vectors

Parameters

ParameterType
anumber[]
bnumber[]

Returns

number

Source

src/datastore/utils/vectors.ts:34 (opens in a new tab)


nearestNeighbors()

static nearestNeighbors<D>(args): D & object[]

Find the nearest neighbors of a vector in a set of documents with embeddings.

Type parameters

Parameter
D extends object

Parameters

ParameterType
argsobject
args.distanceFunction?"cosineSimilarity" | "dotProduct"
args.docsD[]
args.topKnumber
args.vectornumber[]

Returns

D & object[]

The k nearest neighbors of the vector with the similarity score added (sorted by similarity).

Source

src/datastore/utils/vectors.ts:59 (opens in a new tab)