#array of embeddings response indexing

1 messages · Page 1 of 1 (latest)

lusty spruce
#

hi,

when using v1/embeddings

when sending an array of strings to be embedded, does openai guaranteed to return the results in the same ordering as the array that was provided? how do you know which index in the response corresponds to the index of the string you passed in?

runic ospreyBOT
#

Hi @lusty spruce. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, when using the OpenAI's Embeddings API, the order of the embeddings in the response corresponds to the order of the strings you passed in. This is indicated by the 'index' property in the response. Each embedding object in the response has an 'index' property, which represents the index of the embedding in the list of embeddings. This index corresponds to the position of the input string in the array you provided.

Here is an example of the response structure:

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [
        -0.006929283495992422,
        -0.005336422007530928,
        ... (omitted for spacing)
        -4.547132266452536e-05,
        -0.024047505110502243
      ],
    }
  ],
  "model": "text-embedding-3-small",
  "usage": {
    "prompt_tokens": 5,
    "total_tokens": 5
  }
}

In this example, the 'index' property is 0, which means this embedding corresponds to the first string in the input array.

This behavior is also consistent with OpenAI's general approach to Structured Outputs, where outputs are produced in the same order as the ordering of keys in the schema.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: