Skip to content

Commit f6246b1

Browse files
authored
Merge pull request #97 from Dooders/dev
**Improved **
2 parents 6c727bc + 6547631 commit f6246b1

File tree

7 files changed

+61
-201
lines changed

7 files changed

+61
-201
lines changed

memory/embeddings/utils.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,39 @@ def object_to_text(obj: Any) -> str:
9696
parts = []
9797
for key, value in obj.items():
9898
if isinstance(value, dict):
99-
formatted = f"{key}: " + object_to_text(value)
99+
# Special case for position
100+
if key == "position":
101+
# Special formatting for "position" to provide a descriptive
102+
# representation of location-related data.
103+
position_parts = []
104+
if "room" in value:
105+
# Include the room name if available.
106+
position_parts.append(f"room is {value['room']}")
107+
if "x" in value and "y" in value:
108+
# Include coordinates if both x and y are present.
109+
position_parts.append(f"coordinates: {value['x']}, {value['y']}")
110+
if "facing" in value:
111+
# Include the facing direction if available.
112+
position_parts.append(f"facing {value['facing']}")
113+
parts.append(" | ".join(position_parts))
114+
else:
115+
formatted = f"{key}: " + object_to_text(value)
116+
parts.append(formatted)
100117
elif isinstance(value, list):
101-
formatted = f"{key}: " + ", ".join(str(item) for item in value)
118+
# Special case for inventory
119+
if key == "inventory":
120+
if not value:
121+
parts.append("empty inventory")
122+
else:
123+
# Add individual "has" statements for each item
124+
for item in value:
125+
parts.append(f"has {item}")
126+
else:
127+
formatted = f"{key}: " + ", ".join(str(item) for item in value)
128+
parts.append(formatted)
102129
else:
103130
formatted = f"{key}: {value}"
104-
parts.append(formatted)
131+
parts.append(formatted)
105132
return " | ".join(parts)
106133
elif isinstance(obj, list):
107134
if not obj:

memory/search/strategies/match.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ def search(
109109
if tier == "im" and fields_mask:
110110
# Field masking with IM tier needs lower threshold
111111
adjusted_min_score = 0.4
112-
elif tier == "ltm":
113-
# LTM tier has more compressed vectors, lower threshold
114-
adjusted_min_score = 0.4
115112

116113
# Find similar memories
117114
search_limit = limit * 2 # Get more results for post-filtering

tests/embeddings/test_embedding_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,16 @@ def test_text_processing_for_embeddings():
186186

187187
# Dictionary with inventory
188188
inventory_dict = {"inventory": ["sword", "shield", "potion"]}
189-
assert "has sword, shield, potion" in object_to_text(inventory_dict)
189+
text = object_to_text(inventory_dict)
190+
assert "has sword" in text
191+
assert "has shield" in text
192+
assert "has potion" in text
190193

191194
# Dictionary with position
192195
position_dict = {"position": {"room": "kitchen", "x": 5, "y": 10}}
193196
position_text = object_to_text(position_dict)
194197
assert "room is kitchen" in position_text
195-
assert "coordinates" in position_text
196-
assert "5" in position_text
197-
assert "10" in position_text
198+
assert "coordinates: 5, 10" in position_text
198199

199200
def test_object_to_text_realistic_agent_state():
200201
"""Test object_to_text with realistic agent state information."""

tests/search/test_match_strategy.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_search_with_example_object(self):
5050
]
5151

5252
# Mock memory retrieval
53-
self.mock_stm_store.get.side_effect = lambda id: {
53+
self.mock_stm_store.get.side_effect = lambda agent_id, memory_id: {
5454
"mem1": {
5555
"id": "mem1",
5656
"content": {"type": "task", "priority": "high", "status": "pending"},
@@ -70,7 +70,7 @@ def test_search_with_example_object(self):
7070
"content": {"type": "note", "priority": "low"},
7171
"metadata": {"tags": ["reference"]},
7272
},
73-
}.get(id)
73+
}.get(memory_id)
7474

7575
# Perform search
7676
results = self.strategy.search(
@@ -105,7 +105,7 @@ def test_search_with_fields_mask(self):
105105
]
106106

107107
# Mock memory retrieval
108-
self.mock_im_store.get.side_effect = lambda id: {
108+
self.mock_im_store.get.side_effect = lambda agent_id, memory_id: {
109109
"mem1": {
110110
"id": "mem1",
111111
"content": {
@@ -125,7 +125,7 @@ def test_search_with_fields_mask(self):
125125
},
126126
"metadata": {},
127127
},
128-
}.get(id)
128+
}.get(memory_id)
129129

130130
# Perform search with fields mask
131131
results = self.strategy.search(
@@ -158,11 +158,11 @@ def test_search_with_min_score(self):
158158
]
159159

160160
# Mock memory retrieval
161-
self.mock_ltm_store.get.side_effect = lambda id: {
161+
self.mock_ltm_store.get.side_effect = lambda agent_id, memory_id: {
162162
"mem1": {"id": "mem1", "content": "matching content 1", "metadata": {}},
163163
"mem2": {"id": "mem2", "content": "matching content 2", "metadata": {}},
164164
"mem3": {"id": "mem3", "content": "matching content 3", "metadata": {}},
165-
}.get(id)
165+
}.get(memory_id)
166166

167167
# Perform search with min_score
168168
results = self.strategy.search(
@@ -193,7 +193,7 @@ def test_search_with_metadata_filter(self):
193193
]
194194

195195
# Mock memory retrieval
196-
self.mock_stm_store.get.side_effect = lambda id: {
196+
self.mock_stm_store.get.side_effect = lambda agent_id, memory_id: {
197197
"mem1": {
198198
"id": "mem1",
199199
"content": "content 1",
@@ -204,7 +204,7 @@ def test_search_with_metadata_filter(self):
204204
"content": "content 2",
205205
"metadata": {"type": "note"},
206206
},
207-
}.get(id)
207+
}.get(memory_id)
208208

209209
# Perform search with metadata filter
210210
metadata_filter = {"type": "task"}
@@ -349,11 +349,11 @@ def test_search_with_none_memory(self):
349349
]
350350

351351
# Mock memory retrieval with one memory missing
352-
self.mock_stm_store.get.side_effect = lambda id: {
352+
self.mock_stm_store.get.side_effect = lambda agent_id, memory_id: {
353353
"mem1": {"id": "mem1", "content": "content 1", "metadata": {}},
354354
"mem2": None, # Missing memory
355355
"mem3": {"id": "mem3", "content": "content 3", "metadata": {}},
356-
}.get(id)
356+
}.get(memory_id)
357357

358358
# Perform search
359359
results = self.strategy.search(

0 commit comments

Comments
 (0)