liveBook · Manning

Preprocessing

As explained in Generative AI in Action

Data preprocessing is the process of cleaning, transforming, and organizing raw data into a form suitable for analysis or model processing.

Data preprocessing turns source data into a form a generative AI application can use. In a retrieval-augmented generation (RAG) pipeline, it can reduce noise, improve the quality of generated answers, and help determine a suitable size for document chunks. section 7.7.2 section 10.2.3

Choose operations according to the data and application:

  • Clean unwanted noise and transform data from one format to another. section 7.7.2
  • Use information extraction, feature normalization, tokenization, or stop-word removal when required. section 7.7.2
  • Chunk prepared content with attention to query complexity, the model’s context window, and any metadata the application needs. section 7.7.2

For enterprise RAG, preprocessing belongs in the data layer alongside connectors and pipelines that ingest records through APIs or plugins. Pipelines may need batch or streaming processing, authentication, data-refresh settings, and scalable, fault-tolerant processing. Prepared data can then support embedding creation and vector-database retrieval. section 10.2.3

Preparing content for different questions

A short factual question such as “What is the capital of the UK?” places different demands on retrieved content than a question about AI’s economic implications across US industries. Clean the source content, then compare chunk sizes against both answer quality and performance rather than assuming one size fits both queries. section 7.7.2

Table 7.3 Chunking approaches
Chunking approach
Description
Fixed length
Divide documents into chunks of a fixed number of words or tokens. This is straightforward but may sometimes split information that ideally should be kept together.
Sliding window
Use a fixed-sized sliding window with or without overlapping data. This can ensure that important boundaries within the text are not missed, but it can also lead to redundancy if there’s significant overlap.
Punctuation based
Divide the text based on punctuation, such as paragraphs or sections. This is less arbitrary than fixed-length chunking and often preserves the semantic integrity of the content. However, it can result in variable chunk sizes.
Topic or section breaks
In structured documents such as Wikipedia articles, natural breaks like sections or subsections can be used to define chunks. This method ensures that the content within a chunk is semantically coherent.
Adaptive
Use algorithms or models that adaptively determine the best way to chunk documents based on their content. This can be more complex but might yield semantically cohesive chunks.

Compare fixed-length, sliding-window, punctuation-based, and section-based chunking before choosing how to divide preprocessed documents. section 7.7.2

Unstructured provides functions and connectors for customized preprocessing pipelines, including conversion of unstructured data into structured output. LangChain and SK offer chunking options with configurable overlap to help preserve context. Treat these as choices to evaluate against the corpus and application requirements. section 10.4.2 section 7.7.2

How Generative AI in Action covers it

How deep it goes
Lists cleaning and transformation operations and places them in a data pipeline, without an executable preprocessing implementation.
Examples
Contrasts a simple capital-city question with a multifaceted economic question to motivate chunk-size evaluation.
What you can do after
Apply it via Unstructured to create customized preprocessing pipelines, or use LangChain and SK for chunking with overlap.
How it connects
Connects preprocessing to RAG, chunking, embeddings, vector databases, and data pipelines.

Also explained in

Compare how 22 books explain preprocessing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.