Search
Rank documents by semantic relevance to a natural-language query.
AI & ML · Const
Embeddings convert text into vectors that preserve aspects of its content or meaning. Comparing these vectors enables semantic search, clustering, recommendations, anomaly detection, diversity measurement, and classification.
The embeddings API transforms input text into a numeric vector intended to preserve aspects of the text's content or meaning. Applications compare these vectors to support semantic similarity tasks such as search, clustering, recommendations, anomaly detection, and classification.
client.embeddings.create(input=[text], model="text-embedding-3-small")| Name | Type | Description |
|---|---|---|
input | string or array of strings | The text string or strings to convert into embeddings. |
model | string | The name of the embedding model, such as text-embedding-3-small. |
An embedding vector for each supplied input text.
from openai import OpenAI
client = OpenAI()
text = "Semantic search finds related meaning."
result = client.embeddings.create(
model="text-embedding-3-small",
input=text,
)
vector = result.data[0].embedding
print(len(vector))Creates an embedding vector for a text string and prints its dimensionality.
Rank documents by semantic relevance to a natural-language query.
Group texts or items according to vector similarity.
Suggest items whose text representations are related.
Identify items with unusually low relatedness to the rest of a collection.
An embedding is a vector representation of data that aims to preserve aspects of its content or meaning. Related data tends to produce vectors that are closer together than unrelated data.
Follow-up: How would you use embeddings for retrieval? Generate vectors for documents and queries, then rank documents by vector similarity.
Send the text string and embedding model name to the embeddings endpoint. The response contains the resulting embedding vector for the input.
Follow-up: What should be persisted for later search? Store document vectors with their source identifiers and metadata, then embed incoming queries with the same model.
Common applications include search, clustering, recommendations, anomaly detection, diversity measurement, and classification. These tasks use relationships between vectors to find similar or unusual text.
Follow-up: Why is chunking useful for document search? It lets retrieval compare a query with focused portions of a document instead of one vector representing the entire document.
text-embedding-3-smallembeddings APIsemantic searchclusteringrecommendationsanomaly detectionclassification