Class: VectorUtils
Utilities for working with vectors/embeddings.
Constructors
new VectorUtils()
new VectorUtils():
VectorUtils
Returns
Methods
cosineSimilarity()
static
cosineSimilarity(a
,b
):number
Calculate the cosine similarity between two vectors.
Parameters
Parameter | Type |
---|---|
a | number [] |
b | number [] |
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
Parameter | Type |
---|---|
a | number [] |
b | number [] |
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
Parameter | Type |
---|---|
args | object |
args.distanceFunction ? | "cosineSimilarity" | "dotProduct" |
args.docs | D [] |
args.topK | number |
args.vector | number [] |
Returns
D
& object
[]
The k nearest neighbors of the vector with the similarity score added (sorted by similarity).