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.
You can't change the embedding output dimension. The OpenAI Embeddings API doesn't have a parameter to control this. If you use the
text-embedding-ada-002
model, you'll always get a 1536-dimensional embedding vector (i.e., there are 1536 numbers inside).It's pre-defined, as stated in the official OpenAI documentation:
Note: You don't get 1536 embeddings from the OpenAI Embeddings API. You get one(!) 1536-dimensional embedding. What you can try to do is translate the embedding you get from the OpenAI Embeddings API to a lower-dimensional space. You'll have to do it manually.