Embedding Models: Architecture, Pooling & Selection › Embedding Model Architecture and Selection

Michael BrenndoerferJanuary 24, 20264 min read
Language AI HandbookAll chapters
Part 44 of 67Retrieval-Augmented Generation
Chapter 337Embedding Models: Architecture, Pooling & Selection › Embedding Model Architecture and Selection
Reading section 1 of 12 · Embedding Model Architecture and Selection · 4 minSection 1 of 12 · 4 min

Book contents

Section 1 of 12 · 4 min read

Embedding Models: Architecture, Pooling & Selection › Embedding Model Architecture and SelectionOne section · Sections in this chapter1 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

In the previous chapters on dense retrieval and contrastive learning, we established why we need dense vector representations and how models learn to place semantically similar texts near each other in vector space. We explored the mechanics of contrastive loss functions and saw how training pairs can sculpt a continuous geometry of meaning. However, we did not address a necessary question: how does a transformer, which produces a sequence of token-level hidden states, yield a single vector that represents an entire sentence or paragraph? The answer lies in the architecture and design choices of embedding models, the specialized systems that convert variable-length text into fixed-dimensional vectors suitable for similarity search.

Embedding models sit at the heart of every RAG pipeline. The quality of your retrieval, and therefore the quality of your generated answers, depends directly on how well your embedding model captures semantic meaning. A poorly chosen or misconfigured embedding model will return irrelevant chunks no matter how sophisticated the rest of your pipeline is. You could have the most advanced reranker, the most carefully designed prompts, and the most capable generative LLM in the world, but if your retriever returns the wrong passages, none of that sophistication can compensate. The embedding model is the foundation on which everything else stands.

Think of an embedding model as a very sophisticated filing system. When you file a document, you decide what folder it belongs in, and later you can retrieve it by looking in the right folder. An embedding model does something far more fine-grained: it places each piece of text at a precise coordinate in a high-dimensional space, where the coordinates encode the text's meaning. Documents about similar topics land near each other; documents about unrelated topics land far apart. When a query arrives, you convert it to coordinates in the same space and look for nearby documents. The quality of this "filing" determines everything about your retrieval system's accuracy.

This chapter examines embedding models from the inside out. We'll start with the architectural foundations and the non-trivial problem of distilling a sequence into a single vector. Then we'll explore the pooling strategies that perform this distillation, examining each one's mathematical properties and practical implications. We'll discuss the role of embedding dimensionality, including the elegant Matryoshka technique that allows a single model to serve multiple dimensionality requirements. We'll work through a concrete numerical example that makes these concepts tangible. Finally, we'll cover how to select and evaluate a model before deploying it for your use case, including limitations you need to be aware of.

Historical Context

The challenge of creating sentence-level representations from word-level models predates transformers. Early approaches averaged word2vec or GloVe vectors, which worked reasonably well for short texts but failed to capture word order, negation, and compositional meaning. The InferSent model (2017) used BiLSTMs trained on natural language inference data to produce better sentence embeddings. The Universal Sentence Encoder (2018) used transformer architectures but relatively shallow ones. Sentence-BERT (2019) marked a turning point by showing that deep transformer encoders, fine-tuned with siamese networks and contrastive objectives, could produce dramatically better semantic embeddings than any prior approach. Since then, the field has advanced rapidly, with modern models like E5-Mistral and GTE-Qwen2 using billion-parameter LLMs as embedding backbones.