fix(memos-local-openclaw): Viewer API search limit and minScore params not working#1376
fix(memos-local-openclaw): Viewer API search limit and minScore params not working#1376zerone0x wants to merge 1 commit intoMemTensor:mainfrom
Conversation
…wer 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 MemTensor#1372 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes the memos-local-openclaw Viewer /api/search endpoint so callers can control search result size (limit) and semantic similarity threshold (minScore), addressing the bug reported in #1372.
Changes:
- Parse
limitandminScorefrom query params (with clamping and defaults). - Use
minScoreinstead of a hardcoded semantic threshold during vector-hit filtering. - Truncate the final response results to
limitand includelimit/minScorein the response payload.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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)); |
There was a problem hiding this comment.
The query param parsing uses Number(...) || default, which treats 0 as “missing”. That makes limit=0 default to 20 (instead of clamping to 1) and minScore=0 default to 0.64 (instead of clamping to 0.35). Consider parsing with Number.isFinite and applying the default only when the param is absent/NaN, then clamp the resulting value.
| 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 rawLimit = Number(url.searchParams.get("limit")); | |
| const limit = Math.min(100, Math.max(1, Number.isFinite(rawLimit) ? rawLimit : 20)); | |
| const rawMinScore = Number(url.searchParams.get("minScore")); | |
| const minScore = Math.max(0.35, Math.min(1, Number.isFinite(rawMinScore) ? rawMinScore : 0.64)); |
| } | ||
|
|
||
| const results = merged.length > 0 ? merged : ftsResults.slice(0, 20); | ||
| const results = (merged.length > 0 ? merged : ftsResults.slice(0, limit)).slice(0, limit); |
There was a problem hiding this comment.
merged always includes ftsResults (the second loop appends them unconditionally), so the merged.length > 0 ? merged : ftsResults.slice(...) branch is effectively redundant. Simplifying this to a single slice of merged would make the intent clearer and avoid implying there’s a distinct fallback path.
| const results = (merged.length > 0 ? merged : ftsResults.slice(0, limit)).slice(0, limit); | |
| const results = merged.slice(0, limit); |
| 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)); |
There was a problem hiding this comment.
This endpoint change is user-visible (new limit/minScore behavior + response fields) but there doesn’t appear to be coverage for /api/search query-param handling. Given the repo already has integration tests that spin up ViewerServer and call endpoints via fetch, please add a test asserting (a) results are truncated to limit and (b) minScore affects semantic hit inclusion (and that values are clamped to the documented ranges).
| 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 rawLimit = Number(url.searchParams.get("limit")); | |
| const limit = Math.min(100, Math.max(1, Number.isFinite(rawLimit) ? rawLimit : 20)); | |
| const rawMinScore = Number(url.searchParams.get("minScore")); | |
| const minScore = Math.max(0.35, Math.min(1, Number.isFinite(rawMinScore) ? rawMinScore : 0.64)); |
Description
Fix the
/api/searchendpoint inapps/memos-local-openclaw/src/viewer/server.tswherelimitandminScorequery parameters were being completely ignored.Changes
limitfrom query params (clamped to 1-100, default 20)minScorefrom query params (clamped to 0.35-1.0, default 0.64)minScoreas the semantic similarity threshold instead of the hardcoded0.64limitlimitandminScorein the JSON responseRelated Issue
Fixes #1372
Type of Change