Skip to main content

Class: OpenAITextEmbeddingModel

Create a text embedding model that calls the OpenAI embedding API.

See

https://platform.openai.com/docs/api-reference/embeddings

Example

const embeddings = await embedMany(
new OpenAITextEmbeddingModel({ model: "text-embedding-ada-002" }),
[
"At first, Nox didn't know what to do with the pup.",
"He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
]
);

Hierarchy

Implements

Accessors

maxValuesPerCall

get maxValuesPerCall(): number

Limit of how many values can be sent in a single API call.

Returns

number

Implementation of

EmbeddingModel.maxValuesPerCall

Inherited from

AbstractOpenAITextEmbeddingModel.maxValuesPerCall

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAITextEmbeddingModel.ts:38


modelInformation

get modelInformation(): ModelInformation

Returns

ModelInformation

Implementation of

EmbeddingModel.modelInformation

Inherited from

AbstractOpenAITextEmbeddingModel.modelInformation

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:17


modelName

get modelName(): "text-embedding-3-small" | "text-embedding-3-large" | "text-embedding-ada-002"

Returns

"text-embedding-3-small" | "text-embedding-3-large" | "text-embedding-ada-002"

Overrides

AbstractOpenAITextEmbeddingModel.modelName

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:83


settingsForEvent

get settingsForEvent(): Partial<OpenAITextEmbeddingModelSettings>

Returns settings that should be recorded in observability events. Security-related settings (e.g. API keys) should not be included here.

Returns

Partial<OpenAITextEmbeddingModelSettings>

Implementation of

EmbeddingModel.settingsForEvent

Overrides

AbstractOpenAITextEmbeddingModel.settingsForEvent

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:96

Constructors

constructor

new OpenAITextEmbeddingModel(settings): OpenAITextEmbeddingModel

Parameters

NameType
settingsOpenAITextEmbeddingModelSettings

Returns

OpenAITextEmbeddingModel

Overrides

AbstractOpenAITextEmbeddingModel.constructor

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:70

Methods

callAPI

callAPI(texts, callOptions): Promise<{ data: { embedding: number[] ; index: number ; object: "embedding" }[] ; model: string ; object: "list" ; usage?: { prompt_tokens: number ; total_tokens: number } }>

Parameters

NameType
textsstring[]
callOptionsFunctionCallOptions

Returns

Promise<{ data: { embedding: number[] ; index: number ; object: "embedding" }[] ; model: string ; object: "list" ; usage?: { prompt_tokens: number ; total_tokens: number } }>

Inherited from

AbstractOpenAITextEmbeddingModel.callAPI

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAITextEmbeddingModel.ts:44


countTokens

countTokens(input): Promise<number>

Parameters

NameType
inputstring

Returns

Promise<number>

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:92


doEmbedValues

doEmbedValues(texts, callOptions): Promise<{ embeddings: number[][] ; rawResponse: { data: { embedding: number[] ; index: number ; object: "embedding" }[] ; model: string ; object: "list" ; usage?: { prompt_tokens: number ; total_tokens: number } } }>

Parameters

NameType
textsstring[]
callOptionsFunctionCallOptions

Returns

Promise<{ embeddings: number[][] ; rawResponse: { data: { embedding: number[] ; index: number ; object: "embedding" }[] ; model: string ; object: "list" ; usage?: { prompt_tokens: number ; total_tokens: number } } }>

Implementation of

EmbeddingModel.doEmbedValues

Inherited from

AbstractOpenAITextEmbeddingModel.doEmbedValues

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAITextEmbeddingModel.ts:80


withSettings

withSettings(additionalSettings): OpenAITextEmbeddingModel

The withSettings method creates a new model with the same configuration as the original model, but with the specified settings changed.

Parameters

NameType
additionalSettingsOpenAITextEmbeddingModelSettings

Returns

OpenAITextEmbeddingModel

Example

const model = new OpenAICompletionModel({
model: "gpt-3.5-turbo-instruct",
maxGenerationTokens: 500,
});

const modelWithMoreTokens = model.withSettings({
maxGenerationTokens: 1000,
});

Implementation of

EmbeddingModel.withSettings

Overrides

AbstractOpenAITextEmbeddingModel.withSettings

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:100

Properties

contextWindowSize

Readonly contextWindowSize: number

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:90


dimensions

Readonly dimensions: number

The size of the embedding vector.

Implementation of

EmbeddingModel.dimensions

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:87


isParallelizable

Readonly isParallelizable: true

True if the model can handle multiple embedding calls in parallel.

Implementation of

EmbeddingModel.isParallelizable

Inherited from

AbstractOpenAITextEmbeddingModel.isParallelizable

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAITextEmbeddingModel.ts:42


provider

Readonly provider: "openai"

Overrides

AbstractOpenAITextEmbeddingModel.provider

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:82


settings

Readonly settings: OpenAITextEmbeddingModelSettings

Implementation of

EmbeddingModel.settings

Inherited from

AbstractOpenAITextEmbeddingModel.settings

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:7


tokenizer

Readonly tokenizer: TikTokenTokenizer

Defined in

packages/modelfusion/src/model-provider/openai/OpenAITextEmbeddingModel.ts:89