{
  "version": "https://jsonfeed.org/version/1",
  "title": "Machine learning on LLBBL Blog",
  "icon": "https://avatars.micro.blog/avatars/2023/40/125738.jpg",
  "home_page_url": "https://llbbl.blog/",
  "feed_url": "https://llbbl.blog/feed.json",
  "items": [
      {
        "id": "http://llbbl.micro.blog/2026/07/16/what-are-embeddings-really-and.html",
        "title": "What Are Embeddings, Really? (And Why You Can't Just Use GPT-4 to Make Them)",
        "content_html": "<p>If you&rsquo;ve built a RAG pipeline, a semantic search box, or an AI agent with vector-backed memory, you&rsquo;ve used embeddings. You probably called a Mistral or Gemini embedding endpoint, took the array of floats that came back, dumped it into pgvector or Qdrant, and moved on with your day. I&rsquo;ve done this a lot in the last few months.</p>\n<p>But what <em>are</em> those numbers? And why do we need a whole separate model to make them? Why can&rsquo;t I just ask GPT-4 or Claude, which can generate remarkably fluent language, to hand me a vector?</p>\n<p>Part of the answer comes down to a fork in the road inside the Transformer architecture. The rest comes down to how a model is trained and how its output gets turned into one vector. Let me walk you through it.</p>\n<h2 id=\"embeddings-are-just-coordinates\">Embeddings Are Just Coordinates</h2>\n<p>Strip away the jargon and an embedding is a set of coordinates. Picture a giant map of meaning. Similar ideas sit close together, unrelated ideas sit far apart.</p>\n<ul>\n<li><strong>React</strong> and <strong>Vue</strong> land near each other, say around <code>[0.82, 0.19, -0.45]</code>.</li>\n<li><strong>Frontend</strong> sits right next door at <code>[0.79, 0.22, -0.41]</code>.</li>\n<li><strong>Python</strong> and <strong>Sourdough fermentation</strong> are off on different continents entirely.</li>\n</ul>\n<p>When we turn text into these long lists of numbers, we let a computer measure meaning with plain geometry. Depending on the model, a vector may have hundreds or thousands of dimensions. OpenAI models, for example, have used <strong>1,536</strong> or <strong>3,072</strong>, while Mistral Embed uses <strong>1,024</strong>. A common comparison tool is <strong>cosine similarity</strong>. The machine has no idea what &ldquo;React&rdquo; means. It just notices that the angle between the React vector and the Vue vector is tiny, so they must be related. That&rsquo;s the whole trick.</p>\n<h2 id=\"the-fork-encoders-vs-decoders\">The Fork: Encoders vs. Decoders</h2>\n<p>The original 2017 Transformer had two halves, and modern models tend to pick one and run with it. This comparison is simplified, but it captures the two families that matter here.</p>\n<pre tabindex=\"0\"><code>            THE ORIGINAL TRANSFORMER (Vaswani et al., 2017)\n                                |\n        +-----------------------+-----------------------+\n        v                                               v\n  ENCODER-ONLY (BERT, DeBERTa)              DECODER-ONLY (GPT-style, Llama)\n  - Bidirectional attention                 - Causal (masked) attention\n  - Every token sees surrounding text       - Each position sees current/earlier tokens\n  - Often used for embeddings               - Predicts the next token\n  - Strong at classification                - Strong at generation, reasoning, chat\n</code></pre><p>That architecture helps explain why a general-purpose chat model is not automatically a good embedding model.</p>\n<h3 id=\"chat-llms-commonly-use-decoder-style-attention\">Chat LLMs commonly use decoder-style attention</h3>\n<p>GPT-style and Llama models use decoder-only architectures. Their job is to predict the next token based on the tokens so far. Decoders use <strong>causal masking</strong> to prevent a position from attending to later tokens. The hidden state at token #3 can use tokens #1 through #3 to predict token #4, but it cannot use token #4 itself.</p>\n<p>That&rsquo;s ideal for generating text one token at a time, but the raw hidden states are not automatically good whole-passage embeddings. Early token states cannot incorporate later context, although the final token state can represent the entire preceding input. With the right pooling and retrieval training, decoder-based models can still produce strong embeddings.</p>\n<h3 id=\"many-embedding-models-use-bidirectional-encoders\">Many embedding models use bidirectional encoders</h3>\n<p>Many dedicated embedding models use BERT-style <strong>bidirectional attention</strong>. They do not use a causal mask between ordinary content tokens during embedding inference, so each token can incorporate context from both before and after it. The system then turns those contextual token states into one vector using mean pooling, a special token, a learned pooling layer, or another strategy.</p>\n<p>Encoder architecture alone is not enough, though. A useful embedding space also depends on the pooling method and training objective. One model may start out optimized to predict the next token, while another is trained so whole passages with related meanings end up near each other.</p>\n<h2 id=\"why-you-cant-just-ask-a-chat-model\">Why You Can&rsquo;t Just Ask a Chat Model</h2>\n<p>You can ask GPT-4 or Claude to print a list of numbers, but the response is still generated text. A number like <code>0.82</code> is emitted as tokens representing that number. The API is not handing you one of the model&rsquo;s internal vectors.</p>\n<p>That distinction matters because useful embeddings must share a stable coordinate system. If two passages mean similar things, the model needs to place them near each other, request after request. The vectors need a consistent number of dimensions, a defined pooling strategy, and training that makes distance meaningful.</p>\n<p>A chat model&rsquo;s normal output gives you none of those guarantees. It predicts the next token and sends the generated tokens back. An embedding endpoint returns a fixed-length numerical representation designed for similarity, retrieval, and related tasks.</p>\n<p>The chat model is still using vectors internally. Those vectors simply are not what you receive from its chat API. Anthropic does not offer its own embedding model at all, and its documentation points developers to a separate embedding provider.</p>\n<p>You <em>can</em> take an open-weight decoder model, extract its hidden states, add a pooling strategy, and train it for retrieval. Decoder-based embedding models do exactly that. But at that point, you have turned the decoder into an embedding model. You are no longer just asking a chat model to give you a vector.</p>\n<p>So the next time you reach for an embedding, use the model built for it. Your chat model is built for another task entirely.</p>\n<h2 id=\"sources\">Sources</h2>\n<ul>\n<li><a href=\"https://arxiv.org/abs/1706.03762\">Vaswani et al. (2017), Attention Is All You Need</a> — The paper that introduced the attention-based Transformer encoder-decoder architecture.</li>\n<li><a href=\"https://arxiv.org/abs/1810.04805\">Devlin et al. (2018), BERT</a> — How bidirectional Transformer encoders build contextual token representations.</li>\n<li><a href=\"https://arxiv.org/abs/1908.10084\">Reimers and Gurevych (2019), Sentence-BERT</a> — How pooling and task-specific training turn BERT into useful sentence embeddings.</li>\n<li><a href=\"https://arxiv.org/abs/2212.03533\">Wang et al. (2022), E5</a> — An example of weakly supervised contrastive training for general-purpose text embeddings.</li>\n<li><a href=\"https://arxiv.org/abs/2401.00368\">Wang et al. (2024), Improving Text Embeddings with Large Language Models</a> — Evidence that decoder-only models can become strong embedding models with retrieval-specific training.</li>\n<li><a href=\"https://sbert.net/docs/sentence_transformer/loss_overview.html\">Sentence Transformers Loss Overview</a> — The range of contrastive, ranking, regression, distillation, and autoencoding objectives used to train embedding models.</li>\n<li><a href=\"https://openai.com/index/new-embedding-models-and-api-updates/\">OpenAI Embedding Models</a> — Examples of 1,536- and 3,072-dimensional embeddings.</li>\n<li><a href=\"https://docs.mistral.ai/resources/cookbooks/mistral-embeddings-embeddings\">Mistral Embeddings Guide</a> — Mistral Embed&rsquo;s 1,024-dimensional output and retrieval use cases.</li>\n<li><a href=\"https://ai.google.dev/gemini-api/docs/embeddings\">Google Gemini API Embeddings Guide</a> — How asymmetric query vs. document task types work in practice.</li>\n<li><a href=\"https://docs.anthropic.com/en/docs/build-with-claude/embeddings\">Anthropic Embeddings Guide</a> — Anthropic&rsquo;s documentation that Claude does not provide an Anthropic embedding model.</li>\n<li><a href=\"https://huggingface.co/spaces/mteb/leaderboard\">Hugging Face MTEB Leaderboard</a> — Standard benchmark for comparing embedding models head to head.</li>\n</ul>\n<hr>\n<blockquote>\n<p>I&rsquo;d appreciate a follow. You can subscribe with your email below. The emails go out once a week, or you can find me on Mastodon at <a href=\"https://micro.blog/llbbl?remote_follow=1\">@logan@llbbl.blog</a>.</p>\n</blockquote>\n",
        "date_published": "2026-07-16T10:00:00-05:00",
        "url": "https://llbbl.blog/2026/07/16/what-are-embeddings-really-and.html",
        "tags": ["AI","Rag","Embeddings","Machine learning"]
      }
  ]
}
