fix(server): fetch filtered dashboard memories beyond default page (#5753)

This commit is contained in:
冯基魁
2026-06-24 11:49:06 +05:30
committed by GitHub
parent 3497f26a00
commit 09f181c577
3 changed files with 38 additions and 5 deletions
+7 -3
View File
@@ -16,7 +16,7 @@ from errors import (
upstream_error,
upstream_error_handler,
)
from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi import Depends, FastAPI, HTTPException, Query, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, RedirectResponse
from mem0.exceptions import ValidationError as Mem0ValidationError
@@ -409,6 +409,7 @@ def get_all_memories(
user_id: Optional[str] = None,
run_id: Optional[str] = None,
agent_id: Optional[str] = None,
top_k: Optional[int] = Query(None, ge=0, le=ALL_MEMORIES_LIMIT),
_auth=Depends(verify_auth),
):
"""Retrieve stored memories. Lists all memories when no identifier is provided (admin only)."""
@@ -417,11 +418,14 @@ def get_all_memories(
auth_type = getattr(request.state, "auth_type", "none")
if _auth is not None and _auth.role != "admin" and auth_type not in {"admin_api_key", "disabled"}:
raise HTTPException(status_code=403, detail="Admin role required to list all memories.")
return _list_all_memories()
return _list_all_memories(limit=top_k if top_k is not None else ALL_MEMORIES_LIMIT)
filters = {
k: v for k, v in {"user_id": user_id, "run_id": run_id, "agent_id": agent_id}.items() if v is not None
}
return get_memory_instance().get_all(filters=filters)
params = {"filters": filters}
if top_k is not None:
params["top_k"] = top_k
return get_memory_instance().get_all(**params)
except HTTPException:
raise
except Exception: