Skip to content

Commit 6c88daf

Browse files
committed
More variable name fixes
1 parent 5455792 commit 6c88daf

File tree

10 files changed

+70
-237
lines changed

10 files changed

+70
-237
lines changed

agent-memory-client/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,6 @@ results = await client.search_long_term_memory(
263263
limit=10
264264
)
265265

266-
# Legacy parameter names are still supported for backward compatibility
267-
legacy_config = RecencyConfig(
268-
recency_boost=True,
269-
w_sem=0.8, # Deprecated: use semantic_weight
270-
w_recency=0.2, # Deprecated: use recency_weight
271-
wf=0.6, # Deprecated: use freshness_weight
272-
wa=0.4 # Deprecated: use novelty_weight
273-
)
274266
```
275267

276268
## Error Handling

agent-memory-client/agent_memory_client/client.py

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -675,45 +675,14 @@ async def search_long_term_memory(
675675
if recency is not None:
676676
if recency.recency_boost is not None:
677677
payload["recency_boost"] = recency.recency_boost
678-
# Handle both new descriptive names and legacy short names
679-
# Prefer new descriptive names, fall back to old short names
680-
semantic_weight = (
681-
recency.semantic_weight
682-
if recency.semantic_weight is not None
683-
else recency.w_sem
684-
)
685-
if semantic_weight is not None:
686-
payload["recency_semantic_weight"] = semantic_weight
687-
payload["recency_w_sem"] = semantic_weight # For backward compatibility
688-
689-
recency_weight = (
690-
recency.recency_weight
691-
if recency.recency_weight is not None
692-
else recency.w_recency
693-
)
694-
if recency_weight is not None:
695-
payload["recency_recency_weight"] = recency_weight
696-
payload["recency_w_recency"] = (
697-
recency_weight # For backward compatibility
698-
)
699-
700-
freshness_weight = (
701-
recency.freshness_weight
702-
if recency.freshness_weight is not None
703-
else recency.wf
704-
)
705-
if freshness_weight is not None:
706-
payload["recency_freshness_weight"] = freshness_weight
707-
payload["recency_wf"] = freshness_weight # For backward compatibility
708-
709-
novelty_weight = (
710-
recency.novelty_weight
711-
if recency.novelty_weight is not None
712-
else recency.wa
713-
)
714-
if novelty_weight is not None:
715-
payload["recency_novelty_weight"] = novelty_weight
716-
payload["recency_wa"] = novelty_weight # For backward compatibility
678+
if recency.semantic_weight is not None:
679+
payload["recency_semantic_weight"] = recency.semantic_weight
680+
if recency.recency_weight is not None:
681+
payload["recency_recency_weight"] = recency.recency_weight
682+
if recency.freshness_weight is not None:
683+
payload["recency_freshness_weight"] = recency.freshness_weight
684+
if recency.novelty_weight is not None:
685+
payload["recency_novelty_weight"] = recency.novelty_weight
717686
if recency.half_life_last_access_days is not None:
718687
payload["recency_half_life_last_access_days"] = (
719688
recency.half_life_last_access_days

agent-memory-client/agent_memory_client/models.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -250,27 +250,17 @@ class RecencyConfig(BaseModel):
250250
recency_boost: bool | None = Field(
251251
default=None, description="Enable recency-aware re-ranking"
252252
)
253-
# Legacy short parameter names (deprecated)
254-
w_sem: float | None = Field(default=None, description="Weight for semantic score")
255-
w_recency: float | None = Field(
256-
default=None, description="Weight for recency composite"
257-
)
258-
wf: float | None = Field(default=None, description="Weight for freshness")
259-
wa: float | None = Field(default=None, description="Weight for age/novelty")
260-
261-
# New descriptive parameter names (preferred)
262253
semantic_weight: float | None = Field(
263-
default=None,
264-
description="Weight for semantic similarity (preferred over w_sem)",
254+
default=None, description="Weight for semantic similarity"
265255
)
266256
recency_weight: float | None = Field(
267-
default=None, description="Weight for recency score (preferred over w_recency)"
257+
default=None, description="Weight for recency score"
268258
)
269259
freshness_weight: float | None = Field(
270-
default=None, description="Weight for freshness component (preferred over wf)"
260+
default=None, description="Weight for freshness component"
271261
)
272262
novelty_weight: float | None = Field(
273-
default=None, description="Weight for novelty/age component (preferred over wa)"
263+
default=None, description="Weight for novelty/age component"
274264
)
275265

276266
half_life_last_access_days: float | None = Field(

agent-memory-client/tests/test_client.py

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ async def test_search_all_long_term_memories(self, enhanced_test_client):
301301

302302
class TestRecencyConfig:
303303
@pytest.mark.asyncio
304-
async def test_recency_config_payload(self, enhanced_test_client):
305-
"""Ensure RecencyConfig fields are forwarded in the search payload."""
304+
async def test_recency_config_descriptive_parameters(self, enhanced_test_client):
305+
"""Test that RecencyConfig descriptive parameters are properly sent to API."""
306306
with patch.object(enhanced_test_client._client, "post") as mock_post:
307307
mock_response = AsyncMock()
308308
mock_response.raise_for_status.return_value = None
@@ -313,76 +313,32 @@ async def test_recency_config_payload(self, enhanced_test_client):
313313

314314
rc = RecencyConfig(
315315
recency_boost=True,
316-
w_sem=0.7,
317-
w_recency=0.3,
318-
wf=0.6,
319-
wa=0.4,
316+
semantic_weight=0.8,
317+
recency_weight=0.2,
318+
freshness_weight=0.6,
319+
novelty_weight=0.4,
320320
half_life_last_access_days=7,
321321
half_life_created_days=30,
322322
server_side_recency=True,
323323
)
324324

325325
await enhanced_test_client.search_long_term_memory(
326-
text="q", recency=rc, limit=5
326+
text="search query", recency=rc, limit=5
327327
)
328328

329-
# Verify payload contained recency fields (both old and new names for compatibility)
329+
# Verify payload contains descriptive parameter names
330330
args, kwargs = mock_post.call_args
331331
assert args[0] == "/v1/long-term-memory/search"
332332
body = kwargs["json"]
333333
assert body["recency_boost"] is True
334-
# Old parameter names (for backward compatibility)
335-
assert body["recency_w_sem"] == 0.7
336-
assert body["recency_w_recency"] == 0.3
337-
assert body["recency_wf"] == 0.6
338-
assert body["recency_wa"] == 0.4
339-
# New descriptive parameter names (preferred)
340-
assert body["recency_semantic_weight"] == 0.7
341-
assert body["recency_recency_weight"] == 0.3
334+
assert body["recency_semantic_weight"] == 0.8
335+
assert body["recency_recency_weight"] == 0.2
342336
assert body["recency_freshness_weight"] == 0.6
343337
assert body["recency_novelty_weight"] == 0.4
344338
assert body["recency_half_life_last_access_days"] == 7
345339
assert body["recency_half_life_created_days"] == 30
346340
assert body["server_side_recency"] is True
347341

348-
async def test_recency_config_new_parameter_names(self, enhanced_test_client):
349-
"""Test that new descriptive parameter names work and take precedence."""
350-
with patch.object(enhanced_test_client._client, "post") as mock_post:
351-
mock_response = AsyncMock()
352-
mock_response.raise_for_status.return_value = None
353-
mock_response.json.return_value = MemoryRecordResults(
354-
total=0, memories=[], next_offset=None
355-
).model_dump()
356-
mock_post.return_value = mock_response
357-
358-
rc = RecencyConfig(
359-
recency_boost=True,
360-
semantic_weight=0.9, # New parameter name should take precedence
361-
w_sem=0.1, # Old parameter name (should be ignored)
362-
recency_weight=0.1,
363-
freshness_weight=0.7,
364-
novelty_weight=0.3,
365-
half_life_last_access_days=5,
366-
half_life_created_days=20,
367-
server_side_recency=True,
368-
)
369-
370-
await enhanced_test_client.search_long_term_memory(
371-
text="test query", recency=rc, limit=10
372-
)
373-
374-
# Verify new parameter names take precedence
375-
args, kwargs = mock_post.call_args
376-
body = kwargs["json"]
377-
assert body["recency_boost"] is True
378-
# Both old and new names should be present
379-
assert body["recency_w_sem"] == 0.9 # Uses new value, not old
380-
assert body["recency_semantic_weight"] == 0.9 # New parameter
381-
assert body["recency_recency_weight"] == 0.1
382-
assert body["recency_freshness_weight"] == 0.7
383-
assert body["recency_novelty_weight"] == 0.3
384-
assert body["server_side_recency"] is True
385-
386342

387343
class TestClientSideValidation:
388344
"""Tests for client-side validation methods."""

agent_memory_server/api.py

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -131,40 +131,28 @@ def _calculate_context_usage_percentages(
131131

132132

133133
def _build_recency_params(payload: SearchRequest) -> dict[str, Any]:
134-
"""Build recency parameters dict with backward compatibility.
135-
136-
Prefers new descriptive parameter names over old short names.
137-
"""
138-
# Use new parameter names if available, fall back to old ones, then defaults
139-
semantic_weight = (
140-
payload.recency_semantic_weight
141-
if payload.recency_semantic_weight is not None
142-
else (payload.recency_w_sem if payload.recency_w_sem is not None else 0.8)
143-
)
144-
recency_weight = (
145-
payload.recency_recency_weight
146-
if payload.recency_recency_weight is not None
147-
else (
148-
payload.recency_w_recency if payload.recency_w_recency is not None else 0.2
149-
)
150-
)
151-
freshness_weight = (
152-
payload.recency_freshness_weight
153-
if payload.recency_freshness_weight is not None
154-
else (payload.recency_wf if payload.recency_wf is not None else 0.6)
155-
)
156-
novelty_weight = (
157-
payload.recency_novelty_weight
158-
if payload.recency_novelty_weight is not None
159-
else (payload.recency_wa if payload.recency_wa is not None else 0.4)
160-
)
161-
134+
"""Build recency parameters dict from payload."""
162135
return {
163-
# Use new descriptive names internally
164-
"semantic_weight": semantic_weight,
165-
"recency_weight": recency_weight,
166-
"freshness_weight": freshness_weight,
167-
"novelty_weight": novelty_weight,
136+
"semantic_weight": (
137+
payload.recency_semantic_weight
138+
if payload.recency_semantic_weight is not None
139+
else 0.8
140+
),
141+
"recency_weight": (
142+
payload.recency_recency_weight
143+
if payload.recency_recency_weight is not None
144+
else 0.2
145+
),
146+
"freshness_weight": (
147+
payload.recency_freshness_weight
148+
if payload.recency_freshness_weight is not None
149+
else 0.6
150+
),
151+
"novelty_weight": (
152+
payload.recency_novelty_weight
153+
if payload.recency_novelty_weight is not None
154+
else 0.4
155+
),
168156
"half_life_last_access_days": (
169157
payload.recency_half_life_last_access_days
170158
if payload.recency_half_life_last_access_days is not None
@@ -626,26 +614,7 @@ async def search_long_term_memory(
626614
return raw_results
627615

628616
now = _dt.now(UTC)
629-
recency_params = {
630-
"w_sem": payload.recency_w_sem
631-
if payload.recency_w_sem is not None
632-
else 0.8,
633-
"w_recency": payload.recency_w_recency
634-
if payload.recency_w_recency is not None
635-
else 0.2,
636-
"wf": payload.recency_wf if payload.recency_wf is not None else 0.6,
637-
"wa": payload.recency_wa if payload.recency_wa is not None else 0.4,
638-
"half_life_last_access_days": (
639-
payload.recency_half_life_last_access_days
640-
if payload.recency_half_life_last_access_days is not None
641-
else 7.0
642-
),
643-
"half_life_created_days": (
644-
payload.recency_half_life_created_days
645-
if payload.recency_half_life_created_days is not None
646-
else 30.0
647-
),
648-
}
617+
recency_params = _build_recency_params(payload)
649618
ranked = long_term_memory.rerank_with_recency(
650619
raw_results.memories, now=now, params=recency_params
651620
)

agent_memory_server/long_term_memory.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,9 +1391,8 @@ def score_recency(
13911391
)
13921392
half_life_created = max(float(params.get("half_life_created_days", 30.0)), 0.001)
13931393

1394-
# Support both old and new parameter names for backward compatibility
1395-
freshness_weight = float(params.get("freshness_weight", params.get("wf", 0.6)))
1396-
novelty_weight = float(params.get("novelty_weight", params.get("wa", 0.4)))
1394+
freshness_weight = float(params.get("freshness_weight", 0.6))
1395+
novelty_weight = float(params.get("novelty_weight", 0.4))
13971396

13981397
# Convert to decay rates
13991398
access_decay_rate = log(2.0) / half_life_last_access
@@ -1420,9 +1419,8 @@ def rerank_with_recency(
14201419
14211420
score = semantic_weight * (1 - dist) + recency_weight * recency_score
14221421
"""
1423-
# Support both old and new parameter names for backward compatibility
1424-
semantic_weight = float(params.get("semantic_weight", params.get("w_sem", 0.8)))
1425-
recency_weight = float(params.get("recency_weight", params.get("w_recency", 0.2)))
1422+
semantic_weight = float(params.get("semantic_weight", 0.8))
1423+
recency_weight = float(params.get("recency_weight", 0.2))
14261424

14271425
def combined_score(mem: MemoryRecordResult) -> float:
14281426
similarity = 1.0 - float(mem.dist)

agent_memory_server/models.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -372,41 +372,27 @@ class SearchRequest(BaseModel):
372372
default=None,
373373
description="Enable recency-aware re-ranking (defaults to enabled if None)",
374374
)
375-
recency_w_sem: float | None = Field(
376-
default=None, description="Weight for semantic similarity"
377-
)
378-
recency_w_recency: float | None = Field(
379-
default=None, description="Weight for recency score"
380-
)
381-
recency_wf: float | None = Field(
382-
default=None, description="Weight for freshness component"
383-
)
384-
recency_wa: float | None = Field(
385-
default=None, description="Weight for novelty (age) component"
386-
)
387-
recency_half_life_last_access_days: float | None = Field(
388-
default=None, description="Half-life (days) for last_accessed decay"
389-
)
390-
recency_half_life_created_days: float | None = Field(
391-
default=None, description="Half-life (days) for created_at decay"
392-
)
393-
394-
# New descriptive parameter names (preferred over short names above)
395375
recency_semantic_weight: float | None = Field(
396376
default=None,
397-
description="Weight for semantic similarity (preferred over recency_w_sem)",
377+
description="Weight for semantic similarity",
398378
)
399379
recency_recency_weight: float | None = Field(
400380
default=None,
401-
description="Weight for recency score (preferred over recency_w_recency)",
381+
description="Weight for recency score",
402382
)
403383
recency_freshness_weight: float | None = Field(
404384
default=None,
405-
description="Weight for freshness component (preferred over recency_wf)",
385+
description="Weight for freshness component",
406386
)
407387
recency_novelty_weight: float | None = Field(
408388
default=None,
409-
description="Weight for novelty (age) component (preferred over recency_wa)",
389+
description="Weight for novelty (age) component",
390+
)
391+
recency_half_life_last_access_days: float | None = Field(
392+
default=None, description="Half-life (days) for last_accessed decay"
393+
)
394+
recency_half_life_created_days: float | None = Field(
395+
default=None, description="Half-life (days) for created_at decay"
410396
)
411397

412398
# Server-side recency rerank (Redis-only path) toggle

agent_memory_server/utils/redis_query.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ def apply_recency(
5757
) -> RecencyAggregationQuery:
5858
params = params or {}
5959

60-
# Support both old and new parameter names for backward compatibility
61-
semantic_weight = float(params.get("semantic_weight", params.get("w_sem", 0.8)))
62-
recency_weight = float(
63-
params.get("recency_weight", params.get("w_recency", 0.2))
64-
)
65-
freshness_weight = float(params.get("freshness_weight", params.get("wf", 0.6)))
66-
novelty_weight = float(params.get("novelty_weight", params.get("wa", 0.4)))
60+
semantic_weight = float(params.get("semantic_weight", 0.8))
61+
recency_weight = float(params.get("recency_weight", 0.2))
62+
freshness_weight = float(params.get("freshness_weight", 0.6))
63+
novelty_weight = float(params.get("novelty_weight", 0.4))
6764
half_life_access = float(params.get("half_life_last_access_days", 7.0))
6865
half_life_created = float(params.get("half_life_created_days", 30.0))
6966

0 commit comments

Comments
 (0)