Skip to content
mentoor

Topic 5 of 5 · 3 min read

Token embeddings versus text embeddings

Goal: Tell the token embeddings inside an LLM apart from the text embeddings an embedding model returns, and say which a search feature needs.

A token embedding is a vector for one token inside a language model, while a text embedding is one vector for a whole sentence or passage that an embedding model returns for you to use. They share a name and an idea, but they are different things used for different jobs.

Check yourself · 1 of 3

What is a token embedding?

Choose one answer

Why it matters

People often hear that "an LLM turns words into embeddings" and then try to build search by pulling vectors out of a chat model. Or they read about embeddings in a paper and assume they are the same object as the vectors in a search API. Keeping the two apart saves time and avoids a broken design.

Token embeddings

A language model such as the ones behind Claude, ChatGPT, Gemini or Llama first cuts text into tokens, which are small pieces such as words or word parts. Each token has an entry in a big lookup table. That entry is its token embedding, a list of numbers learned during training.

These vectors are the model's first layer. The model then passes them through many more layers that mix in context. They are an internal detail. You normally do not see them, and one token's vector does not know about the sentence around it.

Text embeddings

An embedding model is built for one job: turn a whole text into one vector, so that similar texts land close together. It is trained for exactly that, often with pairs of texts that mean the same thing. It returns one vector per input, ready to store and compare.

Inside, an embedding model also uses token embeddings, then layers that mix in context, then combines everything into a single vector. So token embeddings are one building block of a text embedding, not a rival to it.

Which one does search need?

A search feature needs text embeddings from an embedding model. A chat model is trained to predict the next token, not to place similar texts near each other. Averaging its internal vectors can work poorly for search.

Before and after

Before: "We will take the first-layer vectors from our chat model and average them to search our documents." The results are noisy, because that model was never trained for similarity.

After: "We call an embedding model, store one vector per passage, and compare them." The results are far more useful, and the cost is low.

What goes wrong

  • Mixing the terms in a meeting. One person means the input layer of a chat model, another means an API that returns sentence vectors. Ask which one is meant.
  • Expecting a single word's vector to hold sentence meaning. A token embedding is the same for "bank" in "river bank" and "bank loan"; context layers come later.
  • Using a chat model where an embedding model fits. It is slower and usually less accurate for search.

Examples

Two kinds of vector side by side

Token embedding Text embedding
Covers One token A sentence or passage
Where it lives Inside a language model Returned by an embedding model
Knows the context? No, added in later layers Yes, built from the whole text
You use it for Nothing directly Search, clustering, RAG

Optional code: which call do you want?

# Text embedding: one vector for the whole passage. Use this for search.
vec = client.embeddings.create(
    model="text-embedding-3-small",
    input="Refunds are issued within 14 days.",
).data[0].embedding

# Token ids are not embeddings. They are only the lookup keys.
ids = tokenizer.encode("Refunds are issued within 14 days.")

The token ids point into the model's internal table. The vector you store for search comes from the embeddings call.

Key points

  • A token embedding is the vector for one token inside a language model's first layer.
  • A text embedding is one vector for a whole sentence or passage, returned by an embedding model.
  • Token embeddings are a building block inside text embedding models, not a replacement for them.
  • A search or clustering feature needs text embeddings from a model trained for similarity.
  • A token's own vector does not change with the sentence around it; context is added by later layers.

Common mistakes

  • Thinking the vectors inside a chat model can be used directly for search.
  • Assuming a token's vector depends on its sentence; that happens only in later layers.
  • Using the word embedding for both ideas in a team discussion without saying which one.

Check yourself · 2 of 3

You are building semantic search over your company's documents. Which vectors do you need?

Choose one answer

Check yourself · 3 of 3

A teammate says: 'The word bank has the same token embedding in river bank and bank loan.' Is this correct?

Choose one answer

Practice items, not counted towards your mastery.

Start here