Understand chunking failures and the limits of the retrieval baseline.
Understand the method
Chunking balances context size with complete meaning. If a cap and its invoice condition are split, retrieving only the cap hides the constraint from generation. A shorter chunk is not necessarily a better source.
Each lab rule is already a coherent chunk. For longer documents, start with headings and paragraphs and then respect the actual model context budget. Overlap reduces some boundary loss but creates duplication and does not guarantee complete rules.
Carry parent source, heading path and version. References such as “these staff” may be meaningless alone. Enrich a chunk with the needed heading or retrieve adjacent context. Do not expect the model to reconstruct discarded constraints.
The program uses overlapping Chinese bigrams and Latin words as an inspectable baseline. It scores shared terms between question and chunk. It has no embeddings or synonym understanding. Its transparent failures provide a baseline for later semantic search.
Vector retrieval encodes questions and sources for similarity search. Keyword methods help exact names and IDs. Compare or combine approaches. Neither similarity nor the lab overlap score is a correctness probability; calibrate any threshold with your own cases.
Try rephrasing a computer failure using different wording and observe whether P4 remains. Save the output before adding query synonyms, enriching titles or adopting embeddings. Change one factor at a time to isolate its effect.
- 1Complete rule
- 2Context
- 3Baseline
- 4Misses
Included material
import re
def terms(text):
result = set(re.findall(r"[a-z0-9]+", text.lower()))
for run in re.findall(r"[\u4e00-\u9fff]+", text):
result.update(run[i:i+2] for i in range(max(1, len(run)-1)))
return result
query_terms = terms("Python RAG")
document_terms = terms("RAG with Python")
score = len(query_terms & document_terms) / max(1, len(query_terms))
print(score)Work through the steps
- Write the bigrams for the supplied lodging phrase and compare with code.
- Compare complete P1 with a copy missing the invoice condition.
- Record one observed retrieval result for a paraphrase before changing anything.
Worked example
Bad split: one chunk contains only the cap; another the invoice condition. Better: preserve the complete P1 rule. If retrieved evidence lacks the invoice constraint, repair chunking before prompting.
Your exercise
Write a five-sentence procedure and two chunking strategies. Give one question whose evidence changes with the split. Use original non-sensitive text.
Check before delivery
- Explain that this program has no vector search.
- Record specific lost conditions in the comparison.
Finish the exercise, then view the reference
Identify the cross-boundary requirement, missing evidence and repaired chunk. If both splits support the answer, choose a question that actually exposes the boundary.
An original course with teaching exercises. Reading records, practice outcomes and independent certification are distinct.