Skip to content

fix(memos-local-openclaw): Viewer API search limit and minScore params not working#1376

Open
zerone0x wants to merge 1 commit intoMemTensor:mainfrom
zerone0x:fix/viewer-search-limit-minscore
Open

fix(memos-local-openclaw): Viewer API search limit and minScore params not working#1376
zerone0x wants to merge 1 commit intoMemTensor:mainfrom
zerone0x:fix/viewer-search-limit-minscore

Conversation

@zerone0x
Copy link
Copy Markdown
Contributor

Description

Fix the /api/search endpoint in apps/memos-local-openclaw/src/viewer/server.ts where limit and minScore query parameters were being completely ignored.

Changes

  • Read limit from query params (clamped to 1-100, default 20)
  • Read minScore from query params (clamped to 0.35-1.0, default 0.64)
  • Use minScore as the semantic similarity threshold instead of the hardcoded 0.64
  • Truncate final results array by limit
  • Include limit and minScore in the JSON response

Related Issue

Fixes #1372

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

…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>
Copilot AI review requested due to automatic review settings March 28, 2026 05:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 limit and minScore from query params (with clamping and defaults).
  • Use minScore instead of a hardcoded semantic threshold during vector-hit filtering.
  • Truncate the final response results to limit and include limit/minScore in the response payload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +773 to +774
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));
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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));

Copilot uses AI. Check for mistakes.
}

const results = merged.length > 0 ? merged : ftsResults.slice(0, 20);
const results = (merged.length > 0 ? merged : ftsResults.slice(0, limit)).slice(0, limit);
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
const results = (merged.length > 0 ? merged : ftsResults.slice(0, limit)).slice(0, limit);
const results = merged.slice(0, limit);

Copilot uses AI. Check for mistakes.
Comment on lines +773 to +774
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));
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(memos-local-openclaw): Viewer API search 接口 limit 和 minScore 参数不生效

2 participants