liveBook · Manning

Chapter 8: Advanced indexing

What you will learn in chapter 8 of AI Agents and Applications

The chapter introduction explains why a basic RAG setup can produce poor answers and why improving it requires refining retrieval and application design.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduction explains why a basic RAG setup can produce poor answers and why improving it requires refining retrieval and application design.

Key terms: Retrieval-Augmented Generation (RAG), vector store, indexing, metadata, retrieval strategies

8.1 Improving RAG accuracy

This section frames RAG accuracy as something to improve by examining both content ingestion and question answering, step by step.

Key terms: RAG accuracy, content ingestion, question-answering (Q&A) workflows

8.1.1 Content ingestion stage

This subsection explains why simple content indexing can weaken RAG retrieval and identifies chunking and embeddings as ways to improve it.

Key terms: content ingestion, basic indexing, embedding calculations, text chunks, vector store, chunk size, overlap length, additional embeddings, chunk features

8.1.2 Question-answering stage

This section identifies common reasons a RAG question-answering stage gives weak answers and pairs each problem with a high-level remedy.

Key terms: poor question formulation, ineffective question for retrieval, subquestions, vector stores, structured data sources, relational databases, graph databases, structured queries, routing, irrelevant search results

8.2 Advanced document indexing

This section explains how document indexing choices affect the relevance and accuracy of chunks retrieved for RAG answers.

Key terms: text chunks, splitting strategy, chunk overlap, document hierarchy, embedding strategy, embeddings, metadata, multiple indexes, sentence expansion, surrounding sentences

8.3 Splitting strategy

This section explains how chunk size affects RAG retrieval and answer context, and why it should match the kinds of questions users will ask.

Key terms: RAG ingestion phase, chunks, embeddings, metadata, vector similarity searches, granular chunks, coarse chunks, chunk size, expected query type, retrieval performance

8.3.1 Splitting strategies

This section compares splitting documents by their natural hierarchy with splitting them into fixed-size chunks, including the trade-offs of each approach.

Key terms: splitting by document hierarchy, splitting by absolute size, chunk size

8.3.2 Factors to consider

This section identifies document type and search type as factors when choosing a document-splitting strategy.

Key terms: document type, document hierarchy, fixed-size approach, metadata search, chunk granularity, tags

8.3.3 Choosing the right strategy

This section explains that choosing a document-splitting strategy depends on the documents and the desired balance between hierarchy and chunk size.

Key terms: document hierarchy, absolute size, splitting strategy

8.3.4 Splitting by HTML header

This section sets up granular HTML-header chunks and coarser chunks in separate Chroma collections so their retrieval results can be compared.

Key terms: H1 and H2 tags, granular chunks, coarse chunks, HTMLSectionSplitter, RecursiveCharacterTextSplitter, ChromaDB collection, uk_destinations

8.4 Embedding strategy

This section introduces multi-vector indexing, explains its two-layer chunk structure, and recommends testing strategies against the structure of your text.

Key terms: multiple vectors per document, synthesis chunks, retrieval chunks, embeddings, multi-vector retriever techniques, structure of your text

8.4.1 Embedding child chunks with ParentDocumentRetriever

This section explains how ParentDocumentRetriever uses small child chunks for precise matching while returning larger parent chunks with enough context for an LLM answer.

Key terms: large chunks, small chunks, context, detail, ParentDocumentRetriever, parent chunks, child chunks, document store, vector store, embeddings

8.4.2 Embedding child chunks with MultiVectorRetriever

The section presents MultiVectorRetriever as a way to link embedded child chunks to larger parent chunks and compares its search results with direct search on child chunks.

Key terms: MultiVectorRetriever, parent splitters, child splitters, ingestion, parent chunks, child chunks, direct semantic search, synthesis

8.4.3 Embedding document summaries

This section shows how embedding summaries of coarse chunks can improve retrieval while still returning larger chunks for context.

Key terms: coarse chunks, summary embeddings, search precision, MultiVectorRetriever, direct semantic search, summaries, broader context, summarization chain, InMemoryByteStore, child embeddings

8.4.4 Embedding hypothetical questions

The section explains how embeddings of questions a document chunk could answer can improve retrieval when a user’s question does not closely match the chunk’s wording.

Key terms: hypothetical questions, embeddings, vector store, semantic similarity, MultiVectorRetriever, coarse chunks, structured output, hypothetical question embeddings

8.5 Granular chunk expansion

This section explains how chunk expansion preserves granular search while giving the LLM more surrounding context for complete answers.

Key terms: granular chunks, chunk expansion, MultiVectorRetriever, vector store, document store, expanded chunks

8.6 Semi-structured content

This section explains how to index mixed text and tables so a search can retrieve the full content needed for an answer.

Key terms: semi-structured content, MultiVectorRetriever, document store, vector store, table summary

8.7 Multimodal RAG

This section sketches how multimodal RAG uses an image summary to find and return a raw image for response generation.

Key terms: multimodal LLM, image summary, embeddings, document store, MultiVectorRetriever, raw image

8.8 Summary

This summary explains how advanced indexing can improve RAG retrieval by choosing suitable document splits, preserving context around matches, and preparing semi-structured content.

Where this is used later

Concepts explained in this chapter

← Chapter 7: Q&A chatbots with LangChain and LangSmith Chapter 9: Question transformations →

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.