Skip to main content

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

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(): 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

NameType
settingsHuggingFaceTextEmbeddingModelSettings

Returns

HuggingFaceTextEmbeddingModel

Overrides

AbstractModel&lt;HuggingFaceTextEmbeddingModelSettings&gt;.constructor

Defined in

packages/modelfusion/src/model-provider/huggingface/HuggingFaceTextEmbeddingModel.ts:57

Methods

callAPI

callAPI(texts, callOptions): Promise<number[][]>

Parameters

NameType
textsstring[]
callOptionsFunctionCallOptions

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

NameType
textsstring[]
optionsFunctionCallOptions

Returns

Promise<{ embeddings: number[][] = rawResponse; rawResponse: number[][] }>

Implementation of

EmbeddingModel.doEmbedValues

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

NameType
additionalSettingsPartial<HuggingFaceTextEmbeddingModelSettings>

Returns

HuggingFaceTextEmbeddingModel

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/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

EmbeddingModel.dimensions

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

EmbeddingModel.settings

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