Hot AI News

Text embeddings: How AI turns the meaning of a sentence into numbers it can compare

An embedding turns a sentence into a list of numbers so that similar meanings land close together. It powers search, clustering and topic analysis such as Anthropic's Clio.

Text embeddings: How AI turns the meaning of a sentence into numbers it can compare
Photo illustration: Aiholics

A text embedding is a list of numbers that stands for the meaning of a piece of text. Sentences that mean similar things get lists that are close together, and unrelated sentences get lists that are far apart. That lets software compare meaning with simple arithmetic instead of matching exact words.

OpenAI’s documentation defines an embedding as a vector, a list of floating point numbers, where the distance between two vectors measures how related they are.

A library shelved by meaning instead of by title

Picture a library where books are shelved by what they are about, not by the alphabet. A book on sourdough sits next to a book on baking bread. A book on tax law is on the far side of the building. To find related books, you walk to a spot and look around.

An embedding gives every piece of text such a spot. The spot is not two-dimensional like a floor plan. It has hundreds or thousands of coordinates, and each coordinate captures some faint aspect of meaning. Nobody labels these aspects by hand. The model learns them from data.

This is why a search for “cheap flights to Rome” can find a page that says “low-cost airfare to Italy”. The two share almost no words, but their spots are close.

Advertisements

From text to a point: What the model does and how closeness is measured

A touchscreen kiosk in a bright library shows an abstract sentence becoming a vector of colored cells and a point connected to nearby points.
Photo illustration: Aiholics

An embedding model is a neural network trained to read text and output a fixed-length vector. Text goes in, and a list of numbers comes out. OpenAI’s text-embedding-3-small returns 1,536 numbers by default, and text-embedding-3-large returns 3,072, according to the company’s documentation. An open sentence model used in Anthropic’s Clio research, all-mpnet-base-v2, returns 768.

To compare two vectors, software usually computes cosine similarity. It measures the angle between the two lists. Vectors that point the same way score high, and vectors that point in different directions score low. OpenAI’s guide describes ranking documents by the cosine similarity between the query vector and each document vector.

Comparison is only half the job. Once every text is a point, other tools can work on the points:

  • Search: find the stored texts nearest to a query.
  • Clustering: group points that sit near each other.
  • Recommendations and classification: suggest or label items by their neighbors.
  • Anomaly detection: flag points that sit far from everything else.

OpenAI lists search, clustering, recommendations, anomaly detection, diversity measurement and classification among the uses.

Where the idea came from: Word vectors in 2013, sentence vectors in 2019

The modern version began with words. In 2013, Tomas Mikolov, Kai Chen, Greg Corrado and Jeffrey Dean at Google published “Efficient Estimation of Word Representations in Vector Space”. They proposed two model designs for learning continuous vector representations of words from very large data sets. They reported learning high-quality vectors from a 1.6 billion word data set in under a day, and strong results on tests of word similarity.

Words alone were not enough. Search and clustering need whole sentences. In 2019, Nils Reimers and Iryna Gurevych published Sentence-BERT at EMNLP, a major language-processing conference. BERT, a popular language model from 2018, could judge whether two sentences match, but only by reading both together. The authors noted that finding the most similar pair among 10,000 sentences takes about 50 million BERT computations, roughly 65 hours.

Their fix was to change BERT so that each sentence gets its own embedding that can be compared with cosine similarity. The same search took about 5 seconds in their report, with accuracy kept at BERT’s level. The work is why embedding every document once, then comparing cheaply, became the standard recipe.

Advertisements

Clustering chats by meaning without reading them

Embeddings are the quiet middle step in the privacy-preserving usage analysis that Anthropic calls Clio, which Aiholics covered in its news story on privacy-preserving usage analysis. In the 2024 Clio paper (arXiv:2412.13678), Alex Tamkin and colleagues at Anthropic describe the process in a few steps:

  1. A model first writes a short, scrubbed summary of each conversation.
  2. Each summary is embedded. The paper’s appendix names all-mpnet-base-v2, a sentence-transformer model that provides 768-dimensional embeddings, from Reimers and Gurevych.
  3. The embeddings are grouped with k-means clustering, a method from Stuart Lloyd’s 1982 work. It splits the points into a chosen number of groups, k, so that each point sits near the center of its group.
  4. A language model then names and describes each cluster, and the clusters are arranged into a hierarchy.

The paper says the embedding step is applied to a natural-language facet such as the conversation topic. Because of this, thousands of near-identical requests, such as “debug my Python script”, fall into one group that an analyst can see as a single labeled box. The paper reports analyzing one million Claude.ai Free and Pro conversations this way.

Where embeddings mislead

Closeness in embedding space is a statistical hint, not a verdict. Several limits are worth knowing.

  • The model decides what counts as similar. A model trained mostly on one kind of text may place texts from another domain badly. Two embedding models can disagree about the same pair of sentences.
  • The numbers are hard to read. No single coordinate means “cooking” or “anger”. Meaning is spread across all of them, so a surprising match is hard to explain.
  • Clustering needs choices. With k-means, someone must pick the number of groups. Too few merges distinct topics, and too many splits one topic. The Clio paper says the value of k varies with dataset size.
  • Similar is not the same. A sentence and its negation can land close together, because they share topic and vocabulary. Embeddings are good for finding related material and weaker at telling whether two statements agree.

For the privacy use, there is one more point. An embedding is made from the text, so it can carry information about it. In Clio, the embedding runs on summaries that a model was told to scrub of private details, and Anthropic describes several layered safeguards on top. The embedding step by itself is not what protects anyone.

Advertisements

What to watch as embeddings spread

Embeddings sit under retrieval systems, recommendation features and many analysis tools, so changes to them show up in many products at once. Three things are worth following.

  • Size and cost. OpenAI’s documentation notes a dimensions parameter that shortens vectors, which trades some accuracy for cheaper storage and faster search.
  • Benchmarks. OpenAI cites the Massive Text Embedding Benchmark (MTEB) scores of 62.3% for text-embedding-3-small and 64.6% for text-embedding-3-large. Vendor scores on one benchmark do not guarantee better results on a specific company’s data, so testing on your own text matters.
  • New media. The same idea now covers images, audio and video in a shared space, which extends search by meaning beyond text.

For readers, the practical takeaway is simple. When a product claims it can group, search or summarize by meaning, an embedding is very likely doing the first step, and the quality of the whole system depends on how well that step was done.

Sign Up for the Daily AI Pulse

One email a day. All the stories that matter.

Daniel ReedAI Research, Safety & Ethics Analyst

Daniel Reed currently works as an AI Research, Safety & Ethics Analyst at Aiholics, writing about how changes in artificial intelligence are affecting and will affect scholarship,…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like