---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/embeddings/webllm/adapter/classes/WebLLMEmbeddingsAdapter.md
description: Embeddings adapter for WebLLM's in-process embeddings API.
---

# Class: WebLLMEmbeddingsAdapter

Defined in: [batteries/embeddings/webllm/adapter.ts:55](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L55)

Embeddings adapter for WebLLM's in-process embeddings API.

## Remarks

Reusable: construct once, call [WebLLMEmbeddingsAdapter.embed](#embed) / [embedMany](#embedmany) as many
times as needed. The engine is resolved lazily on first use (or via [preload](#preload)) and cached
with single-flight semantics so concurrent calls share one load.

## Constructors

### Constructor

```ts
new WebLLMEmbeddingsAdapter(options: unknown): WebLLMEmbeddingsAdapter;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:76](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L76)

#### Parameters

| Parameter | Type      | Description                             |
| --------- | --------- | --------------------------------------- |
| `options` | `unknown` | Constructor options. Validated eagerly. |

#### Returns

`WebLLMEmbeddingsAdapter`

#### Throws

[@nhtio/adk/batteries/embeddings/webllm/exceptions!E\_INVALID\_WEBLLM\_EMBEDDINGS\_OPTIONS](../../exceptions/variables/E_INVALID_WEBLLM_EMBEDDINGS_OPTIONS.md) when `options` does not satisfy
[@nhtio/adk/batteries/embeddings/webllm/validation!webLLMEmbeddingsOptionsSchema](../../validation/variables/webLLMEmbeddingsOptionsSchema.md) (e.g. missing `model`).

## Accessors

### dimensions

#### Get Signature

```ts
get dimensions(): number | undefined;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:82](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L82)

Declared output dimensionality (from options), or `undefined` if not configured.

##### Returns

`number` | `undefined`

## Methods

### embed()

```ts
embed(text: string, opts?: EmbedOptions): Promise<number[]>;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:142](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L142)

Embeds a single string.

#### Parameters

| Parameter | Type                                                               | Description                |
| --------- | ------------------------------------------------------------------ | -------------------------- |
| `text`    | `string`                                                           | The input text.            |
| `opts?`   | [`EmbedOptions`](../../../openai/types/interfaces/EmbedOptions.md) | Per-call options (`kind`). |

#### Returns

`Promise`<`number`\[]>

The embedding vector as a plain `number[]`.

***

### embedMany()

```ts
embedMany(texts: string[], opts?: EmbedOptions): Promise<number[][]>;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:156](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L156)

Embeds a batch of strings in a single engine call.

#### Parameters

| Parameter | Type                                                               | Description                                                |
| --------- | ------------------------------------------------------------------ | ---------------------------------------------------------- |
| `texts`   | `string`\[]                                                         | The input texts.                                           |
| `opts?`   | [`EmbedOptions`](../../../openai/types/interfaces/EmbedOptions.md) | Per-call options (`kind`). Defaults to `kind: 'document'`. |

#### Returns

`Promise`<`number`\[]\[]>

One embedding vector per input, in input order, each a plain `number[]`.

#### Throws

[@nhtio/adk/batteries/embeddings/webllm/exceptions!E\_WEBLLM\_EMBEDDINGS\_ENGINE\_ERROR](../../exceptions/variables/E_WEBLLM_EMBEDDINGS_ENGINE_ERROR.md) when the engine call fails or returns a
malformed result.

***

### isAvailable()

```ts
isAvailable(): boolean;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:87](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L87)

Whether WebGPU is available, honoring an injected `isWebGPUAvailable` probe.

#### Returns

`boolean`

***

### preload()

```ts
preload(): Promise<void>;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:98](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L98)

Eagerly loads (and caches) the engine so the first `embed` call is fast. Idempotent.

#### Returns

`Promise`<`void`>

#### Throws

[@nhtio/adk/batteries/embeddings/webllm/exceptions!E\_INVALID\_WEBLLM\_EMBEDDINGS\_OPTIONS](../../exceptions/variables/E_INVALID_WEBLLM_EMBEDDINGS_OPTIONS.md) when no WebGPU is available and no engine
was injected.

#### Throws

[@nhtio/adk/batteries/embeddings/webllm/exceptions!E\_WEBLLM\_EMBEDDINGS\_ENGINE\_ERROR](../../exceptions/variables/E_WEBLLM_EMBEDDINGS_ENGINE_ERROR.md) when engine creation fails.

***

### reset()

```ts
reset(): void;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:103](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L103)

Drops the cached engine and in-flight load so the next call reloads.

#### Returns

`void`

***

### isAvailable()

```ts
static isAvailable(): boolean;
```

Defined in: [batteries/embeddings/webllm/adapter.ts:63](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/embeddings/webllm/adapter.ts#L63)

Whether WebGPU — and therefore this battery — is available in the current runtime.

#### Returns

`boolean`
