Document RAG Bottlenecks in AI Coding Tools: Fixing Input Quality Before Retrieval

    This article explains why input quality, not model choice or vector tuning, sets the ceiling for document RAG in AI coding tools. It covers why PDFs, tables, contracts, and slide decks break keyword-based retrieval, and how a structured pre-processing layer that converts heterogeneous documents into Markdown can improve retrieval. You will find a four-layer conversion pipeline, chunking and dual-channel retrieval practices, observability and incremental indexing tips, and common pitfalls to avoid.

    1. The Real Bottleneck Is Input Quality, Not the Model

    When teams build document Q&A into AI coding tools, they tend to focus on model selection, prompt tuning, and vector parameters. But the factor that actually sets the upper limit on quality is the layer before retrieval even starts: input quality.

    The familiar “garbage in, garbage out” rule applies just as well to document retrieval-augmented generation (RAG). If the chunking unit has already lost semantic boundaries, then no amount of ranking or reranking downstream can fix it. Those steps only optimize over incomplete evidence.

    The retrieval capability of an AI coding tool is fundamentally built on file location and text matching: locate candidate files by filename patterns, search file contents for keyword hits, then read the surrounding context in full and hand it to the model for reasoning. This works extremely well in code repositories, for a simple reason: source code is already well-structured plain text, and identifiers, strings, and comments can all be matched precisely.

    Enterprise knowledge, however, does not primarily live in code. It lives in business documents with complex formatting. That is the core conflict: the retrieval side is “text-first,” while the information-density side is “structure- and layout-first.”

    2.1 PDFs: Layout Is Semantics

    Two-column layouts scramble reading order. Tables spanning pages get cut by headers and footers. Mixed text and images separate captions from the body they describe. Under these conditions, keyword matching either hits garbled text or matches only fragments, and key passages missing their context are systematically skipped.

    2.2 Tables: A Two-Layer Mapping Problem

    This is the most typical failure point. Optical character recognition (OCR) solves the mapping from pixels to characters. Table understanding requires a different mapping: from cells to fields. Which value belongs to which column, which row belongs to which group, and how merged cells should be expanded are all separate questions. Getting the first layer right does not guarantee the second. Once multi-level headers are flattened, the alignment between numbers and column names is lost immediately, and what you read out is a pile of uninterpretable values.

    2.3 Contracts and Policy Documents: Hierarchy Is Constraint

    Contracts, policies, and specifications derive meaning from numbering hierarchy and nesting. The subordination of clause 3.2.1 to clause 3.2, or an appendix’s reference back to the main body, disappears once the document is flattened into continuous paragraphs. The model can no longer determine the scope of a constraint, so answers read fluently but overstep.

    2.4 Presentations: Content Is Spread Across Containers

    In training material, content is distributed across text boxes, shapes, tables, and speaker notes, and reading order has to be reconstructed explicitly. Plain-text matching often hits only titles, leaving the main body completely invisible.

    3. The Fix: Insert a Structured Pre-Processing Layer Before Retrieval

    The idea is straightforward: before retrieval happens, convert heterogeneous documents into structured Markdown, then let the toolchain handle them.

    Markdown is not a preference. It satisfies three conditions at once. First, it is plain text, so it can be matched precisely by keyword and read line by line. Second, hierarchy is explicit: headings, lists, and code blocks map naturally to sections and clauses. Third, tables and images have standard representations, which makes it easy to preserve alignment and reference anchors. More importantly, it is an extremely dense format in model training corpora, so the cost of format compliance at inference time is the lowest.

    A minimal viable conversion pipeline can be abstracted into four layers:

    1. [1] Collection File discovery, deduplication, version identification, permission checks
    2. [2] Parsing Layout analysis -> reading order reconstruction -> structure recovery -> Markdown rendering
    3. [3] Validation Structural integrity checks, table column-count consistency, page anchor backfilling
    4. [4] Indexing Split by heading hierarchy -> generate summaries and keywords -> build dual vector and keyword channels

    A sample output structure looks like this. The key point is that every chunk carries traceable metadata:

    1. # Chapter 3 Revenue Recognition
    2. > Source: 2024 Annual Report.pdf / p.58 / Table 3-2
    3. ## 3.2 Revenue by Region
    4. | Region | Revenue (millions) | YoY |
    5. | --- | --- | --- |
    6. | East China | 1,240 | +12% |
    7. <!-- chunk_id: sec-3-2, parent: sec-3 -->

    4. Implementation Notes

    4.1 Let Structure Drive Chunking, Not Fixed Character Counts

    Split by heading hierarchy first. Keep tables and captions intact as whole units. For overlong subsections, split again by paragraph while keeping the parent heading as a context prefix. Fixed-length chunking is one of the main sources of quality decay in document RAG.

    4.2 Make the Two Retrieval Channels Complementary

    The keyword channel excels at strong identifiers such as proper nouns, clause numbers, and financial line items. The vector channel excels at queries that share intent but differ in wording. Fusing and reranking both sets of recalls significantly reduces the chance of “found it but it does not rank.”

    4.3 Model Tables Separately

    Generate a one-sentence natural-language summary and a field list for each table, while preserving the original table structure. Queries hit the summary; answers cite the original table. This balances recall and accuracy.

    4.4 Observability and Regression

    Maintain a fixed evaluation set and track hit rate, citation accuracy, and no-answer rate. Run a regression pass every time you adjust parsing parameters or chunking strategy, so you avoid “fixing one document and breaking a whole class of documents.”

    4.5 Incremental Updates and Permissions

    When a document changes, re-parse incrementally using content fingerprints. During indexing, inherit the access control attributes of the source file so retrieval results never overstep permissions.

    5. Common Pitfalls

    • Doing recognition without structure recovery: characters are correct but fields are misaligned, which is harder to detect than recognition errors.
    • Using fixed-length chunking for every document: clauses and tables get cut in half.
    • Ignoring reading order: under two-column and multi-container layouts, wrong order equals wrong semantics.
    • Missing source anchors: without page and section traceability, answers cannot be audited and business teams will not trust them.
    • Treating parsing as a one-off script: document formats keep evolving, so the parsing layer needs versioning and regression mechanisms.

    6. Conclusion

    The gains from complex-document RAG come mainly from the engineering layer before retrieval: restoring layout and structure into a plain-text form that both machines and models can consume easily. When the parsing layer reliably outputs Markdown with hierarchy, anchors, and table alignment, retrieval hit rate and answer credibility improve together, and the model finally receives qualified raw material.