fix(server): forward explain in REST search (#5423)

This commit is contained in:
Chirag Arora
2026-06-10 12:15:31 +05:30
committed by GitHub
parent 2274b5acad
commit a86c87236d
2 changed files with 28 additions and 0 deletions
+2
View File
@@ -448,6 +448,8 @@ def search_memories(search_req: SearchRequest, _auth=Depends(verify_auth)):
params["top_k"] = search_req.top_k
if search_req.threshold is not None:
params["threshold"] = search_req.threshold
if search_req.explain is not None:
params["explain"] = search_req.explain
return get_memory_instance().search(query=search_req.query, filters=filters, **params)
except Exception:
raise upstream_error()
+26
View File
@@ -108,6 +108,32 @@ class TestSearchThreshold:
assert "threshold" not in kwargs
# ===========================================================================
# SearchRequest: explain parameter
# ===========================================================================
class TestSearchExplain:
"""Verify that the explain parameter is accepted and forwarded."""
def test_explain_true_forwarded(self, client, mock_memory):
resp = client.post("/search", json={"query": "food", "user_id": "u1", "explain": True})
assert resp.status_code == 200
_, kwargs = mock_memory.search.call_args
assert kwargs["explain"] is True
def test_explain_false_forwarded(self, client, mock_memory):
resp = client.post("/search", json={"query": "food", "user_id": "u1", "explain": False})
assert resp.status_code == 200
_, kwargs = mock_memory.search.call_args
assert kwargs["explain"] is False
def test_explain_omitted_uses_memory_default(self, client, mock_memory):
resp = client.post("/search", json={"query": "food", "user_id": "u1"})
assert resp.status_code == 200
_, kwargs = mock_memory.search.call_args
assert "explain" not in kwargs
# ===========================================================================
# SearchRequest: top_k + threshold together
# ===========================================================================