Class: HuggingFaceTextEmbeddingModel
Create a text embedding model that calls a Hugging Face Inference API Feature Extraction Task.
See
https://huggingface.co/docs/api-inference/detailed_parameters#feature-extraction-task
Example
const model = new HuggingFaceTextGenerationModel({
model: "intfloat/e5-base-v2",
maxTexstsPerCall: 5,
retry: retryWithExponentialBackoff({ maxTries: 5 }),
});
const embeddings = await embedMany(
model,
[
"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
<HuggingFaceTextEmbeddingModelSettings
>↳
HuggingFaceTextEmbeddingModel
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(): string
Returns
string
Overrides
AbstractModel.modelName
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:66
settingsForEvent
• get
settingsForEvent(): Partial
<HuggingFaceTextEmbeddingModelSettings
>
Returns settings that should be recorded in observability events. Security-related settings (e.g. API keys) should not be included here.
Returns
Partial
<HuggingFaceTextEmbeddingModelSettings
>
Implementation of
EmbeddingModel.settingsForEvent
Overrides
AbstractModel.settingsForEvent
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:119
Constructors
constructor
• new HuggingFaceTextEmbeddingModel(settings
): HuggingFaceTextEmbeddingModel
Parameters
Name | Type |
---|---|
settings | HuggingFaceTextEmbeddingModelSettings |
Returns
Overrides
AbstractModel<HuggingFaceTextEmbeddingModelSettings>.constructor
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:57
Methods
callAPI
▸ callAPI(texts
, callOptions
): Promise
<number
[][]>
Parameters
Name | Type |
---|---|
texts | string [] |
callOptions | FunctionCallOptions |
Returns
Promise
<number
[][]>
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:78
doEmbedValues
▸ doEmbedValues(texts
, options
): Promise
<{ embeddings
: number
[][] = rawResponse; rawResponse
: number
[][] }>
Parameters
Name | Type |
---|---|
texts | string [] |
options | FunctionCallOptions |
Returns
Promise
<{ embeddings
: number
[][] = rawResponse; rawResponse
: number
[][] }>
Implementation of
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:128
withSettings
▸ withSettings(additionalSettings
): HuggingFaceTextEmbeddingModel
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 <HuggingFaceTextEmbeddingModelSettings > |
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/huggingface/HuggingFaceTextEmbeddingModel.ts:137
Properties
contextWindowSize
• Readonly
contextWindowSize: undefined
= undefined
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:73
countPromptTokens
• Readonly
countPromptTokens: undefined
= undefined
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:126
dimensions
• Readonly
dimensions: undefined
| number
The size of the embedding vector.
Implementation of
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:74
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/huggingface/HuggingFaceTextEmbeddingModel.ts:71
maxValuesPerCall
• Readonly
maxValuesPerCall: number
Limit of how many values can be sent in a single API call.
Implementation of
EmbeddingModel.maxValuesPerCall
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:70
provider
• Readonly
provider: "huggingface"
Overrides
AbstractModel.provider
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:65
settings
• Readonly
settings: HuggingFaceTextEmbeddingModelSettings
Implementation of
Inherited from
AbstractModel.settings
Defined in
packages/modelfusion/src/model-function/AbstractModel.ts:7
tokenizer
• Readonly
tokenizer: undefined
= undefined
Defined in
packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:76