Skip to main content

Class: CohereTextEmbeddingModel

Create a text embedding model that calls the Cohere Co.Embed API.

See

https://docs.cohere.com/reference/embed

Example

const embeddings = await embedMany(
new CohereTextEmbeddingModel({ model: "embed-english-light-v2.0" }),
[
"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

modelInformation

get modelInformation(): ModelInformation

Returns

ModelInformation

Implementation of

EmbeddingModel.modelInformation

Inherited from

AbstractModel.modelInformation

Defined in

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


modelName

get modelName(): "embed-english-light-v2.0" | "embed-english-v2.0" | "embed-multilingual-v2.0" | "embed-english-v3.0" | "embed-english-light-v3.0" | "embed-multilingual-v3.0" | "embed-multilingual-light-v3.0"

Returns

"embed-english-light-v2.0" | "embed-english-v2.0" | "embed-multilingual-v2.0" | "embed-english-v3.0" | "embed-english-light-v3.0" | "embed-multilingual-v3.0" | "embed-multilingual-light-v3.0"

Overrides

AbstractModel.modelName

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:101


settingsForEvent

get settingsForEvent(): Partial<CohereTextEmbeddingModelSettings>

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

Returns

Partial<CohereTextEmbeddingModelSettings>

Implementation of

EmbeddingModel.settingsForEvent

Overrides

AbstractModel.settingsForEvent

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:164

Constructors

constructor

new CohereTextEmbeddingModel(settings): CohereTextEmbeddingModel

Parameters

NameType
settingsCohereTextEmbeddingModelSettings

Returns

CohereTextEmbeddingModel

Overrides

AbstractModel&lt;CohereTextEmbeddingModelSettings&gt;.constructor

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:86

Methods

callAPI

callAPI(texts, callOptions): Promise<{ embeddings: number[][] ; id: string ; meta: { api_version: { version: string } } ; texts: string[] }>

Parameters

NameType
textsstring[]
callOptionsFunctionCallOptions

Returns

Promise<{ embeddings: number[][] ; id: string ; meta: { api_version: { version: string } } ; texts: string[] }>

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:124


detokenize

detokenize(tokens): Promise<string>

Asynchronously revert a sequence of numeric tokens back into the original text. Detokenization is the process of transforming tokens back to a human-readable format, and it's essential in scenarios where the output needs to be interpretable or when the tokenization process has to be reversible.

Parameters

NameTypeDescription
tokensnumber[]An array of numeric tokens to be converted back to text.

Returns

Promise<string>

A promise containing a string that represents the original text corresponding to the sequence of input tokens.

Implementation of

FullTokenizer.detokenize

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:120


doEmbedValues

doEmbedValues(texts, options): Promise<{ embeddings: number[][] = rawResponse.embeddings; rawResponse: { embeddings: number[][] ; id: string ; meta: { api_version: { version: string } } ; texts: string[] } }>

Parameters

NameType
textsstring[]
optionsFunctionCallOptions

Returns

Promise<{ embeddings: number[][] = rawResponse.embeddings; rawResponse: { embeddings: number[][] ; id: string ; meta: { api_version: { version: string } } ; texts: string[] } }>

Implementation of

EmbeddingModel.doEmbedValues

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:170


tokenize

tokenize(text): Promise<number[]>

Asynchronously tokenize the given text into a sequence of numeric tokens.

Parameters

NameTypeDescription
textstringInput text string that needs to be tokenized.

Returns

Promise<number[]>

A promise containing an array of numbers, where each number is a token representing a part or the whole of the input text.

Implementation of

FullTokenizer.tokenize

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:112


tokenizeWithTexts

tokenizeWithTexts(text): Promise<{ tokenTexts: string[] = response.token_strings; tokens: number[] = response.tokens }>

Asynchronously tokenize the given text, providing both the numeric tokens and their corresponding text.

Parameters

NameTypeDescription
textstringInput text string to be tokenized.

Returns

Promise<{ tokenTexts: string[] = response.token_strings; tokens: number[] = response.tokens }>

A promise containing an object with two arrays:

  1. tokens - An array of numbers where each number is a token.
  2. tokenTexts - An array of strings where each string represents the original text corresponding to each token.

Implementation of

FullTokenizer.tokenizeWithTexts

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:116


withSettings

withSettings(additionalSettings): CohereTextEmbeddingModel

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

Parameters

NameType
additionalSettingsPartial<CohereTextEmbeddingModelSettings>

Returns

CohereTextEmbeddingModel

Example

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

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

Implementation of

EmbeddingModel.withSettings

Overrides

AbstractModel.withSettings

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:178

Properties

contextWindowSize

Readonly contextWindowSize: number

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:109


dimensions

Readonly dimensions: number

The size of the embedding vector.

Implementation of

EmbeddingModel.dimensions

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:107


isParallelizable

Readonly isParallelizable: true

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

Implementation of

EmbeddingModel.isParallelizable

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:106


maxValuesPerCall

Readonly maxValuesPerCall: 96

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

Implementation of

EmbeddingModel.maxValuesPerCall

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:105


provider

Readonly provider: "cohere"

Overrides

AbstractModel.provider

Defined in

packages/modelfusion/src/model-provider/cohere/CohereTextEmbeddingModel.ts:100


settings

Readonly settings: CohereTextEmbeddingModelSettings

Implementation of

EmbeddingModel.settings

Inherited from

AbstractModel.settings

Defined in

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