---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/specialists/ocr/tesseract_js/adapter/classes/TesseractJsOcrAdapter.md
description: OCR adapter for `tesseract.js`.
---

# Class: TesseractJsOcrAdapter

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:70](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L70)

OCR adapter for `tesseract.js`.

## Remarks

Reusable: construct once, call [recognize](#recognize) as many times as needed. The worker is
resolved lazily on first use (or via [preload](#preload)) and cached with single-flight semantics so
concurrent calls share one load. See the module remarks for how this deliberately diverges from
the per-call-worker `MediaEngine` in `src/batteries/media/engines/tesseract_js.ts`.

## Constructors

### Constructor

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

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:87](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L87)

#### Parameters

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

#### Returns

`TesseractJsOcrAdapter`

#### Throws

[@nhtio/adk/batteries!E\_INVALID\_TESSERACT\_JS\_OCR\_OPTIONS](../../exceptions/variables/E_INVALID_TESSERACT_JS_OCR_OPTIONS.md) when invalid.

## Methods

### dispose()

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

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:127](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L127)

Terminates the cached worker and drops the cached handle. Alias of [reset](#reset) — both
reclaim the same underlying resource for this adapter (see [reset](#reset)'s TSDoc).

#### Returns

`Promise`<`void`>

***

### isAvailable()

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

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:92](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L92)

Instance availability probe (honours an injected `isAvailable`).

#### Returns

`boolean`

***

### preload()

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

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:97](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L97)

Eagerly loads (and caches) the worker so the first `recognize` call is fast. Idempotent.

#### Returns

`Promise`<`void`>

***

### recognize()

```ts
recognize(input: SpecialistImageInput, opts?: RecognizeOptions): Promise<RecognizeResult>;
```

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:188](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L188)

Recognizes text in an image.

#### Parameters

| Parameter | Type                                                                               | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| --------- | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `input`   | [`SpecialistImageInput`](../../../../_shared/type-aliases/SpecialistImageInput.md) | The image/document input (bytes, bytes+MIME, or a `Media`-like value).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `opts?`   | [`RecognizeOptions`](../../types/interfaces/RecognizeOptions.md)                   | Per-call options. `opts.languages`, when given, must equal the constructor's `languages` (order-insensitive) — tesseract.js v7 workers do not support re-initializing an already-created worker's languages via a public, stable API (there is no `worker.reinitialize` re-language call safe to make on a warm worker without risking cross-call state bleed), so a genuinely different subset throws [@nhtio/adk/batteries!E\_TESSERACT\_JS\_OCR\_ENGINE\_ERROR](../../exceptions/variables/E_TESSERACT_JS_OCR_ENGINE_ERROR.md) explaining that per-call language switching requires a new adapter instance. |

#### Returns

`Promise`<[`RecognizeResult`](../../types/interfaces/RecognizeResult.md)>

The recognized text and, when tesseract reports a numeric confidence, the mean
confidence (`0..100`).

#### Throws

[@nhtio/adk/batteries!E\_TESSERACT\_JS\_OCR\_ENGINE\_ERROR](../../exceptions/variables/E_TESSERACT_JS_OCR_ENGINE_ERROR.md) when the worker fails to
load, the recognize call throws, or a per-call language override cannot be honored.

***

### reset()

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

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:114](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L114)

Terminates the cached worker (if any) and drops the cached handle + in-flight load, so the
next call creates a fresh worker.

#### Returns

`Promise`<`void`>

#### Remarks

Unlike [@nhtio/adk/batteries/embeddings/transformers\_js!TransformersJsEmbeddingsAdapter.reset](../../../../../embeddings/transformers_js/adapter/classes/TransformersJsEmbeddingsAdapter.md#reset),
which only nulls the JS reference and leaves native resources for [dispose](#dispose) to reclaim,
this `reset()` also terminates the worker. A live tesseract.js worker is the SAME heavy WASM
resource `dispose()` releases — no lighter "just drop the reference" tier exists for it (there
is no separate pipeline-session handle to keep warm), so leaving it running after `reset()`
would just leak it under a different method name. Swallows a terminate error (teardown must
not throw). Idempotent.

***

### isAvailable()

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

Defined in: [src/batteries/specialists/ocr/tesseract\_js/adapter.ts:79](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/specialists/ocr/tesseract_js/adapter.ts#L79)

Whether this battery is available. tesseract.js is environment-neutral (Node + browser), so
this is `true` whenever the runtime can import the peer.

#### Returns

`boolean`
