> For the complete documentation index, see [llms.txt](https://docs.aibrow.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aibrow.ai/api-reference/aibrow/embedding.md).

# Embedding

{% hint style="info" %}
Only available on the <mark style="background-color:green;">extension</mark> & <mark style="background-color:purple;">web</mark> implementations
{% endhint %}

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability.md)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                                |
| ------------------------------------------------------------------------------------------------- |
| **options** `optional` [`EmbeddingCreateOptions`](/api-reference/types/embeddingcreateoptions.md) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility.md)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                                |
| ------------------------------------------------------------------------------------------------- |
| **options** `optional` [`EmbeddingCreateOptions`](/api-reference/types/embeddingcreateoptions.md) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`Embedding`](/api-reference/aibrow/embedding.md)

Creates a new embedding session

| Options (optional)                                                                                |
| ------------------------------------------------------------------------------------------------- |
| **options** `optional` [`EmbeddingCreateOptions`](/api-reference/types/embeddingcreateoptions.md) |

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

***

## Properties

### gpuEngine

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine.md)&#x20;

### dtype

[`AIModelDtype`](/api-reference/types/aimodeldtype.md)&#x20;

### 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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aibrow.ai/api-reference/aibrow/embedding.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
