Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenAI Embeddings API: How to change the embedding output dimension?

In the official OpenAI node library Create embeddings if for example using the model text-embedding-ada-002 the embeddings returned is an array of around 1536.

import {Configuration, OpenAIApi} from 'openai'

openai = new OpenAIApi(this.configuration)
const parameters= {
      model: 'text-embedding-ada-002',
      input: text,
    }
// Make the embedding request and return the result
const resp = await openai.createEmbedding(parameters)
const embeddings = embedding?.data.data[0].embedding

I would like to be able to limit the length of the list of embeddings returned.

like image 712
Nadsah Avatar asked Sep 03 '25 02:09

Nadsah


1 Answers

You need to use the dimensions parameter with the OpenAI Embeddings API.

As stated in the official OpenAI documentation:

By default, the length of the embedding vector will be 1536 for text-embedding-3-small or 3072 for text-embedding-3-large. You can reduce the dimensions of the embedding by passing in the dimensions parameter without the embedding losing its concept-representing properties. We go into more detail on embedding dimensions in the embedding use case section.

Screenshot

like image 60
Rok Benko Avatar answered Sep 05 '25 13:09

Rok Benko