liveBook · Manning

Chapter 4: Embeddings and vector search

What you will learn in chapter 4 of Building Reliable AI Systems

The introduction shows how embeddings enable RAG retrieval and why poor embedding quality can make an otherwise capable chatbot unreliable.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction shows how embeddings enable RAG retrieval and why poor embedding quality can make an otherwise capable chatbot unreliable.

Key terms: embedding model, dense vectors, vector space, similarity search, semantic retrieval, embedding quality, retrieval pipeline, domain, context, unreliable output

4.1 What are embeddings?

Defines embeddings as text vectors and explains how vector closeness enables meaning-based search.

Key terms: embedding, vector, high-dimensional space, semantically similar, semantic search, embedding-based retrieval, cosine similarity, dot product, vector magnitude

4.1.1 A mental model: Embeddings as coordinates in meaning space

The section uses a map metaphor to explain how embeddings place related text near one another and how that proximity supports retrieval.

Key terms: embedding model, meaning space, semantic similarity, embed, query, retrieval, high-dimensional vectors, 2D projection, spatial proximity

4.1.2 Why the model matters

Explains why the embedding model’s fit to both content and queries determines retrieval quality and affects the answers built on it.

Key terms: embedding model, content, queries, retrieval system

4.2 Embedding models in production

This section explains how embedding models turn text into vectors for retrieval and why the quality of those vectors affects whether an LLM receives relevant context.

Key terms: embeddings, vector, high-dimensional space, semantically similar, vector space, relevant documents, wrong context

4.2.1 Commercial models: Powerful but opaque

This section weighs the convenience and general-purpose performance of commercial embedding APIs against their reliability, privacy, and cost tradeoffs.

Key terms: commercial APIs, general domains, specialized domain, training data, fine-tune, per token or per request, latency, rate limits, data-privacy concerns, query embedding

4.2.2 Open source models: Flexible and transparent

This section explains the control offered by open source embedding models, gives examples suited to different retrieval needs, and identifies the costs and evaluation work they require.

Key terms: open source embedding models, fine-tune, semantic similarity, dense retrieval, E5, BGE, BGE-M3, all-MiniLM-L6-v2, model size, self-hosting infrastructure

4.2.3 Domain-specific models: Purpose-built precision

This section explains why domain-specific embedding models can improve retrieval for specialized text, but only when the model matches the domain.

Key terms: general-purpose embeddings, domain-specific models, domain-specific vocabulary

4.2.4 How to choose the right model

This section explains how to choose an embedding model by matching its capabilities and costs to the application rather than relying on a single performance score.

Key terms: embedding model, commercial APIs, open source, custom-tuned models, performance metrics, dimensionality, semantic nuance, Matryoshka Representation Learning (MRL), truncate dimensions, context-length capabilities

4.2.5 Embeddings across industries

Shows how industry-specific needs shape the choice of embedding model beyond benchmark performance.

Key terms: domain-specific models, instruction-tuned models, general-purpose embeddings, cross-domain performance, commercial APIs

4.2.6 Case study: Learning from Airbnb’s embedding journey

Airbnb’s search case study shows how embeddings can improve relevance when they are integrated with scalable retrieval, user-behavior signals, conventional filters, and ongoing evaluation.

Key terms: keyword matching, semantic understanding, embedding models, dual-encoder, two-tower, query encoder, listing encoder, precompute, implicit signals, query-listing pair

4.3 Beyond simple vectors: Hybrid and multistage retrieval

The section introduces dense retrieval as semantic vector search and notes that it has limitations in real-world applications.

Key terms: embedding models, vectors, semantic space, dense retrieval

4.3.1 The limitations of pure vector search

This section shows why retrieving the nearest embedding vectors can miss an answer that is present in the corpus, and why that failure matters for the LLM’s response.

Key terms: dense retrieval, semantic drift, recall limitations, top-k cutoff, domain gaps, hallucinate, top-k nearest vectors

4.3.2 Hybrid retrieval: Combining dense and sparse approaches

The section explains how hybrid retrieval combines semantic and keyword search, then outlines a typical way to merge their results.

Key terms: hybrid retrieval, dense retrieval, embeddings, sparse retrieval, BM25, BM25 search, vector similarity search, result sets, reranking

4.3.3 Multistage retrieval: Building precision through layers

This section explains why finding relevant documents is not enough and how multistage retrieval improves their ranking through filtering and reranking.

Key terms: hybrid search, recall, precision, multistage retrieval, broad retrieval, progressive filtering, precision reranking, bi-encoders, cross-encoders, document embeddings

4.3.4 Building a hybrid retriever: Hands-on implementation for an employee chatbot

This section builds an employee-policy hybrid retriever and uses example queries to show why keyword search, semantic search, and reranking work better together.

Key terms: BM25, E5 embeddings, top-k, cosine similarity, cross-encoder reranking, deduplication, dense embeddings, recall, precision, cross-encoder

4.4 Essential retrieval optimizations with embeddings and RAG

This section introduces the need for practical optimizations beyond retrieval algorithms to make a RAG prototype production-ready.

4.4.1 Metadata filtering: Beyond pure semantic search

The section explains why semantic search needs metadata, how a system can detect and apply metadata constraints, and how this improves retrieval results.

Key terms: semantic search, metadata filtering, document attributes, metadata extraction, structured attributes, semantic-classification tasks, intelligent query analysis, filtering intent, smart search, hard filters

4.4.2 Chunking strategies: Finding the right granularity

Explains how chunk size, document-aware boundaries, and overlap affect what a RAG system can retrieve.

Key terms: document chunking, small chunks, large chunks, relevance score, content-aware chunking, section-based chunking, paragraph-based chunking, function-preserving chunking, sliding-window, chunk overlap

4.5 Exploring vector storage and databases

This section introduces the scaling problem that motivates efficient vector search for RAG systems.

Key terms: RAG system, vector search, naive vector search

4.5.1 HNSW: The algorithm powering modern vector search

Explains how HNSW searches a layered vector graph efficiently and how its main index-building parameters trade accuracy for resource use.

Key terms: HNSW, small world structure, hierarchical navigation, ANNs, O(log n), M, efConstruction, accuracy, memory, indexing

4.5.2 FAISS: Industry-standard vector indexing

This section presents FAISS as a high-performance vector-search library, explains its limits, and compares when to use IVF or HNSW indexes.

Key terms: FAISS, HNSW, GPU acceleration, index analysis and tuning, persistence, metadata filtering, distributed search, vector databases, IVF, IVF-PQ

4.5.3 Vector databases: Complete vector storage solutions

This section explains how vector databases turn vector search into production-ready retrieval systems and compares options for different needs.

Key terms: vector databases, vector indexes, metadata, similarity searches, filtering, persistence and durability, incremental updates, horizontal scaling, replication, monitoring and observability tools

4.5.4 Vector database project: Building a health-care policy assistant with Pinecone

This section builds a health-care policy assistant by preparing policy chunks, storing their embeddings in Pinecone, retrieving relevant policies, and grounding an LLM’s answers in those results.

Key terms: chunks, overlap, section-title extraction, metadata, domain-appropriate model, embeddings, dense vectors, retrieval precision, Pinecone index, dimension

4.6 Practical challenges: Drift and compression

Introduces embedding drift and vector compression as practical challenges for live retrieval systems.

Key terms: embedding drift, user queries, vector representations, vector compression, high-dimensional embeddings, memory footprint, semantic properties

4.6.1 Embedding drift explained

Explains how embedding drift appears, why content or model changes cause it, and how consistent re-embedding keeps retrieval aligned.

Key terms: embedding drift, retriever, re-embed, model version, vector space

4.6.2 Diving deeper into vector compression

The section explains how vector compression reduces the storage and latency burden of large embedding indexes while preserving useful retrieval quality.

Key terms: vector compression, vector index, retrieval, product quantization, codebook, scalar quantization, binary quantization, approximate similarity, compressed vectors, first-pass search

4.7 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 3: Grounding outputs with RAG Chapter 5: Fine-tuning LLMs for improved performance →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.