File size: 898 Bytes
198bd6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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'