Bayesian_LangGraph / tests /test_core.py
Angshul's picture
Upload 21 files
198bd6d verified
Raw History Blame Contribute Delete
898 Bytes
from bayesian_langgraph.core import BayesianIndex, DocumentRecord
from bayesian_langgraph.smc import normalize_logweights
def test_all_negative_infinity_weights_become_uniform():
p = normalize_logweights([float('-inf'), float('-inf')])
assert p == [0.5, 0.5]
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'