跪拜 Guibai
← All articles
Interview · GitHub · Architecture

The RAG Ingestion Pipeline Is Where Your Retrieval Quality Is Won or Lost

By 胡萝卜术 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Ingestion errors are permanent data pollution inside a vector database. A bad chunk boundary or a page full of scraped navigation bars cannot be fixed by a better prompt or re-ranker downstream, so the entire RAG system's ceiling is set before the first embedding is ever computed.

Summary

A RAG system's retrieval accuracy is permanently limited by mistakes made during data ingestion. Raw web pages and PDFs are chaotic; they must pass through extraction, validation, cleaning, and semantic splitting before they become useful knowledge chunks. The common `RecursiveCharacterTextSplitter` uses a greedy fallback strategy, trying coarse separators like paragraphs first, then progressively finer ones like sentences, to keep chunks small but semantically whole. Overlap between chunks acts as insurance against cutting through key references, but it cannot fix upstream extraction failures.

Production pipelines need more than a working splitter. Content validation must reject empty pages, WAF challenge screens, and JavaScript-dependent shells that static loaders miss. Quality gates should enforce minimum text lengths and log metrics for every document processed. Idempotent updates driven by content hashing prevent costly full rebuilds, and permission metadata must be bound at ingestion time so that retrieval filters can enforce access control.

Evaluating chunk quality requires three dimensions: structural integrity, retrieval recall on real queries, and generation faithfulness. The right chunk size and overlap are not formulaic; they emerge from iterative testing against a specific dataset and use case.

Takeaways
An HTTP 200 response does not mean content was extracted; static loaders fail silently on JavaScript-rendered pages, WAF challenges, and empty shells.
Content validation must immediately follow extraction, checking for minimum text length and known failure signatures like challenge-page markers.
The `RecursiveCharacterTextSplitter` tries coarse separators first and falls back to finer ones recursively, with an empty-string final separator as a hard-cut safety valve.
`chunkOverlap` preserves context across chunk boundaries but cannot compensate for poor extraction or bad separator design.
Production ingestion pipelines need quality gates, content hashing for idempotent incremental updates, and permission metadata bound at write time.
Chunk quality must be evaluated structurally, by retrieval recall on real queries, and by generation faithfulness, not just by whether `splitDocuments` returned an array.
Conclusions

Most RAG failures blamed on retrieval or generation actually originate in the ingestion pipeline, where silent data corruption is permanent and untraceable once written to the vector store.

The recursive splitter's fallback strategy is a practical compromise between semantic integrity and size control, but its separator priority list encodes assumptions about document structure that may not hold across formats.

Binding access-control metadata at ingestion time rather than at query time is a security design choice that prevents leakage by making permissions a retrieval precondition, not a post-hoc filter.

Concepts & terms
RecursiveCharacterTextSplitter
A text splitter that attempts to divide documents using a prioritized list of separators. It starts with the coarsest separator and recursively applies finer ones to any chunk that still exceeds the size limit, falling back to hard character-count cuts as a last resort.
chunkOverlap
A configurable number of characters shared between adjacent text chunks. It prevents key information like pronouns, causal links, or definitions from being severed at a chunk boundary, acting as context insurance rather than a fix for poor splitting.
Document (LangChain)
A standard data object with two fields: `pageContent` for the text that gets vectorized, and `metadata` for structured attributes like source, page number, and permissions that travel with the content through the pipeline.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗