AiBrow
  • Welcome
  • AiBrow web API
    • Getting started
    • Feature comparison
  • AiBrow Extension
    • Getting started
    • Web polyfill
    • Helping users install the AiBrow extension
    • Remove the on-device helper or models
  • Examples
    • Embedding API
    • LanguageDetector API
    • LanguageModel API
    • Rewriter API
    • Summarizer API
    • Translator API
    • Writer API
    • Using different models
    • Model download feedback
    • Getting JSON output
  • API Reference
    • AI
      • AIBrow
      • BrowserAI
      • AIBrowWeb
    • AiBrow
      • Embedding
      • LanguageDetector
      • LanguageModel
      • Rewriter
      • Summarizer
      • Translator
      • Writer
    • Types
      • AIModelAvailability
      • AIModelCoreCompatibility
      • AIModelDtype
      • AIModelGpuEngine
      • AICreateMonitor
      • EmbeddingCreateOptions
      • LanguageDetectorCreateOptions
      • LanguageDetectorDetectResult
      • LanguageModelCreateOptions
      • RewriterCreateOptions
      • RewriterFormat
      • RewriterLength
      • RewriterTone
      • SummarizerCreateOptions
      • SummarizerFormat
      • SummarizerLength
      • SummarizerType
      • TranslatorCreateOptions
      • WriterCreateOptions
      • WriterFormat
      • WriterLength
      • WriterTone
    • Models
Powered by GitBook
On this page
  • Static Methods
  • static availability
  • static compatibility
  • static create
  • Properties
  • gpuEngine
  • dtype
  • flashAttention
  • contextSize
  • Methods
  • get
  • calculateCosineSimilarity
  • findSimilar
  1. API Reference
  2. AiBrow

Embedding

PreviousAiBrowNextLanguageDetector

Last updated 12 days ago

Only available on the extension & web implementations

Static Methods

static availability

static async availability(options) =>

Get the availability of the on-device language model.

Options (optional)

Returns the availability

static compatibility

static async compatibility(options) =>

Get the availability of the on-device language model.

Options (optional)

Returns the compatibility

static create

static async create(options) =>

Creates a new embedding session

Options (optional)

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


Properties

gpuEngine

dtype

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

options optional

options optional

options optional

AIModelAvailability
AIModelCoreCompatibility
Embedding
AIModelGpuEngine
AIModelDtype
EmbeddingCreateOptions
EmbeddingCreateOptions
EmbeddingCreateOptions