merge: T57 significance-aware retrieval ranking
This commit is contained in:
@@ -125,3 +125,37 @@ def test_search_invalid_witness_role_raises(tmp_path):
|
||||
with open_db(db) as conn:
|
||||
with pytest.raises(ValueError):
|
||||
search_memories(conn, "bot_a", "invalid_role", "anything", k=4)
|
||||
|
||||
|
||||
def test_higher_significance_outranks_equal_rank(tmp_path):
|
||||
"""T57: significance multiplier biases the SQL ORDER BY.
|
||||
|
||||
Two memories with IDENTICAL FTS-matching text yield (effectively) equal
|
||||
BM25 ranks. The significance bias applied in the SQL ORDER BY must
|
||||
surface the higher-significance row first.
|
||||
"""
|
||||
db = tmp_path / "t.db"
|
||||
_seed(
|
||||
db,
|
||||
memory_specs=[
|
||||
# Identical pov_summary text -> FTS BM25 rank is the same for both.
|
||||
{"pov_summary": "she swore an oath", "significance": 0},
|
||||
{"pov_summary": "she swore an oath", "significance": 3},
|
||||
],
|
||||
)
|
||||
with open_db(db) as conn:
|
||||
out = search_memories(conn, "bot_a", "host", "oath", k=5)
|
||||
assert len(out) == 2
|
||||
# Higher significance wins despite tied FTS rank.
|
||||
assert out[0]["significance"] == 3
|
||||
assert out[1]["significance"] == 0
|
||||
|
||||
|
||||
def test_significance_bias_is_constant_module_level():
|
||||
"""T57: pin ``SIGNIFICANCE_RANK_BIAS`` as a tunable module-level numeric."""
|
||||
from chat.state.memory import SIGNIFICANCE_RANK_BIAS
|
||||
|
||||
assert isinstance(SIGNIFICANCE_RANK_BIAS, (int, float))
|
||||
# Must be non-negative -- a negative bias would invert the desired
|
||||
# "higher significance ranks higher" semantics.
|
||||
assert SIGNIFICANCE_RANK_BIAS >= 0
|
||||
|
||||
Reference in New Issue
Block a user