PythiloLesson 5 of 6 · progress kept in this browser

Project: assemble permission-scoped lexical retrieval context

Build a complete local retrieval pipeline that keeps authorization before ranking, computes a lexical relevance baseline and packs evidence within a token-ID budget. Every returned chunk retains its document identifier so citations can be checked against the exact supplied context.

The local retriever uses token overlap rather than an external embedding or generation service. It is a working deterministic baseline, not an assertion that a language model produced a grounded answer. The review should explain relevance judgments, corpus versioning, access revocation, prompt injection and a separate real-model evaluation plan.

query={"python","queue"}
document={"python","async","queue"}
print(len(query&document)/len(query|document))
Your task

Implement build_context(docs,tenant,query,budget). Docs have id,tenant,tokens(list of strings). Filter tenant first; score by Jaccard of unique query/document tokens (zero for empty union), keep only positive scores, sort descending then id. Pack whole documents by len(tokens), skipping nonfitting docs; return {ids,tokens_used,evidence:[{id,tokens}]}. Require budget>=0; doc ids unique within tenant.