chapter four

4 Embeddings and vector search

 

This chapter covers

  • How embedding models power retrieval-augmented generation systems by mapping text into vector space
  • Seeing why embedding quality determines whether the right documents are retrieved
  • Choosing among commercial, open-source, and domain-specific embedding models based on your domain, constraints, and goals
  • Designing hybrid and multistage retrieval pipelines that combine dense, sparse, and reranking components for better precision
  • Building a hybrid retriever for an employee-policy chatbot

A major health-care company launched a chatbot designed to help patients navigate their insurance plans. It was built using retrieval-augmented generation (RAG), backed by a well-trained large language model (LLM) and connected to internal policy documents (figure 4.1). On paper, everything looked solid. The system had access to accurate information, and the model could generate fluent, helpful responses.

Figure 4.1 Document embedding in RAG systems
figure

But shortly after launch, users began reporting problems. The chatbot frequently failed to answer questions that should have been easy to answer. When someone asked whether physical therapy after surgery was covered, the model returned a vague reply or an “I don’t know” response, even though the answer was clearly stated in the documents it had access to. In some cases, it gave outdated or incorrect information.

4.1 What are embeddings?

4.1.1 A mental model: Embeddings as coordinates in meaning space

4.1.2 Why the model matters

4.2 Embedding models in production

4.2.1 Commercial models: Powerful but opaque

4.2.2 Open source models: Flexible and transparent

4.2.3 Domain-specific models: Purpose-built precision

4.2.4 How to choose the right model

4.2.5 Embeddings across industries

4.2.6 Case study: Learning from Airbnb’s embedding journey

4.3 Beyond simple vectors: Hybrid and multistage retrieval

4.3.1 The limitations of pure vector search

4.3.2 Hybrid retrieval: Combining dense and sparse approaches

4.3.3 Multistage retrieval: Building precision through layers

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