Search⌘ K
AI Features

Embeddings

Explore how to use the OpenAI embeddings endpoint to transform text into numerical vectors for machine learning. Learn to calculate semantic similarity using cosine similarity and apply embeddings in practical NLP applications like anomaly detection and text clustering.

The embeddings endpoint

Embedding is a method to represent the data in a vector of continuous numbers. We can provide these vectors to machine learning algorithms and models. Similar texts will have the same embedding vectors, and two different texts will have very different embeddings. OpenAI API takes text as input and returns the embedding vector.

Embeddings
Embeddings

The Embeddings API call

To get an embeddings vector for a chunk of text, we can call the following function:

response = client.embeddings.create(
input="The text whose embeddings are required",
model="<model_name>"
)

Understanding the embeddings endpoint

Let’s look at the embeddings endpoint in more detail, reviewing the request parameters and the response parameters.

Request parameters

Let’s look at the parameters that are required to make a request at the embeddings endpoint. ...