Chapter 4 · section 6 of 7
In production
The deployed version is worker/src/law-retrieval.ts, and yours is a transcription of it with two things removed: the file is fetched rather than imported, and the function that fuses several rankings is Chapter 5’s. Its header comment says what the stage is for in one sentence:
Retrieval is lexical and deterministic on purpose: the model sees the laws this returns and nothing else from the corpus, and a test can say exactly which laws a question reaches.
The one thing worth seeing is how the laws arrive. The worker reads one state’s file per question from the site’s own static files, at /ask-laws/MD.json, with the edge cache told to keep a successful response for an hour and a failed one for no time at all:
const response = await fetch(`${LAWS_ORIGIN}${at}`, {
cf: { cacheTtlByStatus: { '200': 3600, '300-599': 0 }, cacheEverything: true },
}) The '300-599': 0 is a scar. The worker deploys before the site does, and in the minutes between, a request for a state’s file answers 404. Cached for an hour, that 404 would have kept every road-law question for that state refused long after the file was published. A failure is never cached; only a success is.
And the file is built in one place. publishedLawsOf in scripts/statutes/laws.ts is what the site publishes, what the index in Chapter 5 embeds and what the measurement in Chapter 11 retrieves from, and the browser tests in Chapter 12 serve its lawsOf, the same list without the agency’s page rows, so the law the box quotes, the law the index ranks and the law a test drives cannot be three different cuts of the same section.