langchain.js
    Preparing search index...

    Class AzureOpenAIEmbeddings

    Class for generating embeddings using the OpenAI API.

    To use with Azure, import the AzureOpenAIEmbeddings class.

    // Embed a query using OpenAIEmbeddings to generate embeddings for a given text
    const model = new OpenAIEmbeddings();
    const res = await model.embedQuery(
    "What would be a good company name for a company that makes colorful socks?",
    );
    console.log({ res });

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • Optionalfields: Partial<OpenAIEmbeddingsParams> & Partial<AzureOpenAIInput> & {
            apiKey?: string;
            configuration?: ClientOptions;
            deploymentName?: string;
            openAIApiVersion?: string;
            verbose?: boolean;
        }
        • OptionalapiKey?: string

          The OpenAI API key to use.

        • Optionalconfiguration?: ClientOptions
        • OptionaldeploymentName?: string
        • OptionalopenAIApiVersion?: string
        • Optionalverbose?: boolean

      Returns AzureOpenAIEmbeddings

    Properties

    azureADTokenProvider?: () => Promise<string>
    azureOpenAIApiDeploymentName?: string
    azureOpenAIApiInstanceName?: string
    azureOpenAIApiKey?: string
    azureOpenAIApiVersion?: string
    azureOpenAIBasePath?: string
    batchSize: number = 512

    The maximum number of documents to embed in a single request. This is limited by the OpenAI API to a maximum of 2048.

    client: OpenAI
    clientConfig: ClientOptions
    dimensions?: number

    The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.

    encodingFormat?: "float" | "base64"

    The format to return the embeddings in. Can be either 'float' or 'base64'.

    model: string = "text-embedding-ada-002"

    Model name to use

    modelName: string

    Use "model" instead

    organization?: string
    stripNewLines: boolean = true

    Whether to strip new lines from the input text. This is recommended by OpenAI for older models, but may not be suitable for all use cases. See: https://github.com/openai/openai-python/issues/418#issuecomment-1525939500

    timeout?: number

    Timeout to use when making requests to OpenAI.

    Methods

    • Private method to make a request to the OpenAI API to generate embeddings. Handles the retry logic and returns the response from the API.

      Parameters

      • request: EmbeddingCreateParams

        Request to send to the OpenAI API.

      Returns Promise<any>

      Promise that resolves to the response from the API.

    • Method to generate embeddings for an array of documents. Splits the documents into batches and makes requests to the OpenAI 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.