M3Medium★ RAG Debugging Essential · Span Recall AuditPart M · LLM Eval & RAG/Agent Ops

RAG Chunk Boundary Collapse & Overlap Recall Audit

⚡Flashcard Drill➔

Detect evidence tearing across zero-overlap chunk splits and verify sliding-window overlap recovery over golden evidence spans.

⏱️ Time: O(doc_len / (chunk_size - overlap))
💾 Space: O(NumChunks)
🎯 Interactive Self-Practice Loop (Attempt Before Peeking)
Practice in 4 steps: recall mechanism, complete core lines, check edge cases, and log mastery locally.
Step 1 · Mechanism Recall & Stability Self-Check
Step 2 · Complete Key Implementation Lines
def chunk_spans_with_overlap(doc_len: int, chunk_size: int, overlap: int) -> list:
"""
Generate [start, end) character/token index spans for sliding-window chunking.
"""
if chunk_size <= 0 or overlap < 0 or overlap >= chunk_size:
raise ValueError("Require chunk_size > 0 and 0 <= overlap < chunk_size")
stride =
spans = []
pos = 0
while pos < doc_len:
end =
spans.append((pos, end))
if end == doc_len:
break
pos += stride
return spans
def span_recall_contained(doc_len: int, evidence_span: tuple, chunk_size: int, overlap: int) -> float:
"""
Return 1.0 if the full golden evidence span [ev_start, ev_end) is intact inside at least one chunk, else 0.0.
"""
ev_start, ev_end = evidence_span
spans = chunk_spans_with_overlap(doc_len, chunk_size, overlap)
intact = any(c_start <= ev_start and ev_end <= c_end for c_start, c_end in spans)
return 1.0 if intact else 0.0
Step 3 · Verify Boundary Cases & Assertions
Step 4 · Follow-Up Drill & Review Outcome
Q1: How does Small-to-Big (Parent-Child) retrieval resolve the trade-off between small precise embeddings and broad generation context?
Next: Agent Tool Loop Breaker & Idempotency Guard →
💡

Core Mental Anchor / Mnemonic

Check overlap < chunk_size; sliding overlap or parent-child lookup keeps cross-boundary facts intact.

📐 Mathematical Derivation & Core Formula

Chunki=[i(S−O),  i(S−O)+S),Containment=I(∃i:  a≥cistart∧b≤ciend)\mathrm{Chunk}_i = [i(S - O), \; i(S - O) + S), \quad \text{Containment} = \mathbb{I}(\exists i:\; a \ge c_i^{\text{start}} \land b \le c_i^{\text{end}})
### Quantifying Chunk-Boundary Splitting Failure
Zero-overlap fixed splitting tears short cross-boundary facts (e.g., metric value + qualifier) into two incomplete vectors. Sliding windows with stride = chunk_size - overlap guarantee intact containment for any span shorter than overlap + 1, while Small-to-Big parent indexing preserves full surrounding context during generation.

🔄 Tensor Dimensions & Shape Flow

doc_len, chunk_size, overlap -> stride -> sliding [start, end) spans -> verify intact evidence containment

🛡️ Numerical Stability & Pitfalls Checklist

  • Assert 0 <= overlap < chunk_size so window stride stays strictly positive.
  • Prefer structural boundaries (headers/tables) paired with parent-document lookup over blind character cuts.

💻 Reference Code Implementation

def chunk_spans_with_overlap(doc_len: int, chunk_size: int, overlap: int) -> list:
    """
    Generate [start, end) character/token index spans for sliding-window chunking.
    """
    if chunk_size <= 0 or overlap < 0 or overlap >= chunk_size:
        raise ValueError("Require chunk_size > 0 and 0 <= overlap < chunk_size")
    stride = chunk_size - overlap
    spans = []
    pos = 0
    while pos < doc_len:
        end = min(doc_len, pos + chunk_size)
        spans.append((pos, end))
        if end == doc_len:
            break
        pos += stride
    return spans

def span_recall_contained(doc_len: int, evidence_span: tuple, chunk_size: int, overlap: int) -> float:
    """
    Return 1.0 if the full golden evidence span [ev_start, ev_end) is intact inside at least one chunk, else 0.0.
    """
    ev_start, ev_end = evidence_span
    spans = chunk_spans_with_overlap(doc_len, chunk_size, overlap)
    intact = any(c_start <= ev_start and ev_end <= c_end for c_start, c_end in spans)
    return 1.0 if intact else 0.0

🧪 Runnable Assertions & Validation

Copy and run directly in Python / Jupyter:

# Evidence spans index [9, 12), crossing a strict 10-unit boundary
doc_len = 25
evidence = (9, 12)
recall_no_overlap = span_recall_contained(doc_len, evidence, chunk_size=10, overlap=0)
recall_with_overlap = span_recall_contained(doc_len, evidence, chunk_size=10, overlap=4)
assert recall_no_overlap == 0.0, "Zero-overlap chunking tears boundary evidence apart!"
assert recall_with_overlap == 1.0, "Sliding overlap must keep cross-boundary evidence intact!"
print("✓ RAG chunk-boundary collapse audit assertion passed")

🎯 Core Follow-up Inquiries & Reference Answers

Q1:How does Small-to-Big (Parent-Child) retrieval resolve the trade-off between small precise embeddings and broad generation context?
Index small child chunks (128-256 tokens) for high semantic SNR during vector search, then fetch the linked larger parent section via parent_id for LLM synthesis.
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
← Prev: Constrained JSON Decoding via FSM Logit MaskingBack to Part M & All 105Next: Agent Tool Loop Breaker & Idempotency Guard →