Skip to content

Commit bc55656

Browse files
fix: memory API endpoints — pass user_id scope and strip embeddings
Memory endpoints were returning SPA fallback or raw embedding vectors. - Pass user_id='default' to get_all, search, and get_stats - Strip embedding arrays from responses to reduce payload size - Normalize echo_depth/echo_encodings from metadata for frontend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9a420ef commit bc55656

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

  • engram-bridge/engram_bridge/channels

engram-bridge/engram_bridge/channels/web.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,22 @@ async def list_sub_issues(issue_id: str):
796796

797797
# ── REST API — Memory endpoints ──
798798

799+
_MEM_USER = "default" # scope all memory queries to the default user
800+
801+
def _clean_memory(m: dict) -> dict:
802+
"""Strip embedding vectors and normalise fields for the frontend."""
803+
out = {k: v for k, v in m.items() if k != "embedding"}
804+
md = out.get("metadata") or {}
805+
out.setdefault("echo_depth", md.get("echo_depth", "none"))
806+
out.setdefault("echo_encodings", md.get("echo_encodings"))
807+
return out
808+
799809
@app.get("/api/memory/stats")
800810
async def memory_stats():
801811
if channel._memory is None:
802812
return JSONResponse({"error": "Memory not configured"}, status_code=503)
803813
try:
804-
stats = channel._memory.get_stats()
814+
stats = channel._memory.get_stats(user_id=_MEM_USER)
805815
return JSONResponse(stats)
806816
except Exception as exc:
807817
logger.exception("memory stats error")
@@ -814,9 +824,9 @@ async def memory_search(q: str = Query(default=""), limit: int = Query(default=2
814824
if not q.strip():
815825
return JSONResponse([])
816826
try:
817-
result = channel._memory.search(q.strip(), limit=limit)
827+
result = channel._memory.search(q.strip(), user_id=_MEM_USER, limit=limit)
818828
items = result.get("results", [])
819-
return JSONResponse(items)
829+
return JSONResponse([_clean_memory(m) for m in items])
820830
except Exception as exc:
821831
logger.exception("memory search error")
822832
return JSONResponse({"error": str(exc)}, status_code=500)
@@ -830,7 +840,8 @@ async def memory_all(
830840
if channel._memory is None:
831841
return JSONResponse({"error": "Memory not configured"}, status_code=503)
832842
try:
833-
memories = channel._memory.get_all()
843+
result = channel._memory.get_all(user_id=_MEM_USER, limit=limit)
844+
memories = result.get("results", []) if isinstance(result, dict) else result
834845
# Apply optional filters
835846
if layer:
836847
memories = [m for m in memories if m.get("layer") == layer]
@@ -842,7 +853,7 @@ async def memory_all(
842853
]
843854
# Return newest first, limited
844855
memories.sort(key=lambda m: m.get("updated_at", m.get("created_at", "")), reverse=True)
845-
return JSONResponse(memories[:limit])
856+
return JSONResponse([_clean_memory(m) for m in memories[:limit]])
846857
except Exception as exc:
847858
logger.exception("memory all error")
848859
return JSONResponse({"error": str(exc)}, status_code=500)
@@ -866,7 +877,7 @@ async def memory_get(memory_id: str):
866877
mem = channel._memory.get(memory_id)
867878
if not mem:
868879
return JSONResponse({"error": "Not found"}, status_code=404)
869-
return JSONResponse(mem)
880+
return JSONResponse(_clean_memory(mem))
870881
except Exception as exc:
871882
logger.exception("memory get error")
872883
return JSONResponse({"error": str(exc)}, status_code=500)

0 commit comments

Comments
 (0)