openai.createEmbedding

Creates an embedding vector representing the input text.

Syntax

createEmbedding(params)

Parameters

Return value

An object containing response from OpenAI API.

await openai.createCompletion({
  model: "text-davinci-003",
  prompt: "In the future, AI will",
  max_tokens: 7,
  temperature: 0,
})
{
  object: list,
  data: [{
          object: embedding,
          index: 0,
          embedding: [-0.004836373, 0.0048300717, -0.016484628, -0.024437075, -0.017291216, 0.012451692, -0.01908083, 0.009074107, -0.010157959, -0.026995469, 0.022798695, 0.010384812, -0.023479253, -0.006597632, 0.007939843, 0.0026261348, 0.02514284, -0.012130317, 0.012880191, 0.013119646, -0.010542348, -0.0035256688, 0.0040077306, 0.008582593, -0.020656196, -0.0018479042, 0.01223114, -0.019181654, 0.030473877, -0.0310032, 0.0035823819, -0.007820116, -0.006049405, -0.017807936, 0.0049025384, -0.015640233, 0.0013941987, -0.015514202, 0.019521933, -0.016093938, 0.007221477, 0.008387248, 0.01145606, -0.013901028, -0.033322137, 0.011355237, 0.004310201, -0.0127478605, -0.0013839589, 0.028280968, 0.025432706, 0.00073215127, -0.016308187, 0.017492862, -0.016459422, 0.008425057, -0.03312049, 0.031154435, 0.032465138, -0.021349357, 0.0033145698, 0.0055925488, -0.007763403, 0.006093515, 0.00632982, 0.01687532, 0.0036453966, 0.007681484, -0.01885398, 0.026088059, 0.024676532, 0.0054885745, -0.0015730028, -0.004782811, 0.018438082, 0.0031018953, -0.011430855, -0.0020211944, 0.005072678, 0.0022370196, 0.036069576, -0.027373556, -0.0084754685, 0.015425982, 0.018967405, 0.0019566044, -0.0032925147, 0.020870447, -0.014417748, -0.024979, 0.012558817, 0.01386322, 0.006855992, 0.008557388, -0.015236938, -0.0029144268, -0.0086330045, 0.016761893, 0.004171569, -0.048042357, ...]
        }],
  model: text-embedding-ada-002-v2,
  usage: {
           prompt_tokens: 2,
           total_tokens: 2
         }
}

External resources