From 54cd62dbcf74e97ce50434cfd386db5cdf21a8b0 Mon Sep 17 00:00:00 2001 From: zerone0x Date: Sat, 28 Mar 2026 13:17:33 +0800 Subject: [PATCH] fix(memos-local-openclaw): use limit and minScore query params in Viewer search API Read limit and minScore from query params instead of ignoring them. Use minScore as the semantic threshold instead of hardcoded 0.64. Truncate results by limit and include both params in the response. Fixes #1372 Co-Authored-By: Claude Opus 4.6 --- apps/memos-local-openclaw/src/viewer/server.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/memos-local-openclaw/src/viewer/server.ts b/apps/memos-local-openclaw/src/viewer/server.ts index ea35bcaf2..3f9b089a6 100644 --- a/apps/memos-local-openclaw/src/viewer/server.ts +++ b/apps/memos-local-openclaw/src/viewer/server.ts @@ -770,6 +770,9 @@ export class ViewerServer { const q = url.searchParams.get("q") ?? ""; if (!q.trim()) { this.jsonResponse(res, { results: [], query: q }); return; } + const limit = Math.min(100, Math.max(1, Number(url.searchParams.get("limit")) || 20)); + const minScore = Math.max(0.35, Math.min(1, Number(url.searchParams.get("minScore")) || 0.64)); + const role = url.searchParams.get("role") ?? undefined; const session = url.searchParams.get("session") ?? undefined; const owner = url.searchParams.get("owner") ?? undefined; @@ -810,7 +813,7 @@ export class ViewerServer { } } - const SEMANTIC_THRESHOLD = 0.64; + const SEMANTIC_THRESHOLD = minScore; const VECTOR_TIMEOUT_MS = 8000; let vectorResults: any[] = []; let scoreMap = new Map(); @@ -849,7 +852,7 @@ export class ViewerServer { if (!seenIds.has(r.id)) { seenIds.add(r.id); merged.push(r); } } - const results = merged.length > 0 ? merged : ftsResults.slice(0, 20); + const results = (merged.length > 0 ? merged : ftsResults.slice(0, limit)).slice(0, limit); this.store.recordViewerEvent("search"); this.jsonResponse(res, { @@ -858,6 +861,8 @@ export class ViewerServer { vectorCount: vectorResults.length, ftsCount: ftsResults.length, total: results.length, + limit, + minScore, }); }