import sys,time,json,numpy as np,pandas as pd sys.path.insert(0,'/mnt/data') from msmarco_full_search_fast import FullIndex,load_query_texts,qrels_from_tsv,eval_run,ROOT,WORK,P BEST_H=0 idx=FullIndex(); print('loaded',idx.meta,flush=True) df=pd.read_csv(ROOT/'dev.tsv',sep='\t',usecols=['query-id']); ids=[str(x) for x in np.unique(df['query-id'].to_numpy())]; del df texts=load_query_texts(ids); qrels=qrels_from_tsv(ROOT/'dev.tsv',ids,positive_only=True) # warm compile/pages, not timed w=idx.prepare(texts[ids[0]],hmax=1); idx.rank_h(w,0,100); del w run={}; times=[]; cands=[]; mems=[] route_num=pool_num=rel_den=0 for z,qid in enumerate(ids): t=time.perf_counter(); pp=idx.prepare(texts[qid],hmax=1); rank=idx.rank_h(pp,BEST_H,100); dt=(time.perf_counter()-t)*1000 run[qid]=rank; times.append(dt); cands.append(pp['candidate_docs'] if pp else 0); mems.append(pp['candidate_memberships'] if pp else 0) rel=[int(d) for d,r in qrels[qid].items() if r>0]; rel_den+=len(rel) if pp is not None: ud=pp['ud']; pool=pp['cand_docs'][:P] for d in rel: k=np.searchsorted(ud,d); route_num += int(k