A free ebook, as a PDF and an EPUB

Text data cleaning for RAG pipelines

Normalize Unicode, split BM25 and vector cleaning, route languages, repair mojibake and redact PII once at ingest, so every retriever downstream sees honest text.

The PDF opens in a new tab. Your details go to learnwithparam only. This does not subscribe you to the newsletter.

Look insidePages from the PDF, as they print.

  1. Page 3: The right article was in the index, and search still could not find it.
    Page 3: The right article was in the index, and search still could not find it.
  2. Page 4: Most text artifacts are invisible, and each one costs retrieval in its own way.
    Page 4: Most text artifacts are invisible, and each one costs retrieval in its own way.
  3. Page 7: NFC, collapse spaces, strip invisible characters: nothing fancier.
    Page 7: NFC, collapse spaces, strip invisible characters: nothing fancier.
  4. Page 11: The same article becomes two different keys, one per index.
    Page 11: The same article becomes two different keys, one per index.
  5. Page 18: Real accents pass, mojibake is repaired, and lost bytes are rejected.
    Page 18: Real accents pass, mojibake is repaired, and lost bytes are rejected.
  6. Page 20: Redact with a recognizer engine, so names are caught as well as emails.
    Page 20: Redact with a recognizer engine, so names are caught as well as emails.

What the ebook covers

  1. 1

    Why text cleaning is upstream of retrieval quality

    Text that reads fine to a person can be invisible to an index. Fix it once at ingest and every index, retriever and reranker downstream benefits.

  2. 2

    Unicode, whitespace and zero-width characters

    Compose characters with NFC, collapse every kind of space, and strip the invisible characters that split words. Keep the ones that carry meaning in some scripts.

  3. 3

    Tokenization for BM25 vs vectors

    BM25 is a bag of terms and wants aggressive folding. Embedders read case, punctuation and numbers. One cleaning pipeline serves one index, not both.

  4. 4

    Language detection and multilingual handling

    An English embedder silently loses recall on other languages. Detect the language at ingest as routing metadata, not a cleaning step.

  5. 5

    Encoding artifact detection (mojibake)

    Mojibake means bytes were decoded with the wrong encoding somewhere upstream. Detect it at ingest, repair it with ftfy, and reject what cannot be repaired.

  6. 6

    PII and sensitive-content redaction

    Anything in the index can come back in an answer, a log or a cache. Redact personal data at ingest, not at query time, and encrypt instead when PII is the point.

  7. 7

    Ship checklist

    Before a cleaning change ships, run one real batch through it, read the rejects, and compare saved queries against the last release.

  8. 8

    The page to keep and the questions people ask

    Every cleaning rule on one page, then short answers to what engineers search about text data cleaning for RAG.

See the lab this ebook comes fromBuild a Second Brain with Claude Code: A second brain over your notes, docs and Linear that answers with sources and serves the same memory to any agent over MCP.