A metadata schema that is checked
In Java the metadata is a Map<String, Object>, so the type checks use instanceof. A real project would use a typed class.
Metadata is the labelled information stored next to every chunk: source, section, date, version, language and who may read it. Each field exists because a later step needs it, and a schema that is checked at ingestion keeps bad records out.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write newest(chunks) for a list of (source, version) pairs that keeps only the pair with the highest version for each source, preserving order. Print the result for [("a", 1), ("b", 1), ("a", 2)].
Write is_iso_date(text) that returns True when the text looks like YYYY-MM-DD (digits only, with dashes in the right places). Print it for "2026-03-01" and "1 March 2026".
Explain it without notes
Name four metadata fields and what each is used for later.
Why validate metadata when chunks are created and not when they are searched?
Why filter by access before ranking rather than after?
Why is metadata usually not part of the embedded text, and when is an exception sensible?
Expected output
chunk 1: ok
chunk 2: missing source; access must be public or staff, got internal
chunk 3: version must be a whole number from 1; updated must look like 2026-03-01, got 1 March 2026