Class for generating embeddings using the Mixedbread AI API.

This class leverages the model "mixedbread-ai/mxbai-embed-large-v1" to generate embeddings for text documents. The embeddings can be used for various NLP tasks such as similarity comparison, clustering, or as features in machine learning models.

Example

const embeddings = new MixedbreadAIEmbeddings({ apiKey: 'your-api-key' });
const texts = ["Baking bread is fun", "I love baking"];
const result = await embeddings.embedDocuments(texts);
console.log(result);

Example

const embeddings = new MixedbreadAIEmbeddings({
apiKey: 'your-api-key',
model: 'mixedbread-ai/mxbai-embed-large-v1',
encodingFormat: MixedbreadAI.EncodingFormat.Binary,
dimensions: 512,
normalized: true,
});
const texts = ["Baking bread is fun", "I love baking"];
const result = await embeddings.embedDocuments(texts);
console.log(result);

Hierarchy (view full)

Constructors

  • Constructor for MixedbreadAIEmbeddings.

    Parameters

    Returns MixedbreadAIEmbeddings

    Throws

    If the API key is not provided or found in the environment variables.

    Throws

    If the batch size exceeds 256.

    Example

    const embeddings = new MixedbreadAIEmbeddings({
    apiKey: 'your-api-key',
    model: 'mixedbread-ai/mxbai-embed-large-v1',
    batchSize: 64
    });

Properties

batchSize: number
requestParams: EmbeddingsRequestWithoutInput

Methods

  • Generates embeddings for an array of texts.

    Parameters

    • texts: string[]

      An array of strings to generate embeddings for.

    Returns Promise<number[][]>

    A Promise that resolves to an array of embeddings.

    Example

    const embeddings = new MixedbreadAIEmbeddings({ apiKey: 'your-api-key' });
    const texts = ["Baking bread is fun", "I love baking"];
    const result = await embeddings.embedDocuments(texts);
    console.log(result);
  • Generates an embedding for a single text.

    Parameters

    • text: string

      A string to generate an embedding for.

    Returns Promise<number[]>

    A Promise that resolves to an array of numbers representing the embedding.

    Example

    const embeddings = new MixedbreadAIEmbeddings({ apiKey: 'your-api-key' });
    const text = "Represent this sentence for searching relevant passages: Is baking bread fun?";
    const result = await embeddings.embedQuery(text);
    console.log(result);

Generated using TypeDoc