Skip to content

Commit f667234

Browse files
aayush3011Aayush Kataria
andauthored
updating episodic memory prompts (#11)
* updating episodic memory prompts * code improvements * code improvements --------- Co-authored-by: Aayush Kataria <aayushkataria@Aayushs-MacBook-Pro-2.local>
1 parent 1b34fad commit f667234

30 files changed

Lines changed: 689 additions & 179 deletions

Docs/azure_testing.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ for i in range(10):
314314

315315
# Wait for the change-feed processor to catch up, then read derived memories.
316316
import time; time.sleep(15)
317-
print(memory.get_memories(user_id="user-1", thread_id="thread-1", memory_type="summary"))
318-
print(memory.get_memories(user_id="user-1", memory_type="fact"))
319-
print(memory.get_memories(user_id="user-1", memory_type="user_summary"))
317+
print(memory.get_memories(user_id="user-1", thread_id="thread-1", memory_types=["summary"]))
318+
print(memory.get_memories(user_id="user-1", memory_types=["fact"]))
319+
print(memory.get_memories(user_id="user-1", memory_types=["user_summary"]))
320320
```
321321

322322
### Change feed auto-processing
@@ -339,7 +339,7 @@ for i in range(3):
339339
# Wait a few seconds for the change feed to trigger, then check:
340340
import time
341341
time.sleep(10)
342-
results = memory.get_memories(user_id="user-1", thread_id=thread_id, memory_type="summary")
342+
results = memory.get_memories(user_id="user-1", thread_id=thread_id, memory_types=["summary"])
343343
print(results) # Should contain an auto-generated summary
344344
```
345345

@@ -348,9 +348,9 @@ Check the Function App logs to confirm the `on_memory_change` trigger fired and
348348
### Verify stored results
349349

350350
```python
351-
print(memory.get_memories(user_id="user-1", memory_type="summary"))
352-
print(memory.get_memories(user_id="user-1", memory_type="fact"))
353-
print(memory.get_memories(user_id="user-1", memory_type="user_summary"))
351+
print(memory.get_memories(user_id="user-1", memory_types=["summary"]))
352+
print(memory.get_memories(user_id="user-1", memory_types=["fact"]))
353+
print(memory.get_memories(user_id="user-1", memory_types=["user_summary"]))
354354
```
355355

356356
---

Docs/design_patterns.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Search across all memories (or filter by type) to find the most relevant context
162162
facts = await mem.search_cosmos(
163163
search_terms="database migration requirements",
164164
user_id="user-1",
165-
memory_type="fact",
165+
memory_types=["fact"],
166166
top_k=10,
167167
)
168168

@@ -185,10 +185,10 @@ profile = await mem.get_user_summary(user_id="user-1")
185185

186186
```python
187187
# All summaries for a user
188-
summaries = await mem.get_memories(user_id="user-1", memory_type="summary")
188+
summaries = await mem.get_memories(user_id="user-1", memory_types=["summary"])
189189

190190
# All facts
191-
facts = await mem.get_memories(user_id="user-1", memory_type="fact")
191+
facts = await mem.get_memories(user_id="user-1", memory_types=["fact"])
192192

193193
# Filter by thread_id
194194
thread_turns = await mem.get_memories(user_id="user-1", thread_id=THREAD_ID)
@@ -204,7 +204,7 @@ A typical chat application lifecycle looks like this:
204204
New session starts
205205
206206
├─ Retrieve user summary (get_user_summary)
207-
├─ Semantic search for prior facts (search_cosmos, type="fact")
207+
├─ Semantic search for prior facts (search_cosmos, memory_types=["fact"])
208208
209209
│ ┌── Conversation loop ──┐
210210
│ │ Store each turn │ (add_cosmos)
@@ -221,7 +221,7 @@ New session starts
221221
```python
222222
# --- Session start ---
223223
profile = await mem.get_user_summary(user_id="user-1")
224-
relevant = await mem.search_cosmos("topic of interest", user_id="user-1", memory_type="fact", top_k=5)
224+
relevant = await mem.search_cosmos("topic of interest", user_id="user-1", memory_types=["fact"], top_k=5)
225225

226226
# Build system prompt with profile and relevant facts
227227
system_prompt = build_prompt(profile, relevant)
@@ -280,7 +280,7 @@ await mem.extract_facts(user_id="user-1", thread_id="research-thread")
280280
facts = await mem.search_cosmos(
281281
search_terms="source database schema foreign keys",
282282
user_id="user-1",
283-
memory_type="fact",
283+
memory_types=["fact"],
284284
top_k=10,
285285
)
286286

Docs/local_testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ for i in range(3):
377377
5. Verify the summary was created:
378378

379379
```python
380-
result = memory.get_memories(user_id="user-001", thread_id=thread_id, memory_type="summary")
380+
result = memory.get_memories(user_id="user-001", thread_id=thread_id, memory_types=["summary"])
381381
print(result)
382382
```
383383

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Filter at retrieval time:
202202

203203
```python
204204
results = memory.search_cosmos("user preferences", user_id="u1", min_confidence=0.7)
205-
high_conf_facts = memory.get_memories(user_id="u1", memory_type="fact", min_confidence=0.7)
205+
high_conf_facts = memory.get_memories(user_id="u1", memory_types=["fact"], min_confidence=0.7)
206206
```
207207

208208
### Memory Reconciliation

Samples/Demo.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@
510510
" print(f\" [{m['id'][:8]}...] {m['content'][:60]}\")\n",
511511
"\n",
512512
"# Filter by type\n",
513-
"facts = memory.get_local(memory_type=\"fact\")\n",
513+
"facts = memory.get_local(memory_types=[\"fact\"])\n",
514514
"print(f\"\\nFact memories: {len(facts)}\")\n",
515515
"for m in facts:\n",
516516
" print(f\" [{m['id'][:8]}...] {m['content']}\")\n",
@@ -2739,7 +2739,7 @@
27392739
"source": [
27402740
"# Inspect the persisted derived memories across BOTH threads for this user.\n",
27412741
"for mt in (\"fact\", \"episodic\", \"procedural\"):\n",
2742-
" docs = memory.get_memories(user_id=USER_ID, memory_type=mt)\n",
2742+
" docs = memory.get_memories(user_id=USER_ID, memory_types=[mt])\n",
27432743
" print(f\"\\n{mt.upper()}S ({len(docs)}):\")\n",
27442744
" for d in docs:\n",
27452745
" print(f\" • {d['content'][:100]} [salience={d.get('salience')}]\")\n"
@@ -2879,7 +2879,7 @@
28792879
"stored = memory.get_user_summary(user_id=user_id)\n",
28802880
"if stored:\n",
28812881
" print(\"User Summary for\", user_id)\n",
2882-
" print(stored[0][\"content\"])\n",
2882+
" print(stored[\"content\"])\n",
28832883
"else:\n",
28842884
" print(\"No user summary found — run the generate_user_summary cell first.\")\n"
28852885
]

Samples/Demo_async.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@
499499
" print(f\" [{m['id'][:8]}...] {m['content'][:60]}\")\n",
500500
"\n",
501501
"# Filter by type\n",
502-
"facts = memory.get_local(memory_type=\"fact\")\n",
502+
"facts = memory.get_local(memory_types=[\"fact\"])\n",
503503
"print(f\"\\nFact memories: {len(facts)}\")\n",
504504
"for m in facts:\n",
505505
" print(f\" [{m['id'][:8]}...] {m['content']}\")\n",
@@ -2631,7 +2631,7 @@
26312631
"source": [
26322632
"# Inspect the persisted derived memories across BOTH threads for this user.\n",
26332633
"for mt in (\"fact\", \"episodic\", \"procedural\"):\n",
2634-
" docs = await memory.get_memories(user_id=USER_ID, memory_type=mt)\n",
2634+
" docs = await memory.get_memories(user_id=USER_ID, memory_types=[mt])\n",
26352635
" print(f\"\\n{mt.upper()}S ({len(docs)}):\")\n",
26362636
" for d in docs:\n",
26372637
" print(f\" • {d['content'][:100]} [salience={d.get('salience')}]\")\n"
@@ -2765,7 +2765,7 @@
27652765
"stored = await memory.get_user_summary(user_id=user_id)\n",
27662766
"if stored:\n",
27672767
" print(\"User Summary for\", user_id)\n",
2768-
" print(stored[0][\"content\"])\n",
2768+
" print(stored[\"content\"])\n",
27692769
"else:\n",
27702770
" print(\"No user summary found — run the generate_user_summary cell first.\")\n"
27712771
]

Samples/Demo_function_app.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
"## 5. Wait for the Function App to produce a summary\n",
255255
"\n",
256256
"`process_now_and_wait` polls Cosmos for the thread's summary doc until `timeout` seconds. This is **RU-costly**\n",
257-
"(repeated `get_memories(memory_type='summary')` queries) — only use it for demos and tests.\n",
257+
"(repeated `get_memories(memory_types=['summary'])` queries) — only use it for demos and tests.\n",
258258
"\n",
259259
"> If this returns `False`, check that:\n",
260260
"> * The Function App is deployed and running.\n",
@@ -594,7 +594,7 @@
594594
"def _show():\n",
595595
" counts = {}\n",
596596
" for mt in (\"summary\", \"fact\", \"episodic\", \"procedural\", \"user_summary\"):\n",
597-
" docs = memory.get_memories(user_id=USER_ID, memory_type=mt)\n",
597+
" docs = memory.get_memories(user_id=USER_ID, memory_types=[mt])\n",
598598
" counts[mt] = len(docs)\n",
599599
" print(f\"\\n{mt.upper()}S ({len(docs)}):\")\n",
600600
" for d in docs:\n",
@@ -610,7 +610,7 @@
610610
" break\n",
611611
" print(f\"\\n... fact / procedural extraction still in flight (attempt {attempt+1}/6, sleeping 15s)\")\n",
612612
" time.sleep(15)\n",
613-
" counts = {mt: len(memory.get_memories(user_id=USER_ID, memory_type=mt))\n",
613+
" counts = {mt: len(memory.get_memories(user_id=USER_ID, memory_types=[mt]))\n",
614614
" for mt in (\"summary\", \"fact\", \"episodic\", \"procedural\", \"user_summary\")}\n",
615615
"\n",
616616
"print(\"\\n=== Final state ===\")\n",
@@ -627,7 +627,7 @@
627627
"* **Per-turn embedding**: the SDK auto-embeds non-`turn` documents you `add_cosmos` directly. Raw `turn`\n",
628628
" records are intentionally not embedded — the function app does that during summary/extraction.\n",
629629
"* **Search across function-app-produced memories**: works exactly as in the in-process demo:\n",
630-
" `memory.search_cosmos(search_terms=\"\", memory_type=\"fact\", user_id=USER_ID)`.\n",
630+
" `memory.search_cosmos(search_terms=\"\", memory_types=[\"fact\"], user_id=USER_ID)`.\n",
631631
"* **Switch back to in-process** for ad-hoc work: instantiate the client without the `processor=` kwarg\n",
632632
" (or pass `InProcessProcessor()` explicitly) and use `generate_thread_summary` / `extract_memories`\n",
633633
" directly."

Samples/Demo_function_app_async.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@
537537
"async def _show():\n",
538538
" counts = {}\n",
539539
" for mt in (\"summary\", \"fact\", \"episodic\", \"procedural\", \"user_summary\"):\n",
540-
" docs = await memory.get_memories(user_id=USER_ID, memory_type=mt)\n",
540+
" docs = await memory.get_memories(user_id=USER_ID, memory_types=[mt])\n",
541541
" counts[mt] = len(docs)\n",
542542
" print(f\"\\n{mt.upper()}S ({len(docs)}):\")\n",
543543
" for d in docs:\n",
@@ -554,7 +554,7 @@
554554
" await asyncio.sleep(15)\n",
555555
" counts = {}\n",
556556
" for mt in (\"summary\", \"fact\", \"episodic\", \"procedural\", \"user_summary\"):\n",
557-
" docs = await memory.get_memories(user_id=USER_ID, memory_type=mt)\n",
557+
" docs = await memory.get_memories(user_id=USER_ID, memory_types=[mt])\n",
558558
" counts[mt] = len(docs)\n",
559559
"\n",
560560
"print(\"\\n=== Final state ===\")\n",

Samples/advanced_memory_lifecycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def main() -> None:
9292

9393
_header(5, "Archive: delete raw turns, keep derived memories")
9494
deleted = 0
95-
for m in mem.get_memories(user_id=user_id, thread_id=thread_id, memory_type="turn"):
95+
for m in mem.get_memories(user_id=user_id, thread_id=thread_id, memory_types=["turn"]):
9696
mem.delete_cosmos(memory_id=m["id"], thread_id=thread_id, user_id=user_id)
9797
deleted += 1
9898
print(f" deleted {deleted} raw turn(s)")

Samples/processing_fact_extraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def main() -> None:
7575
print(f"Extraction stats: {json.dumps(stats, indent=2)}\n")
7676

7777
for kind in ("fact", "procedural", "episodic"):
78-
items = mem.get_memories(user_id=user_id, memory_type=kind)
78+
items = mem.get_memories(user_id=user_id, memory_types=[kind])
7979
print(f"{kind.upper()}S ({len(items)}):")
8080
for it in items:
8181
tags = ", ".join(it.get("tags") or [])

0 commit comments

Comments
 (0)