RAG System Challenges: The Hardest Part Is Preserving Constraints Across the Pipeline

    Building an LLM-based RAG system is often treated as a model-selection and vector-database problem, but the real difficulty is keeping constraints intact from source material to final answer. This article explains five critical constraint types—time, version, permission, device instance, and query intent—and shows where they tend to decay across parsing, chunking, metadata indexing, retrieval, reranking, context assembly, and generation. It also covers constraint-aware filtering code, evaluation gaps, and ongoing knowledge-base maintenance practices that help teams prevent fluent but conditionally wrong answers.

    Introduction: The Real Difficulty Is Not Model Selection, but Constraint Propagation

    When planning a retrieval-augmented generation (RAG) system, many teams invest heavily in model selection and throughput comparisons across vector databases. That work has value, but in project retrospectives one lesson often stands out: what determines system success is the path from raw source material to the final answer. Along that path, whether constraints can be fully propagated is the hardest part to get right.

    A typical RAG pipeline includes: raw sources (PDF, Word, web pages, databases) → parsing → chunking → metadata annotation → vectorization → retrieval → reranking → context assembly → generation. Each transformation can lose part of the constraints. Once the generation side receives context that lacks the relevant conditions, even a strong model cannot recover them—it cannot infer information the document did not carry.

    1. Five Key Constraint Types: The Invisible Objects to Protect Across the Pipeline

    In practice, five main types of constraints need to remain valid throughout the pipeline:

    1. Time constraints: document effective dates and data freshness. For example, an operating procedure may have been revised in 2023 while the old version remains in the index.
    2. Version constraints: firmware versions, document versions, and chip revision numbers. The same error code may require completely different handling across versions.
    3. Permission constraints: the scope of material visible to different roles. If permissions are filtered only after retrieval, unauthorized fragments have already entered the candidate set, creating leakage risk.
    4. Device instance constraints: applicability to a specific model or series. General semantic vectors tend to blur similar device types together.
    5. Query intent constraints: device, time, and scenario information implied in the user’s question. Without them, the query cannot be correctly matched to document conditions.

    Once these five constraint types are understood, it becomes clearer how constraints are “lost” at each stage.

    2. Five Decay Points for Constraints in the Pipeline

    1. Chunking: Structural Constraints Break

    Fixed-length chunking is the most common approach, and it is also a major source of semantic breaks. Parameter values often come with conditions—accuracy metrics may hold only within a certain temperature range, and register bit definitions may apply only to a specific revision. Fixed-length chunks can separate these values from their preconditions. Retrieval then returns a metric that “looks complete,” while the error hides in the discarded precondition.

    Countermeasure: Use structure-aware chunking, such as parent-child chunking—preserve relationships in the document hierarchy (sections, tables, footnotes), retrieve child chunks, and trace back to the parent chunk for full context.

    2. Index Annotation: Time and Version Constraints Are Missed

    Many teams store only text and vectors when building an index, with very few metadata fields. Only after the system goes live do they discover that they cannot filter by time or version.

    Countermeasure: During metadata annotation, enforce fields such as timestamp, version number, source type, and applicability scope, and design them as first-class filterable structures rather than optional extras.

    3. Retrieval: Permission Filtering Happens at the Wrong Time

    If permission filtering is applied after reranking, unauthorized content has already entered the candidate set. Even if it does not appear in the final answer, it may still leak through citations, summaries, or other means.

    Countermeasure: Permissions must be enforced as a hard filter before retrieval—a typical constraint that should be enforced at the structural level rather than left to the model’s discretion.

    4. Semantic Retrieval: Device Instances Are Blurred

    “This device” and “another device in the same series” are close together in semantic vector space. In industrial practice, the most dangerous error is mistaking semantic similarity for operational interchangeability: the same error code may have completely different reset preconditions across series and firmware versions.

    Countermeasure: Use hybrid retrieval for device instance constraints—semantic vectors handle “fuzzy recall,” while keywords (device model, firmware version number) handle exact matching. Treat instance constraints as metadata filters and extract them from the user query during query rewriting.

    5. Query Stage: Intent Constraints Are Missing

    User questions often lack device and time information: “How do I handle this error code?”—without saying which device, which version, or when it occurred. Without these conditions, retrieval cannot correctly narrow the scope.

    Countermeasure: Introduce a query rewriting step, complete constraints through conversation context or clarifying follow-up questions, and then carry the completed conditions into retrieval and filtering.

    3. Illustrative Code: Constraint-Aware Retrieval Filtering

    1. # Pseudocode: enforce constraint filters before retrieval
    2. filters = {
    3. "doc_valid_until": {"$gte": query.timestamp},
    4. "device_series": query.device_series, # device instance constraint
    5. "firmware_version": query.fw_version, # version constraint
    6. "acl_group": {"$in": user.acl_groups}, # permission constraint, applied before retrieval
    7. }
    8. results = hybrid_search(
    9. query_text=rewritten_query, # intent completed through query rewriting
    10. top_k=20,
    11. metadata_filter=filters,
    12. )
    13. reranked = rerank(results)[:5]
    14. context = assemble_with_metadata(reranked) # metadata enters context with each fragment

    There are three key points: filter conditions take effect before retrieval, metadata enters the final context with each fragment, and query rewriting happens first.

    4. Evaluation: Why Automated Metrics Miss Wrong Answers

    This is a blind spot in most discussions. Common retrieval metrics (recall, hit rate) and generation metrics (faithfulness, relevance) are fragment-level evaluations. They cannot detect errors where “the answer is fluent but its preconditions are no longer valid.” A metric may be retrieved and the answer may be faithful to that fragment—but the fragment has lost its temperature condition, and standard evaluation still gives a high score.

    Countermeasures:

    • Build an evaluation set with constraint conditions: each test question includes device, version, time, and other conditions, and the reference answer labels the applicable scope of those conditions.
    • Distinguish “semantically correct” from “constraint-correct” during evaluation: if the answer text is right but violates time, version, or device constraints, it should be judged wrong.
    • Run regular regressions: after knowledge-base updates (new document versions indexed, old versions archived), automatically trigger constraint consistency checks, such as whether handling differences for the same error code across document versions are correctly distinguished.

    5. Continuous Knowledge-Base Operations: Constraints Are Alive

    Documents are revised, versions iterate, and permissions change. Constraints are not static information annotated once at index-build time; they are dynamic assets that require continuous operations:

    • Version archiving strategy: when new documents are indexed, explicitly define the status of old versions (deprecated or still partially valid) to avoid mixed retrieval when old and new versions coexist.
    • Metadata validation pipeline: before indexing, automatically check whether required fields are complete, and block documents that do not meet constraint annotation requirements.
    • Invalidation feedback mechanism: identify cases of “answer does not match reality” from user feedback and trace them back to the stage where the constraint was lost.

    Conclusion

    Returning to the original question: what is the hardest part of building a RAG system? It is keeping constraints from being lost along the pipeline. Parsing, chunking, hybrid retrieval, reranking, and other stages all have mature reusable approaches. What teams truly need to design is treating the five constraint types—time, version, permission, device instance, and query intent—as first-class citizens, with explicit propagation paths and enforcement points at the architecture level. Only when constraints are preserved can answer correctness have a foundation. Otherwise, every fluent answer the system produces may be a well-packaged time bomb.