WRITE · TRACE · UNDERSTAND
Project: rank an authorized corpus with real BM25 statistics
Documents have tenant,id,roles,text; (tenant,id) must be unique.
Read lesson: Project: rank an authorized corpus with real BM25 statistics →
Your experiment
Documents have tenant,id,roles,text; (tenant,id) must be unique. Admit only the requested tenant and public documents (roles empty) or any role intersection. Tokenize query and documents using lowercase ASCII [a-z0-9]+; deduplicate query terms. Compute all corpus statistics after permission filtering. BM25 uses k1=1.2,b=.75, idf=log(1+(N-df+.5)/(df+.5)), term contribution=idf*tf*2.2/(tf+1.2*(.25+.75*length/average_length)). Return positive-score {id,score} rows sorted by descending score then id, cut at integer k>=0. Empty/no-match/empty-length corpora return [].
Python runs in your browser. Your draft stays on this device.
What to look for
Review tenant/ACL provenance, corpus-statistic scope, tokenizer changes, ranking evaluation and tie stability. Production indexes also need versioned updates, revocation handling and access-aware caches. Replay follows the main orchestration function; helper computations execute and are checked separately.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.
