"""Frozen full511 same-corpus graph/native/BM parent retrieval visibility.""" import collections,hashlib,json from pathlib import Path from analyze_miriad511_evidence import load_annotations,paired_visibility_delta from audit_miriad511_cited_spans import context_coverage ROOT=Path(__file__).resolve().parent;BASE=ROOT/'miriad_public';OUT=BASE/'graph_common_corpus_gpt_20261121/full4685/human511_retrieval_prospective_v1' def read(p):return [json.loads(x) for x in p.read_text().splitlines()] def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() def main(): audit=json.loads((OUT/'matched_context_preparation_audit.json').read_text());p=OUT/'matched_reader_requests3066_local_only.jsonl';assert sha(p)==audit['reader_requests_sha256'] and audit['provider_usage_ledgers_unchanged'] requests=read(p);selection={r['id']:r for r in read(OUT/'source_only_selection511_local_only.jsonl')};assert len(selection)==511 and all(not r['gold_or_reference_opened_for_selection'] for r in selection.values()) items={r['id']:r for r in read(BASE/'openqa_human511_readers/selected_items.jsonl')};annotations=load_annotations(BASE,items);refs={r['id']:r['reference_source_id'] for r in read(BASE/'retrieval_queries2979.jsonl')} corpus_ids={r['source_id'] for r in read(OUT.parent/'corpus.jsonl')} outcomes=collections.defaultdict(dict);counts=collections.defaultdict(collections.Counter);tokens=collections.defaultdict(list);allrows=[] for req in requests: ident,method=req['id'],req['method'];context=json.loads(req['messages'][1]['content'])['evidence'];_,coverage,visible=context_coverage(context,refs[ident],annotations[ident]);candidates=selection[ident]['source_candidates'][method] row={'id':ident,'method':method,'source_family_id':items[ident]['source_family_id'],'reference_in_parent_candidates':refs[ident] in candidates, 'reference_header_visible':bool(coverage),'any_annotated_quote_visible':bool(visible),'all_annotated_quotes_visible':len(visible)==len(annotations[ident]), 'annotated_quotes':len(annotations[ident]),'visible_quotes':len(visible),'actual_context_tokens':req['context_tokens_unified']} row['candidate_ref_but_header_lost']=row['reference_in_parent_candidates'] and not row['reference_header_visible'];row['header_but_no_annotated_quote']=row['reference_header_visible'] and not row['any_annotated_quote_visible'] row['some_but_not_all_quotes']=row['any_annotated_quote_visible'] and not row['all_annotated_quotes_visible'];outcomes[ident][method]=row;allrows.append(row) for k in ['reference_in_parent_candidates','reference_header_visible','any_annotated_quote_visible','all_annotated_quotes_visible','candidate_ref_but_header_lost','header_but_no_annotated_quote','some_but_not_all_quotes']:counts[method][k]+=row[k] tokens[method].append(req['context_tokens_unified']) groups=collections.defaultdict(list) for ident,item in items.items():groups[item['source_family_id']].append(ident) contrasts={} for treatment,baseline in [('graph4000_question_bm25','graph4000_original'),('graph12000_original','graph4000_original'),('graph12000_question_bm25','graph4000_original'),('graph12000_question_bm25','graph12000_original'),('graph12000_question_bm25','bm25_parent_commoncap'),('graph12000_question_bm25','native_parent_commoncap')]: contrasts[treatment+'_minus_'+baseline]={metric:paired_visibility_delta(sorted(items),groups,outcomes,treatment,baseline,metric) for metric in ['reference_header_visible','all_annotated_quotes_visible']} (OUT/'reference_visibility_per_question_local_only.jsonl').write_text(''.join(json.dumps(r)+'\n' for r in allrows)) report={'scope':'Exploratory literal reference-evidence visibility on all511historically exposed humanOpenQA. Not semantic retrieval recall, answer correctness, clinical accuracy or an untouchedtest.', 'questions':511,'source_families':len(groups),'arms':6,'strict_equal_actual_length_questions':audit['counts']['strict_equal_actual_length_questions'],'requests_sha256':sha(p),'counts':counts, 'token_lengths':{m:{'min':min(v),'max':max(v),'mean':sum(v)/len(v)} for m,v in tokens.items()},'paired_pointwise_source_family_effects':contrasts, 'known_reference_passages_in_corpus':sum(refs[i] in corpus_ids for i in items),'new_model_calls':0,'new_reader_outputs':0,'expert_reviews':0,'limits':'Reference quotes from two automatic source auditors, not expert necessary facts or exhaustive relevance labels. Alternative sources/paraphrases can support answers. Header visibility does not mean full reference text retained. The topic corpus contains510/511known reference passages; the missing one is retained in the denominator and remains oracle-only. This is not independent external clinical KB coverage. New BM/native parent arms differ from old chunk baselines. All six arms share per-question actual token lengths; embeddings/index extractors differ. Family bootstrap is pointwise, no multiple-comparison significance claim. Source-study boundary entailment and mixed-extractor graph semantic precision unvalidated.'} (OUT/'literal_reference_visibility_audit.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps({k:report[k] for k in ['questions','source_families','strict_equal_actual_length_questions','counts','new_model_calls']})) if __name__=='__main__':main()