Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent_memory_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ class Settings(BaseSettings):

# Compaction settings
compaction_every_minutes: int = 10
compact_semantic_duplicates: bool = True

# Docket task timeout for LLM-dependent tasks (in minutes)
# This controls how long tasks like memory compaction, extraction, and summarization
Expand Down
5 changes: 4 additions & 1 deletion agent_memory_server/long_term_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ async def compact_long_term_memories(
redis_client: Redis | None = None,
vector_distance_threshold: float = 0.2,
compact_hash_duplicates: bool = True,
compact_semantic_duplicates: bool = True,
compact_semantic_duplicates: bool | None = None,
perpetual: Perpetual = Perpetual(
every=timedelta(minutes=settings.compaction_every_minutes), automatic=True
),
Expand All @@ -653,6 +653,9 @@ async def compact_long_term_memories(

Returns the count of remaining memories after compaction.
"""
if compact_semantic_duplicates is None:
compact_semantic_duplicates = settings.compact_semantic_duplicates

if not redis_client:
redis_client = await get_redis_conn()

Expand Down
32 changes: 20 additions & 12 deletions tests/test_long_term_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ def mock_execute_command(command):
# Should return count from final search
assert remaining_count == 2 # Mocked total

def test_compact_semantic_duplicates_env_var(self, monkeypatch):
"""Regression: COMPACT_SEMANTIC_DUPLICATES env var must affect runtime behavior."""
monkeypatch.setenv("COMPACT_SEMANTIC_DUPLICATES", "false")
from agent_memory_server.config import Settings

s = Settings()
assert s.compact_semantic_duplicates is False

@pytest.mark.asyncio
async def test_promote_working_memory_to_long_term(self, mock_async_redis_client):
"""Test promoting memories from working memory to long-term storage"""
Expand Down Expand Up @@ -1032,9 +1040,9 @@ async def test_search_with_topics_filter_issue_156(
namespace=Namespace(eq="issue-156-ns"),
limit=10,
)
assert (
results_no_filter.total >= 1
), "Baseline search without topics filter failed"
assert results_no_filter.total >= 1, (
"Baseline search without topics filter failed"
)

# Test 2: Search WITH topics.any filter (was failing with 500 error)
results_topics_any = await search_long_term_memories(
Expand All @@ -1047,9 +1055,9 @@ async def test_search_with_topics_filter_issue_156(
# Verify the returned memories have the expected topic
for memory in results_topics_any.memories:
assert memory.topics is not None, "Memory should have topics"
assert (
"family" in memory.topics
), f"Memory topics {memory.topics} should contain 'family'"
assert "family" in memory.topics, (
f"Memory topics {memory.topics} should contain 'family'"
)

# Test 3: Search WITH topics.eq filter (was also failing with 500 error)
results_topics_eq = await search_long_term_memories(
Expand All @@ -1061,9 +1069,9 @@ async def test_search_with_topics_filter_issue_156(
assert results_topics_eq.total >= 1, "Search with topics.eq filter failed"
for memory in results_topics_eq.memories:
assert memory.topics is not None, "Memory should have topics"
assert (
"documents" in memory.topics
), f"Memory topics {memory.topics} should contain 'documents'"
assert "documents" in memory.topics, (
f"Memory topics {memory.topics} should contain 'documents'"
)

# Test 4: Search WITH entities filter (same underlying issue)
results_entities = await search_long_term_memories(
Expand All @@ -1075,9 +1083,9 @@ async def test_search_with_topics_filter_issue_156(
assert results_entities.total >= 1, "Search with entities filter failed"
for memory in results_entities.memories:
assert memory.entities is not None, "Memory should have entities"
assert (
"folder" in memory.entities
), f"Memory entities {memory.entities} should contain 'folder'"
assert "folder" in memory.entities, (
f"Memory entities {memory.entities} should contain 'folder'"
)

# Test 5: Combined topics and namespace filter (real-world scenario from issue)
results_combined = await search_long_term_memories(
Expand Down
Loading