Skip to content

feat(#252): configurable similarity threshold for recall - #274

Merged
ajianaz merged 11 commits into
developfrom
feat/252-configurable-recall-threshold
Jun 11, 2026
Merged

ajianaz merged 11 commits into
developfrom
feat/252-configurable-recall-threshold

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #252

Add minimum similarity score threshold to recall operations. Results below threshold are filtered, enabling "I don't know" behavior instead of confident wrong answers.

Changes

Config (uteke.toml)

[recall]
min_score = 0.3          # default, skip results below 0.3 cosine similarity
min_score_strict = 0.5   # for --strict flag (critical queries)

CLI

uteke recall "quantum computing"              # uses config min_score (default 0.3)
uteke recall "quantum computing" --min 0.5    # per-query override
uteke recall "deploy staging" --strict         # uses min_score_strict

Core

  • All recall paths (vector, FTS5, hybrid RRF) filter by min_score
  • min_score == 0.0 = no filter (backward compatible)

Server API

  • POST /recall accepts min_score and strict in request body
  • Empty results with threshold return enriched JSON with diagnostic info

Threshold resolution

--min <value> > --strict (→ min_score_strict) > config min_score > 0.0

Files changed

  • crates/uteke-cli/src/config.rs — RecallConfig struct + [recall] section
  • crates/uteke-core/src/lib.rs — RecallConfig in Uteke struct, 4 new tests
  • crates/uteke-core/src/operations.rs — min_score filtering in all recall paths
  • crates/uteke-cli/src/main.rs — --min and --strict CLI flags
  • crates/uteke-cli/src/commands/recall.rs — threshold resolution + output
  • crates/uteke-cli/src/commands/server.rs — pass threshold to server
  • crates/uteke-cli/src/output.rs — threshold info in empty results
  • crates/uteke-server/src/main.rs — server-side threshold support

Tests

  • 112 total pass (4 new: threshold filtering, zero threshold, specific score, config override)
  • cargo test --workspace ✅
  • cargo clippy --workspace ✅ (no new warnings)

ajianaz added 5 commits June 10, 2026 23:31
- Task 1: Add [recall] config section (min_score, min_score_strict)
- Task 2: Add min_score parameter to all recall methods
- Task 3: Add RecallConfig to Uteke struct

Partially implements #252 — CLI/Server callers need updating.
- Task 4: Add --min and --strict flags to recall command
- Task 5: Server API supports min_score/strict in /recall endpoint
- Task 6: 4 new integration tests (112 total pass)

Threshold resolution: --min > --strict (min_score_strict) > config min_score > 0.0
Empty results with threshold show diagnostic info (JSON + human).

Closes #252
Comment thread crates/uteke-core/src/lib.rs Fixed
Comment thread crates/uteke-core/uteke_index.keys Fixed
@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (2)

  • crates/uteke-cli/src/commands/recall.rs:23 — The CLI now applies entity/category filtering after calling uteke.recall(...), but it still only fetches limit results from the core search. If some of those top limit items fail the metadata filter, the command can return fewer than the requested number even when additional matching memories exist just below the cutoff. The server code already compensates for this by over-fetching before post-filtering; the CLI path should do the same for consistent behavior.
  • crates/uteke-server/src/main.rs:713 — The CLI resolves the default threshold from config.recall.min_score, whose default is 0.3, but the server falls back to DEFAULT_MIN_SCORE = 0.0 when no [recall] section is configured. This makes the same recall request behave differently depending on whether it is executed locally or via the server, which is a functional inconsistency and likely to surprise users.

Review powered by cora-cli · BYOK · MIT

ajianaz added 2 commits June 11, 2026 00:19
…ategory server filter

- Remove committed uteke_index.keys/usearch, add to .gitignore
- Add entity/category fields to server RecallRequest + post-filter in route
- Suppress dead_code warning for recall_config (stored for future use)
- cargo fmt --all
… limit

Address Cora review: entity/category filtering after recall could
miss results because the original limit was too small. Now over-fetches
3x when metadata filters are present, then truncates to requested limit.
Comment thread crates/uteke-cli/src/main.rs Fixed
Comment thread crates/uteke-server/src/main.rs Fixed
- Mark 4 recall threshold tests as #[ignore] (require ONNX model)
- Fix clippy unnecessary_map_or in server.rs
- Fix clippy unnecessary closure in uteke-server
Comment thread crates/uteke-server/src/main.rs Fixed
@ajianaz
ajianaz force-pushed the feat/252-configurable-recall-threshold branch from bd7d4a6 to e4ecd64 Compare June 10, 2026 17:53
When entity/category filters are present, recall without min_score
to avoid discarding valid lower-ranked matches. Apply min_score
after metadata filtering, then truncate to requested limit.

Fixes CodeCora finding: over-fetch + pre-filter could miss valid
matches that satisfy metadata but rank below top-N.
@ajianaz
ajianaz force-pushed the feat/252-configurable-recall-threshold branch from e4ecd64 to d951d59 Compare June 10, 2026 17:53
Comment thread crates/uteke-server/src/main.rs Fixed
@ajianaz

ajianaz commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

Cora Review Findings — 2 Bugs Need Fixing

Bug 1: RRF scores ≠ cosine similarity

The min_score filter is applied to RRF-normalized scores (rank-based), not raw cosine similarity. In hybrid mode, a threshold of 0.3 or 0.5 can incorrectly filter out nearly all results even when vector matches are strong.

Fix: Apply min_score filter only to the raw cosine similarity component, not to the final RRF score. Or document clearly that hybrid mode uses a different score scale.

Bug 2: Server ignores [recall] config

The server resolves strict with hard-coded STRICT_THRESHOLD = 0.5 instead of reading from config. CLI and server behavior diverge.

Fix: Load RecallConfig in server startup and use it for threshold resolution.


Please address these before merge. Marking as review requested.

ajianaz added a commit that referenced this pull request Jun 11, 2026
…275)

Lesson learned from PR #274: CodeCora failure was dismissed as external
but Cora Review (separate check) found 2 real critical bugs. Every red
CI check must be investigated before merge, not dismissed.

Also merging dependabot PRs:
- PR #255: actions/checkout v4→v6 (CI pass, local verified)
- PR #256: trivy-action 0.9.2→0.36.0 (CI pass, local verified)
ajianaz added a commit that referenced this pull request Jun 11, 2026
Bug 1: RRF scores vs cosine similarity — min_score filter was applied
to normalized RRF scores (rank-based 0..1) in hybrid recall, not raw
cosine similarity. A threshold of 0.3 or 0.5 would incorrectly filter
out nearly all hybrid results even when vector matches were strong.
Fix: remove min_score filtering from recall_rrf() since RRF scores
are not comparable to cosine. Document that min_score only applies to
vector-only and fts5-only recall modes.

Bug 2: Server ignores [recall] config — strict mode used hard-coded
STRICT_THRESHOLD=0.5 instead of reading from uteke.toml [recall]
section. CLI and server behavior diverged.
Fix: add RecallFileSection to server config parsing, pass recall config
through ReqCtx, resolve thresholds from config matching CLI behavior.
Bug 1: RRF scores vs cosine similarity — min_score filter was applied
to normalized RRF scores (rank-based 0..1) in hybrid recall, not raw
cosine similarity. A threshold of 0.3 or 0.5 would incorrectly filter
out nearly all hybrid results even when vector matches were strong.
Fix: remove min_score filtering from recall_rrf() since RRF scores
are not comparable to cosine. Document that min_score only applies to
vector-only and fts5-only recall modes.

Bug 2: Server ignores [recall] config — strict mode used hard-coded
STRICT_THRESHOLD=0.5 instead of reading from uteke.toml [recall]
section. CLI and server behavior diverged.
Fix: add RecallFileSection to server config parsing, pass recall config
through ReqCtx, resolve thresholds from config matching CLI behavior.
@ajianaz
ajianaz force-pushed the feat/252-configurable-recall-threshold branch from 5126381 to 7e68624 Compare June 11, 2026 02:18
) -> Result<(), String> {
tracing::info!("Recalling: {query} (limit: {limit})");
// Resolve threshold: --min > --strict (→ config min_score_strict) > config min_score > 0.0
let min_score = match min {
@ajianaz
ajianaz merged commit 417dd85 into develop Jun 11, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the feat/252-configurable-recall-threshold branch June 11, 2026 02:36
ajianaz added a commit that referenced this pull request Aug 13, 2026
…275)

Lesson learned from PR #274: CodeCora failure was dismissed as external
but Cora Review (separate check) found 2 real critical bugs. Every red
CI check must be investigated before merge, not dismissed.

Also merging dependabot PRs:
- PR #255: actions/checkout v4→v6 (CI pass, local verified)
- PR #256: trivy-action 0.9.2→0.36.0 (CI pass, local verified)
ajianaz added a commit that referenced this pull request Aug 13, 2026
* feat(#252): add recall threshold config and core filtering

- Task 1: Add [recall] config section (min_score, min_score_strict)
- Task 2: Add min_score parameter to all recall methods
- Task 3: Add RecallConfig to Uteke struct

Partially implements #252 — CLI/Server callers need updating.

* fix(#252): pass min_score through FTS5 fallback, document RRF score caveat

* feat(#252): complete recall threshold — CLI flags, server API, tests

- Task 4: Add --min and --strict flags to recall command
- Task 5: Server API supports min_score/strict in /recall endpoint
- Task 6: 4 new integration tests (112 total pass)

Threshold resolution: --min > --strict (min_score_strict) > config min_score > 0.0
Empty results with threshold show diagnostic info (JSON + human).

Closes #252

* fix(#252): pass entity/category in server recall, extract strict threshold constant

* chore: clean up subagent artifacts

* fix(#252): address Cora review — remove index artifacts, add entity/category server filter

- Remove committed uteke_index.keys/usearch, add to .gitignore
- Add entity/category fields to server RecallRequest + post-filter in route
- Suppress dead_code warning for recall_config (stored for future use)
- cargo fmt --all

* fix(#252): over-fetch for metadata post-filter, truncate to requested limit

Address Cora review: entity/category filtering after recall could
miss results because the original limit was too small. Now over-fetches
3x when metadata filters are present, then truncates to requested limit.

* fix(#252): CI fixes — ignore model-dependent tests, fix clippy warnings

- Mark 4 recall threshold tests as #[ignore] (require ONNX model)
- Fix clippy unnecessary_map_or in server.rs
- Fix clippy unnecessary closure in uteke-server

* fix(#252): defer min_score filtering until after metadata post-filter

When entity/category filters are present, recall without min_score
to avoid discarding valid lower-ranked matches. Apply min_score
after metadata filtering, then truncate to requested limit.

Fixes CodeCora finding: over-fetch + pre-filter could miss valid
matches that satisfy metadata but rank below top-N.

* fix: resolve 2 Cora review findings in PR #274

Bug 1: RRF scores vs cosine similarity — min_score filter was applied
to normalized RRF scores (rank-based 0..1) in hybrid recall, not raw
cosine similarity. A threshold of 0.3 or 0.5 would incorrectly filter
out nearly all hybrid results even when vector matches were strong.
Fix: remove min_score filtering from recall_rrf() since RRF scores
are not comparable to cosine. Document that min_score only applies to
vector-only and fts5-only recall modes.

Bug 2: Server ignores [recall] config — strict mode used hard-coded
STRICT_THRESHOLD=0.5 instead of reading from uteke.toml [recall]
section. CLI and server behavior diverged.
Fix: add RecallFileSection to server config parsing, pass recall config
through ReqCtx, resolve thresholds from config matching CLI behavior.
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.

feat: configurable similarity threshold for recall ("I don't know" behavior)

2 participants