import math from bayesian_langchain.core import BayesianIndex, DocumentRecord from bayesian_langchain.smc import normalize_logweights def test_all_negative_infinity_weights_become_uniform(): p = normalize_logweights([float('-inf'), float('-inf'), float('-inf')]) assert p == [1/3, 1/3, 1/3] def test_authoritative_current_document_beats_stale_high_overlap(): docs = [ DocumentRecord('stale','The current HR portal is WorkSphere.','Current HR portal','cache',{'reliability_alpha':6,'reliability_beta':6,'authority':0.45,'freshness':0.18}), DocumentRecord('official','Leave requests and payslips are now handled in PeopleHub.','Migration complete','official',{'reliability_alpha':18,'reliability_beta':2,'authority':0.98,'freshness':1.0}), ] hits = BayesianIndex(docs).search('What is the current HR portal for leave requests and payslips?', k=2) assert hits[0].document.id == 'official'