Introduction

Building a Retrieval-Augmented Generation (RAG) application requires careful preparation of data before it can be effectively retrieved and used by large language models (LLMs). Preprocessing ensures that information is broken down, represented, and stored in ways that maximize efficiency and semantic coherence. The three critical components of preprocessing for RAG are chunking, embeddings, and metadata.

Step 1: Chunking

Chunking is the first and most critical preprocessing step in building Retrieval-Augmented Generation (RAG) applications. It involves splitting documents into smaller, semantically coherent units that can be consumed by embedding models and large language models (LLMs). Effective chunking ensures that data is consumable, coherent, and contextual, enabling accurate retrieval and generation.

The Three Cs of Chunking

1. Consumable

2. Coherent

3. Contextual

Key Chunking Parameters

1. Chunk Size

2. Chunk Overlap

Purpose:

Example: Including the last sentence of one chunk at the start of the next.

3. Special Characters

Chunking Strategies by Text Type

Chunking strategies vary depending on the type of text being processed. Different document structures require different approaches to ensure that chunks remain consumable, coherent, and contextual. This section explores three common types of text data—document data, Q/A transcripts, and chat transcripts—and how chunking applies to each.

1. Document Data

Examples:

Defining Features:

Chunking Approach:

Use Case:

2. Q/A Transcripts

Examples:

Defining Features:

Chunking Approach:

Use Case:

3. Chat Transcripts

Examples:

Defining Features:

Chunking Approach:

Use Case:

Step 2: Embeddings

What Are Embeddings?

Choosing the Right Embedding Model

Three critical considerations guide model selection:

Embedding Size (Dimensionality)

Model Size

Training Data

Types of Embedding Models

Neural Network-Based

Examples:

Algorithmic Models (Non-Neural)

Examples:

What to Embed

Techniques:

Non-English Embeddings: Embedding models trained on English data often fail to capture nuances in other languages. Models like GPT-4, Mixtral, or Queen support multiple languages but may be computationally expensive. The MTEB leaderboard lists models trained on specific languages (French, Polish, Chinese, etc.), offering more efficient and domain-specific embeddings.

Comparing Embeddings

Dense Vector Metrics

Sparse/Binary Metrics

Step 3: Metadata

What Is Metadata?

Types of Metadata

Metadata can be broadly divided into two categories:

1. Chunking Metadata

Usage:

2. Non-Chunking Metadata

Usage:

Why Metadata Matters in RAG

Storing Metadata

There are two main approaches:

Linked Storage

Advantage: Separation of concerns, useful for complex relational queries.

Direct Storage in Vector Database

Advantage: Faster retrieval and simpler integration for RAG applications.

Most popular approach in modern vector databases (e.g., Pinecone, Weaviate, Milvus).

Unified Workflow

Visual Summary (Conceptual Flow)

Raw Data → Chunking → Embeddings → Metadata → Vector Database → Retrieval → LLM Generation

Summary

Chunking, embeddings, and metadata form the three pillars of RAG preprocessing. Chunking ensures data is consumable, embeddings make it comparable, and metadata makes it contextual and filterable. Together, they transform raw unstructured data into a structured, retrievable knowledge base that powers effective RAG applications.