const model = new HuggingFaceTransformersEmbeddings({
model: "Xenova/all-MiniLM-L6-v2",
});

// Embed a single query
const res = await model.embedQuery(
"What would be a good company name for a company that makes colorful socks?"
);
console.log({ res });

// Embed multiple documents
const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
console.log({ documentRes });

Hierarchy

  • Embeddings
    • HuggingFaceTransformersEmbeddings

Implements

Constructors

Properties

batchSize: number = 512

The maximum number of documents to embed in a single request.

caller: AsyncCaller

The async caller should be used by subclasses to make any async calls, which will thus benefit from the concurrency and retry logic.

model: string = "Xenova/all-MiniLM-L6-v2"

Model name to use

modelName: string = "Xenova/all-MiniLM-L6-v2"

Model name to use Alias for model

pipelineOptions?: FeatureExtractionPipelineOptions

Optional parameters for the pipeline.

pretrainedOptions?: PretrainedOptions

Optional parameters for the pretrained model.

stripNewLines: boolean = true

Whether to strip new lines from the input text. This is recommended by OpenAI, but may not be suitable for all use cases.

timeout?: number

Timeout to use when making requests to OpenAI.

Methods

  • An abstract method that takes an array of documents as input and returns a promise that resolves to an array of vectors for each document.

    Parameters

    • texts: string[]

    Returns Promise<number[][]>

    A promise that resolves to an array of vectors for each document.

  • An abstract method that takes a single document as input and returns a promise that resolves to a vector for the query document.

    Parameters

    • text: string

    Returns Promise<number[]>

    A promise that resolves to a vector for the query document.