Preserve independent conversational memory fragments
This commit is contained in:
+11
-2
@@ -120,6 +120,9 @@ class QwenMemoryConfig:
|
||||
text_memory_threshold: float = 0.40
|
||||
text_memory_write_threshold: float = 0.5
|
||||
text_memory_replace_threshold: float = 0.35
|
||||
# A slightly more permissive boundary for recognizing a same-attribute
|
||||
# update. Unrelated fragments still remain independent V2 records.
|
||||
text_memory_update_overlap_threshold: float = 0.30
|
||||
text_memory_key_tokens: int = 128
|
||||
text_memory_overlap_threshold: float = 0.22
|
||||
automatic_memory: bool = False
|
||||
@@ -197,6 +200,8 @@ class QwenMemoryConfig:
|
||||
raise ValueError("text_memory_write_threshold must be between 0 and 1")
|
||||
if not -1.0 <= self.text_memory_replace_threshold <= 1.0:
|
||||
raise ValueError("text_memory_replace_threshold must be between -1 and 1")
|
||||
if not -1.0 <= self.text_memory_update_overlap_threshold <= 1.0:
|
||||
raise ValueError("text_memory_update_overlap_threshold must be between -1 and 1")
|
||||
if self.text_memory_key_tokens < 1:
|
||||
raise ValueError("text_memory_key_tokens must be positive")
|
||||
if not 0.0 <= self.text_memory_overlap_threshold <= 1.0:
|
||||
@@ -284,6 +289,9 @@ def load_memory_config(adapter_dir: str | Path) -> QwenMemoryConfig:
|
||||
text_memory_threshold=float(saved.get("text_memory_threshold", 0.40)),
|
||||
text_memory_write_threshold=float(saved.get("text_memory_write_threshold", 0.5)),
|
||||
text_memory_replace_threshold=float(saved.get("text_memory_replace_threshold", 0.35)),
|
||||
text_memory_update_overlap_threshold=float(
|
||||
saved.get("text_memory_update_overlap_threshold", 0.30)
|
||||
),
|
||||
text_memory_key_tokens=int(saved.get("text_memory_key_tokens", 128)),
|
||||
text_memory_overlap_threshold=float(saved.get("text_memory_overlap_threshold", 0.22)),
|
||||
automatic_memory=bool(saved.get("automatic_memory", False)),
|
||||
@@ -1684,7 +1692,7 @@ class QwenDynamicMemoryModel(nn.Module):
|
||||
else:
|
||||
best_similarity = torch.tensor(-1.0, device=key.device)
|
||||
best_slot = torch.tensor(0, dtype=torch.long, device=key.device)
|
||||
if float(best_similarity) >= self.memory_config.text_memory_replace_threshold:
|
||||
if float(best_similarity) >= self.memory_config.text_memory_update_overlap_threshold:
|
||||
slot = int(best_slot.item())
|
||||
else:
|
||||
free_slots = (~valid_slots).nonzero(as_tuple=False).flatten()
|
||||
@@ -1717,7 +1725,8 @@ class QwenDynamicMemoryModel(nn.Module):
|
||||
# duplicate/update of an existing fact.
|
||||
v2_slot_index = (
|
||||
slot
|
||||
if float(best_similarity) >= self.memory_config.text_memory_replace_threshold
|
||||
if float(best_similarity)
|
||||
>= self.memory_config.text_memory_update_overlap_threshold
|
||||
else -1
|
||||
)
|
||||
if v2_slot_index >= 0 and self.memory_os_v2 is not None:
|
||||
|
||||
Reference in New Issue
Block a user