Semantic search
Convert documents into vectors that can be indexed and compared for meaning.
AI & ML · Function
Creates numerical vector representations of text through the OpenAI embeddings API. These vectors can be used for semantic search, retrieval, and related machine-learning workflows.
Send text input and an embedding model name to the embeddings API. The response contains embedding vectors in its data collection, with one result corresponding to each supplied input item.
client.embeddings.create({ model, input })| Name | Type | Description |
|---|---|---|
input | string | string[] | Text string or array of text strings to convert into embedding vectors. |
model | string | Name of the embedding model, such as text-embedding-3-small. |
A response whose data items contain embedding vectors; one item is returned for each input text.
import OpenAI from "openai";
const client = new OpenAI();
const response = await client.embeddings.create({
model: "text-embedding-3-small",
input: ["A document about machine learning.", "A document about databases."]
});
console.log(response.data.map(item => item.embedding.length));Creates one embedding vector for each supplied text using the OpenAI embeddings API.
Convert documents into vectors that can be indexed and compared for meaning.
Represent a user question and compare it with stored document vectors.
Transform text into numerical features for downstream machine-learning processing.
The method accepts text input and a model identifier, then returns embedding vectors in the response data. For multiple inputs, provide an array and read the corresponding vector from each data item.
Follow-up: How would you embed a batch? Pass an array of strings as input and associate each returned data item with the input at the same position.
Use an embedding model such as text-embedding-3-small and provide the text to represent. The returned vector is available from the embedding field of each response item.
Follow-up: What should change when embedding several texts? Supply multiple strings in the input array and process every returned vector rather than only the first one.
The API response exposes results through data, and each result contains an embedding vector. The vector can then be used by an application for semantic comparison or retrieval workflows.
Follow-up: How can the output support retrieval? Store vectors and compare a query vector with stored vectors using a similarity method implemented by the retrieval system.
embeddings APItext-embedding-3-smallretrievalvector embeddings