Optional
fields: Partial<OpenAIEmbeddingsParams> & Partial<AzureOpenAIInput> & {Optional
apiKey?: stringThe OpenAI API key to use.
Optional
configuration?: ClientOptionsOptional
deploymentName?: stringOptional
openAIApiVersion?: stringOptional
verbose?: booleanOptional
azureOptional
azureOptional
azureOptional
azureOptional
azureOptional
azureThe maximum number of documents to embed in a single request. This is limited by the OpenAI API to a maximum of 2048.
Protected
clientProtected
clientOptional
dimensionsThe number of dimensions the resulting output embeddings should have.
Only supported in text-embedding-3
and later models.
Optional
encodingThe format to return the embeddings in. Can be either 'float' or 'base64'.
Model name to use
Optional
organizationWhether 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
Optional
timeoutTimeout to use when making requests to OpenAI.
Protected
embeddingPrivate method to make a request to the OpenAI API to generate embeddings. Handles the retry logic and returns the response from the API.
Request to send to the OpenAI API.
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.
Array of documents to generate embeddings for.
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.
Document to generate an embedding for.
Promise that resolves to an embedding for the document.
Class for generating embeddings using the OpenAI API.
To use with Azure, import the
AzureOpenAIEmbeddings
class.Example