Skip to main content

Class: HuggingFaceInferenceAPIEmbedding()

Uses feature extraction from Hugging Face's Inference API to generate embeddings.

Set the model and accessToken parameter in the constructor, e.g.:

new HuggingFaceInferenceAPIEmbedding({
model: HuggingFaceEmbeddingModelType.XENOVA_ALL_MPNET_BASE_V2,
accessToken: "<your-access-token>"
});

Extends

HuggingFaceInferenceAPIEmbedding<Options>(nodes, options?): Promise<BaseNode<Metadata>[]>

Uses feature extraction from Hugging Face's Inference API to generate embeddings.

Set the model and accessToken parameter in the constructor, e.g.:

new HuggingFaceInferenceAPIEmbedding({
model: HuggingFaceEmbeddingModelType.XENOVA_ALL_MPNET_BASE_V2,
accessToken: "<your-access-token>"
});

Type Parameters

Options extends Record<string, unknown>

Parameters

nodes: BaseNode<Metadata>[]

options?: Options

Returns

Promise<BaseNode<Metadata>[]>

Defined in

packages/llamaindex/src/embeddings/HuggingFaceEmbedding.ts:82

Constructors

new HuggingFaceInferenceAPIEmbedding()

new HuggingFaceInferenceAPIEmbedding(init): HuggingFaceInferenceAPIEmbedding

Parameters

init: any

Returns

HuggingFaceInferenceAPIEmbedding

Overrides

BaseEmbedding.constructor

Defined in

packages/llamaindex/src/embeddings/HuggingFaceEmbedding.ts:86

Properties

embedBatchSize

embedBatchSize: number

Inherited from

BaseEmbedding.embedBatchSize

Defined in

packages/core/embeddings/dist/index.d.ts:34


embedInfo?

optional embedInfo: EmbeddingInfo

Inherited from

BaseEmbedding.embedInfo

Defined in

packages/core/embeddings/dist/index.d.ts:35


hf

hf: HfInference

Defined in

packages/llamaindex/src/embeddings/HuggingFaceEmbedding.ts:84


id

id: string

Inherited from

BaseEmbedding.id

Defined in

packages/core/schema/dist/index.d.ts:171


model

model: string

Defined in

packages/llamaindex/src/embeddings/HuggingFaceEmbedding.ts:83

Methods

getQueryEmbedding()

getQueryEmbedding(query): Promise<null | number[]>

Parameters

query: MessageContentDetail

Returns

Promise<null | number[]>

Inherited from

BaseEmbedding.getQueryEmbedding

Defined in

packages/core/embeddings/dist/index.d.ts:39


getTextEmbedding()

getTextEmbedding(text): Promise<number[]>

Parameters

text: string

Returns

Promise<number[]>

Overrides

BaseEmbedding.getTextEmbedding

Defined in

packages/llamaindex/src/embeddings/HuggingFaceEmbedding.ts:95


getTextEmbeddings()

getTextEmbeddings(texts): Promise<number[][]>

Optionally override this method to retrieve multiple embeddings in a single request

Parameters

texts: string[]

Returns

Promise<number[][]>

Overrides

BaseEmbedding.getTextEmbeddings

Defined in

packages/llamaindex/src/embeddings/HuggingFaceEmbedding.ts:103


getTextEmbeddingsBatch()

getTextEmbeddingsBatch(texts, options?): Promise<number[][]>

Get embeddings for a batch of texts

Parameters

texts: string[]

options?: BaseEmbeddingOptions

Returns

Promise<number[][]>

Inherited from

BaseEmbedding.getTextEmbeddingsBatch

Defined in

packages/core/embeddings/dist/index.d.ts:50


similarity()

similarity(embedding1, embedding2, mode?): number

Parameters

embedding1: number[]

embedding2: number[]

mode?: SimilarityType

Returns

number

Inherited from

BaseEmbedding.similarity

Defined in

packages/core/embeddings/dist/index.d.ts:37


truncateMaxTokens()

truncateMaxTokens(input): string[]

Parameters

input: string[]

Returns

string[]

Inherited from

BaseEmbedding.truncateMaxTokens

Defined in

packages/core/embeddings/dist/index.d.ts:51