mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-08 12:00:36 +00:00
* fix(memory): tolerate unbounded stored fact confidence A stored memory fact can carry a JSON integer such as 10**400. float() on it raises OverflowError in _coerce_source_confidence and in the dedup merge comparison, aborting the whole update cycle even though both sites already handle every other unusable confidence. Treat the overflow like a missing or non-finite value: 0.5 for ranking, 0.0 for the merge comparison. * fix(memory): harden the remaining fact-confidence coercions The import normalizer, prompt builder and relevance scorer each coerce a stored fact confidence with float() and caught only TypeError/ValueError, so an unbounded JSON integer such as 10**400 raised OverflowError: import failed before the updater fallbacks ran, and prompt/relevance ranking could abort. Catch OverflowError and take the existing defaults; document the full set of coercions.
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
"""An unbounded stored fact confidence must not abort memory reads or imports.
|
|
|
|
A memory document is editable JSON, so ``confidence`` can be an arbitrary
|
|
precision integer such as ``10**400``. ``float()`` raises ``OverflowError`` on
|
|
it; every fact-confidence coercion on a read or import path must treat that
|
|
like any other unusable value instead of failing the whole operation.
|
|
"""
|
|
|
|
from deerflow.agents.memory.backends.deermem.deermem.core.prompt import _coerce_confidence as prompt_confidence
|
|
from deerflow.agents.memory.backends.deermem.deermem.core.relevance import _coerce_confidence as relevance_confidence
|
|
from deerflow.agents.memory.backends.deermem.deermem.core.storage import normalize_memory_data
|
|
|
|
UNBOUNDED = 10**400
|
|
|
|
|
|
def test_legacy_import_normalization_falls_back_to_the_default_confidence():
|
|
normalized = normalize_memory_data({"facts": [{"content": "User likes Rust", "confidence": UNBOUNDED}]})
|
|
|
|
assert normalized["facts"][0]["confidence"] == 0.5
|
|
|
|
|
|
def test_prompt_confidence_falls_back_to_the_caller_default():
|
|
assert prompt_confidence(UNBOUNDED, default=0.0) == 0.0
|
|
|
|
|
|
def test_relevance_confidence_falls_back_to_zero():
|
|
assert relevance_confidence({"confidence": UNBOUNDED}) == 0.0
|