Skip to content

Commit 0277c47

Browse files
authored
Merge pull request #134 from Dooders/dev
Dev
2 parents 935a8b9 + 98afca8 commit 0277c47

6 files changed

Lines changed: 265 additions & 129 deletions

File tree

memory/embeddings/vector_store.py

Lines changed: 23 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -556,60 +556,31 @@ def store_memory_vectors(
556556
embeddings = memory_entry.get("embeddings", {})
557557
metadata = memory_entry.get("metadata", {})
558558

559-
def store_vector(
560-
index,
561-
memory_id: str,
562-
vector: List[float],
563-
metadata: Dict[str, Any],
564-
tier: str,
565-
) -> bool:
566-
"""
567-
Store a vector in the appropriate index.
568-
569-
Args:
570-
index: Vector index to store in
571-
memory_id: Unique identifier for the memory
572-
vector: Vector to store
573-
metadata: Metadata to store
574-
tier: Tier to store the vector in ("stm", "im", or "ltm")
575-
576-
Returns:
577-
True if storage was successful
578-
"""
579-
try:
580-
logger.debug(f"Storing {tier.upper()} vector for memory {memory_id}")
581-
return index.add(memory_id, vector, metadata)
582-
except Exception as e:
583-
logger.error(
584-
f"Failed to store {tier.upper()} vector for memory {memory_id}: {e}"
559+
try:
560+
logger.debug(f"Storing {tier.upper()} vector for memory {memory_id}")
561+
562+
# Store in appropriate index based on tier
563+
if tier == "stm":
564+
return self.stm_index.add(
565+
memory_id, embeddings["full_vector"], metadata
585566
)
567+
elif tier == "im":
568+
#! TODO: Use compressed vector
569+
return self.im_index.add(memory_id, embeddings["full_vector"], metadata)
570+
elif tier == "ltm":
571+
#! TODO: Use abstract vector
572+
return self.ltm_index.add(
573+
memory_id, embeddings["full_vector"], metadata
574+
)
575+
else:
576+
logger.error(f"Invalid tier: {tier}")
586577
return False
587578

588-
success = True
589-
590-
# Store in appropriate index based on tier
591-
if tier == "stm":
592-
success = store_vector(
593-
self.stm_index, memory_id, embeddings["full_vector"], metadata, "stm"
594-
)
595-
elif tier == "im":
596-
#! TODO: Use compressed vector
597-
logger.debug(
598-
f"@@@@@@@@@@@@@@@@@@@@@@@@@ Storing IM vector for memory {memory_id}"
599-
)
600-
success = store_vector(
601-
self.im_index, memory_id, embeddings["full_vector"], metadata, "im"
602-
)
603-
logger.debug(
604-
f"@@@@@@@@@@@@@@@@@@@@@@@@@ Result of storing IM vector: {success}"
605-
)
606-
elif tier == "ltm":
607-
#! TODO: Use abstract vector
608-
success = store_vector(
609-
self.ltm_index, memory_id, embeddings["full_vector"], metadata, "ltm"
579+
except Exception as e:
580+
logger.error(
581+
f"Failed to store {tier.upper()} vector for memory {memory_id}: {e}"
610582
)
611-
612-
return success
583+
return False
613584

614585
def find_similar_memories(
615586
self,
@@ -654,38 +625,18 @@ def filter_fn(metadata):
654625
logger.debug("Found match for type in memory_type: %s", value)
655626
continue
656627

657-
# Try match in nested content.metadata
658-
if "content" in metadata and isinstance(metadata["content"], dict):
659-
content = metadata["content"]
660-
if "metadata" in content and isinstance(
661-
content["metadata"], dict
662-
):
663-
content_metadata = content["metadata"]
664-
if (
665-
key in content_metadata
666-
and content_metadata[key] == value
667-
):
668-
logger.debug(
669-
"Found nested match for %s: %s in content.metadata",
670-
key,
671-
value,
672-
)
673-
continue
674-
675628
# No match found for this key
676629
unmatched_keys.append((key, value))
677-
return False
678630

679631
if unmatched_keys:
680632
logger.debug(
681633
"No matches found for the following keys and values: %s",
682634
unmatched_keys,
683635
)
636+
return False
684637
else:
685638
logger.debug("All filter criteria matched")
686-
# All keys matched
687-
logger.debug("All filter criteria matched")
688-
return True
639+
return True
689640

690641
# Select the appropriate index based on tier
691642
if tier == "im":

memory/search/strategies/similarity.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, memory_system: AgentMemorySystem):
3535
self.vector_store = self.memory_system.vector_store
3636
self.embedding_engine = self.memory_system.embedding_engine
3737
self.config = self.memory_system.config
38+
# self.logger = self.memory_system.logger #! future use
3839

3940
def name(self) -> str:
4041
"""Return the name of the search strategy.
@@ -111,13 +112,13 @@ def search(
111112

112113
# Generate query vector from input
113114
query_vector = self._generate_query_vector(query, current_tier)
114-
115+
115116
# Add detailed logging for vector generation
116117
logger.debug(
117118
"Query vector generation for tier %s - Input: %s, Output: %s",
118119
current_tier,
119120
query,
120-
query_vector
121+
query_vector,
121122
)
122123

123124
# Skip if vector generation failed
@@ -135,9 +136,9 @@ def search(
135136

136137
# Find similar vectors
137138
logger.debug(
138-
"About to call vector_store.find_similar_memories for tier %s with vector: %s",
139+
"About to call vector_store.find_similar_memories for tier %s with vector: %s",
139140
current_tier,
140-
query_vector
141+
query_vector,
141142
)
142143
try:
143144
similar_vectors = self.vector_store.find_similar_memories(
@@ -156,7 +157,7 @@ def search(
156157
logger.error(
157158
"Error in vector_store.find_similar_memories for tier %s: %s",
158159
current_tier,
159-
str(e)
160+
str(e),
160161
)
161162
continue
162163

@@ -307,7 +308,10 @@ def _generate_query_vector(
307308
vector,
308309
)
309310
else:
310-
logger.warning("Failed to generate vector for tier %s - encoding returned None", tier)
311+
logger.warning(
312+
"Failed to generate vector for tier %s - encoding returned None",
313+
tier,
314+
)
311315
return vector
312316
except Exception as e:
313317
logger.error("Error generating vector for tier %s: %s", tier, str(e))

memory/utils/serialization.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,18 @@ def load_memory_system_from_json(filepath: str, use_mock_redis: bool = False):
468468
}
469469

470470
# Store the vector
471-
vector_store.store_memory_vectors(memory_copy)
471+
472472

473473
# Determine the tier for the memory
474474
tier = memory_copy.get("tier")
475475
if tier == "stm":
476+
vector_store.store_memory_vectors(memory_copy, tier="stm")
476477
memory_agent.stm_store.store(agent_id, memory_copy)
477478
elif tier == "im":
479+
vector_store.store_memory_vectors(memory_copy, tier="im")
478480
memory_agent.im_store.store(agent_id, memory_copy)
479481
elif tier == "ltm":
482+
vector_store.store_memory_vectors(memory_copy, tier="ltm")
480483
memory_agent.ltm_store.store(memory_copy)
481484
else:
482485
logger.warning(f"Unknown tier '{tier}' for memory {memory_copy.get('memory_id')}")

validation/search/attribute/validation.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
## Overview
44

5-
This document outlines the comprehensive validation approach used to ensure the AttributeSearchStrategy implementation is robust, efficient, and reliable. The validation strategy covers basic functionality, advanced features, edge cases, and performance characteristics.
5+
This document outlines the comprehensive validation approach used to ensure the AttributeSearchStrategy implementation is robust, efficient, and reliable. The validation strategy covers basic functionality, advanced features, and edge cases.
66

77
## Validation Components
88

99
The validation suite for AttributeSearchStrategy consists of:
1010

1111
1. **Functional Testing**: A comprehensive test suite that verifies correctness of various search capabilities
12-
2. **Performance Testing**: Metrics-driven evaluation of search performance under various conditions
13-
3. **Edge Case Testing**: Validation of behavior with unexpected or boundary inputs
12+
2. **Edge Case Testing**: Validation of behavior with unexpected or boundary inputs
1413

1514
## Functional Validation
1615

@@ -79,15 +78,6 @@ Robustness is validated through testing of edge cases:
7978
- ✅ Long vs. short document handling
8079
- ✅ Varying document length impacts
8180

82-
## Performance Characteristics
83-
84-
The strategy has been performance-tested with:
85-
86-
- ✅ Varying memory sizes
87-
- ✅ Different scoring methods' performance impact
88-
- ✅ Pattern caching effectiveness
89-
- ✅ Memory impact across different query types
90-
9181
## Validation Methodology
9282

9383
### Test Data
@@ -126,12 +116,11 @@ The AttributeSearchStrategy validation is comprehensive because it:
126116
1. **Covers all public API parameters** - Every parameter of the `search()` method is tested
127117
2. **Tests all scoring methods** - All implemented scoring approaches are validated
128118
3. **Examines edge cases** - Boundary conditions and error handling are verified
129-
4. **Verifies performance characteristics** - Both speed and resource usage are measured
130-
5. **Validates across memory tiers** - Tests span STM, IM, and LTM memory stores
131-
6. **Tests with realistic data** - Uses representative memory content structures
119+
4. **Validates across memory tiers** - Tests span STM, IM, and LTM memory stores
120+
5. **Tests with realistic data** - Uses representative memory content structures
132121

133122
## Conclusion
134123

135-
The AttributeSearchStrategy implementation has been thoroughly validated across functional requirements, edge cases, and performance characteristics. The test suite provides confidence in the robustness of the implementation and establishes a baseline for regression testing as the codebase evolves.
124+
The AttributeSearchStrategy implementation has been thoroughly validated across functional requirements and edge cases. The test suite provides confidence in the robustness of the implementation and establishes a baseline for regression testing as the codebase evolves.
136125

137-
Both the test suite and performance testing components verify that the strategy successfully handles various memory structures, search patterns, and retrieval scenarios. All tests pass with the expected results, confirming that the implementation fulfills its designed purpose effectively.
126+
Both the test suite components verify that the strategy successfully handles various memory structures, search patterns, and retrieval scenarios. All tests pass with the expected results, confirming that the implementation fulfills its designed purpose effectively.

0 commit comments

Comments
 (0)