Reputation: 129
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.
Upvotes: 4
Views: 5521
Reputation: 23060
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
fortext-embedding-3-small
or3072
fortext-embedding-3-large
. You can reduce the dimensions of the embedding by passing in thedimensions
parameter without the embedding losing its concept-representing properties. We go into more detail on embedding dimensions in the embedding use case section.
Upvotes: 2