Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI & ML · Const

embeddings

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.

How it works

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.

Syntax

client.embeddings.create(input=[text], model="text-embedding-3-small")

Parameters

NameTypeDescription
inputstring or array of stringsThe text string or strings to convert into embeddings.
modelstringThe name of the embedding model, such as text-embedding-3-small.

Returns

An embedding vector for each supplied input text.

Key points

  • Text embeddings quantify how related text strings are.
  • Typical applications include semantic search, clustering, recommendations, anomaly detection, diversity measurement, and classification.
  • The request requires input text and an embedding model name.
  • Similarity between vectors is useful as a proxy for similarity between the represented data.
  • Text embedding models accept strings and return vectors.

Common mistakes

  • Keep each input within the selected model’s maximum context length; embedding models do not produce output tokens.

Example: Create a text embedding

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.

When to use it

Search

Rank documents by semantic relevance to a natural-language query.

Clustering

Group texts or items according to vector similarity.

Recommendations

Suggest items whose text representations are related.

Anomaly detection

Identify items with unusually low relatedness to the rest of a collection.

Interview questions

QWhat is an embedding?

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.

QHow do you obtain an embedding?

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.

QWhat problems are embeddings useful for?

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-small
  • embeddings API
  • semantic search
  • clustering
  • recommendations
  • anomaly detection
  • classification

Source: Vector embeddings | OpenAI API. Checked 2026-10-15.