Course contentsShow
← Machine Learning and Deep Learning
Lesson 1947 of 3,53842. Retrieval-Augmented Generation: FoundationsFree lesson

Indexing Phase: From Documents to Searchable Chunks

How raw documents are processed, chunked, embedded, and stored in a vector database during the indexing phase.

Indexing Phase: From Documents to Searchable Chunks

What you'll learn: How RAG systems transform raw documents into searchable, embedded chunks stored in a vector database.

The Foundation of Retrieval

Before an LLM can retrieve relevant information, you need to prepare your knowledge base. The indexing phase is where raw documents—PDFs, web pages, databases—become searchable building blocks for your RAG system.

Think of it like preparing ingredients before cooking: you can't throw whole vegetables into a blender and expect smooth soup. Similarly, you can't feed entire documents directly to an LLM at query time.

The Four-Step Indexing Process

1. Document Loading

Your system ingests raw documents from various sources (files, APIs, databases). Each document might be thousands of words long.

2. Chunking

Documents are split into smaller, semantically meaningful pieces—typically 200-1000 tokens. Why? Because retrieval works best when chunks are self-contained and focused. Chunk boundaries might respect paragraph breaks, sentence boundaries, or semantic coherence.

3. Embedding

Each chunk is converted into a dense vector (embedding) using an embedding model. These vectors capture semantic meaning numerically—similar concepts produce similar vectors.

4. Storage

Chunks and their embeddings are stored in a vector database (like Pinecone, Weaviate, or FAISS). The database indexes these vectors for lightning-fast similarity search later.

Why This Matters

At query time, your user's question gets embedded using the same model, then compared against stored chunk embeddings. The most semantically similar chunks get retrieved and fed to the LLM as context—solving the knowledge cutoff problem you learned about earlier.

Key Takeaway: Indexing transforms unstructured documents into searchable, embedded chunks stored in a vector database, enabling fast semantic retrieval when users ask questions.