langchain.js
    Preparing search index...

    Class for generating embeddings using the MistralAI API.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    apiKey: string

    The API key to use.

    {process.env.MISTRAL_API_KEY}
    
    batchSize: number = 512

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

    {512}
    
    beforeRequestHooks?: BeforeRequestHook[]

    A list of custom hooks that must follow (req: Request) => Awaitable<Request | void> They are automatically added when a ChatMistralAI instance is created

    encodingFormat: string = "float"

    The format of the output data.

    {"float"}
    
    endpoint: string

    use serverURL instead

    httpClient?: HTTPClient

    Optional custom HTTP client to manage API requests Allows users to add custom fetch implementations, hooks, as well as error and response processing.

    model: string = "mistral-embed"

    The name of the model to use.

    {"mistral-embed"}
    
    modelName: string = "mistral-embed"

    The name of the model to use. Alias for model.

    {"mistral-embed"}
    
    requestErrorHooks?: RequestErrorHook[]

    A list of custom hooks that must follow (err: unknown, req: Request) => Awaitable They are automatically added when a ChatMistralAI instance is created

    responseHooks?: ResponseHook[]

    A list of custom hooks that must follow (res: Response, req: Request) => Awaitable They are automatically added when a ChatMistralAI instance is created

    serverURL?: string

    Override the default server URL used by the Mistral SDK.

    stripNewLines: boolean = true

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

    {true}
    

    Methods

    • Returns void

    • Method to generate embeddings for an array of documents. Splits the documents into batches and makes requests to the MistralAI API to generate embeddings.

      Parameters

      • texts: string[]

        Array of documents to generate embeddings for.

      Returns Promise<number[][]>

      Promise that resolves to a 2D array of embeddings for each document.

    • Method to generate an embedding for a single document. Calls the embeddingWithRetry method with the document as the input.

      Parameters

      • text: string

        Document to generate an embedding for.

      Returns Promise<number[]>

      Promise that resolves to an embedding for the document.

    • Returns void

    • Parameters

      • hook: BeforeRequestHook | RequestErrorHook | ResponseHook

      Returns void