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))Review the design
This is an executable lexical RAG retrieval baseline with traceable context. It deliberately does not fabricate generation, embedding quality or semantic faithfulness; those require a real model, judged queries and adversarial evaluation outside this local fixture.
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.
The explanation opens here once every check passes.