Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 11.2 — Freshness
RAG and Vector Search · Example 1 of 1

Index lag: a schedule against a change feed

Time is a counter, never a real clock, so the three languages agree. The allowance of 20 ticks is an example value.

An index is a photograph of the documents at some moment. Freshness is how old that photograph may be when a question arrives. You decide the allowance, measure the lag between an edit and its appearance in answers, and show the reader the "as of" date.

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 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write pending(edits, indexed_at, now) returning the sorted list of documents that were edited at or before now but whose edit is not yet indexed. Try it with the schedule from the example at tick 40.

02

Write as_of_label(as_of_tick, now) returning text such as "as of tick 30 (10 ticks ago)", and "as of the original (never edited)" when as_of_tick is 0.

Explain it without notes

01

What is index lag, and how would you measure it?

02

Compare a nightly schedule with a change feed for keeping an index fresh.

03

Why show an "as of" date in an answer?

04

Why must deletes and permission changes take the fast path, not the nightly one?

Index lag: a schedule against a change feed
Sign in to run this example in your browser.

Expected output

nightly lag: D8=19, D2=18, D6=17, D1=22 | worst 22 | within allowance: no
feed lag: D8=2, D2=2, D6=2, D1=2 | worst 2 | within allowance: yes
tick 40 nightly: D2 answer is as of tick 0, D1 answer is as of tick 0
tick 40 feed: D2 answer is as of tick 30, D1 answer is as of tick 0
tick 74 nightly: D2 answer is as of tick 30, D1 answer is as of tick 50
tick 74 feed: D2 answer is as of tick 30, D1 answer is as of tick 50