Embedding

Only available on the extension & web implementations

Static Methods

static availability

static async availability(options) => AIModelAvailability

Get the availability of the on-device language model.

Options (optional)

options optional EmbeddingCreateOptions

Returns the availability

static compatibility

static async compatibility(options) => AIModelCoreCompatibility

Get the availability of the on-device language model.

Options (optional)

options optional EmbeddingCreateOptions

Returns the compatibility

static create

static async create(options) => Embedding

Creates a new embedding session

Options (optional)

options optional EmbeddingCreateOptions

Returns a new Embedding session that can be prompted with the pre-provided configuration


Properties

gpuEngine

AIModelGpuEngine

dtype

AIModelDtype

flashAttention

boolean

contextSize

number


Methods

get

async (input, options) => number[] | number[][]

Creates a new vector from the provided input

Input

A string or strings[] to generate a vector(s) from

Options (optional)

signal optional AbortSignal

Returns the vector or vectors from the language model

calculateCosineSimilarity

(vectorA, vectorB) => number

Calculates the cosine similarity between two embeddings. Only compare embeddings created by the same model

vectorA

A number[] vector to compare

vectorB

A number[] vector to compare

Returns a value between 0 and 1 representing the similarity. 1 being the most similar

findSimilar

(embeddings, target) => any[]

Finds and sorts similar vectors

embeddings

An Array<{ id: any, vector: number[] }> array of objects, each with id and vector

target

A number[] vector to use as the search target

Returns a list of ids, sorted by the most similar to the least similar

Last updated