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
-
AbstractModel
<CohereTextEmbeddingModelSettings
>↳
CohereTextEmbeddingModel
Implements
Accessors
modelInformation
• get
modelInformation(): ModelInformation
Returns
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
Name | Type |
---|---|
settings | CohereTextEmbeddingModelSettings |
Returns
Overrides
AbstractModel<CohereTextEmbeddingModelSettings>.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
Name | Type |
---|---|
texts | string [] |
callOptions | FunctionCallOptions |
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
Name | Type | Description |
---|---|---|
tokens | number [] | 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
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
Name | Type |
---|---|
texts | string [] |
options | FunctionCallOptions |
Returns
Promise
<{ embeddings
: number
[][] = rawResponse.embeddings; rawResponse
: { embeddings
: number
[][] ; id
: string
; meta
: { api_version
: { version
: string
} } ; texts
: string
[] } }>
Implementation of
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
Name | Type | Description |
---|---|---|
text | string | Input 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
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
Name | Type | Description |
---|---|---|
text | string | Input text string to be tokenized. |
Returns
Promise
<{ tokenTexts
: string
[] = response.token_strings; tokens
: number
[] = response.tokens }>
A promise containing an object with two arrays:
tokens
- An array of numbers where each number is a token.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
Name | Type |
---|---|
additionalSettings | Partial <CohereTextEmbeddingModelSettings > |
Returns
Example
const model = new OpenAICompletionModel({
model: "gpt-3.5-turbo-instruct",
maxGenerationTokens: 500,
});
const modelWithMoreTokens = model.withSettings({
maxGenerationTokens: 1000,
});
Implementation of
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
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
Inherited from
AbstractModel.settings