Skip to content

fix(#894): room recall_semantic returns zero for small rooms in large DBs - #897

Merged
ajianaz merged 1 commit into
developfrom
fix/894-room-recall-small-rooms
Aug 5, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/894-room-recall-small-rooms

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

What

Fix recall_room_semantic returning zero results for small rooms in large databases.

Why

The fixed fetch cap of 200 (#546) caused 93% of rooms to return zero results from semantic recall. Small rooms (≤20 memories) in a 2,486-memory database almost never appear in the global top-200 hybrid search results, so the room ID post-filter eliminated everything.

Changes

File Change
rooms.rs:92-108 fetch_limit = total_memories (was effective_limit.min(200))
crud.rs:93-100 New count_all_memories() method for dynamic fetch sizing
rooms.rs:312-388 Regression tests

Verification

Tested on production clone (2,284 memories, 74 rooms):

Room Memories Before After
cora-code 20 0 results 5 results
codecora-marketing 14 0 results 5 results
server-infra 8 0 results 3 results
uteke-dev 5 0 results 1 result

Testing

  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test --workspace — 447 passed, 0 failed, 26 ignored
  • Production clone verification — all 4 previously-broken rooms now return results

Closes #894

… DBs

The fixed fetch cap of 200 (#546) caused semantic room recall to return
zero results for 93% of rooms. Small rooms (≤20 memories) in large DBs
(2,486+ memories) almost never appear in the global top-200 hybrid
search results, making the room ID post-filter eliminate everything.

Fix: set fetch_limit to total_memories so the hybrid search covers the
entire database before filtering to room IDs. HNSW vector search is
O(log N), so fetching 2K+ results adds negligible latency.

Changes:
- rooms.rs: fetch_limit = total_memories (was effective_limit.min(200))
- crud.rs: add count_all_memories() for dynamic fetch sizing
- rooms.rs: regression test for small room in large DB

Verified on production clone (2,486 memories, 74 rooms):
  cora-code (20 mem):  0 → 5 results ✅
  codecora-marketing:  0 → 5 results ✅
  server-infra:        0 → 3 results ✅
  uteke-dev:           0 → 1 results  ✅
//
// Fetch ALL memories so post-filter to room IDs has complete coverage.
// HNSW vector search is O(log N), so fetching 2K+ results is still fast.
// The old fixed cap of 200 (#546) caused small rooms to return zero (#894).
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • crates/uteke-core/src/rooms.rs:96 — The old code capped fetch_limit at 200 (issue BUG: room recall --query (semantic search within room) returns empty results #546: "prevent unbounded searches for large rooms"). The new code sets fetch_limit = total_memories, removing all bounds. For a database with 50K+ memories, every call to recall_room_semantic will fetch, deserialize, and hybrid-score the entire memory store — even when the caller only wants a few results. The comment claims "HNSW vector search is O(log N)" but that only covers the ANN lookup; the downstream retrieval, row deserialization, keyword search, and score merging all scale with fetch_limit. A caller requesting limit=5 will still trigger a full-table fetch. Consider scaling fetch_limit relative to the caller's limit (e.g., total_memories.min(limit * factor)) or using a higher but still bounded cap.

Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 7b935e4 into develop Aug 5, 2026
12 of 13 checks passed
ajianaz added a commit that referenced this pull request Aug 5, 2026
)

Replace unbounded fetch_limit=total_memories with two-stage algorithm:

Stage 1 (Primary): Hybrid search with adaptive bounded limit:
  fetch_limit = max(room_size * 10, effective_limit * 5)
                  .min(total_memories)
                  .min(MAX_ROOM_FETCH=5000)

Stage 2 (Fallback): If primary missed room memories (small room in
large DB — the original #894 bug), load missing IDs directly and score
them with cosine similarity against query embedding.

This guarantees complete room coverage without unbounded global fetch.
For a 50K+ DB with a 20-memory room, fetch_limit is capped at 5000
instead of scanning all 50K memories.

Addresses reviewer concern about PR #897 unbounded fetch_limit.

Tested: 4 rooms in production clone (2,486 memories) all return correct
results. cargo test 453 passed, clippy clean.

Co-authored-by: ajianaz <[email protected]>
ajianaz added a commit that referenced this pull request Aug 13, 2026
… DBs (#897)

The fixed fetch cap of 200 (#546) caused semantic room recall to return
zero results for 93% of rooms. Small rooms (≤20 memories) in large DBs
(2,486+ memories) almost never appear in the global top-200 hybrid
search results, making the room ID post-filter eliminate everything.

Fix: set fetch_limit to total_memories so the hybrid search covers the
entire database before filtering to room IDs. HNSW vector search is
O(log N), so fetching 2K+ results adds negligible latency.

Changes:
- rooms.rs: fetch_limit = total_memories (was effective_limit.min(200))
- crud.rs: add count_all_memories() for dynamic fetch sizing
- rooms.rs: regression test for small room in large DB

Verified on production clone (2,486 memories, 74 rooms):
  cora-code (20 mem):  0 → 5 results ✅
  codecora-marketing:  0 → 5 results ✅
  server-infra:        0 → 3 results ✅
  uteke-dev:           0 → 1 results  ✅

Co-authored-by: ajianaz <[email protected]>
ajianaz added a commit that referenced this pull request Aug 13, 2026
)

Replace unbounded fetch_limit=total_memories with two-stage algorithm:

Stage 1 (Primary): Hybrid search with adaptive bounded limit:
  fetch_limit = max(room_size * 10, effective_limit * 5)
                  .min(total_memories)
                  .min(MAX_ROOM_FETCH=5000)

Stage 2 (Fallback): If primary missed room memories (small room in
large DB — the original #894 bug), load missing IDs directly and score
them with cosine similarity against query embedding.

This guarantees complete room coverage without unbounded global fetch.
For a 50K+ DB with a 20-memory room, fetch_limit is capped at 5000
instead of scanning all 50K memories.

Addresses reviewer concern about PR #897 unbounded fetch_limit.

Tested: 4 rooms in production clone (2,486 memories) all return correct
results. cargo test 453 passed, clippy clean.

Co-authored-by: ajianaz <[email protected]>
@ajianaz
ajianaz deleted the fix/894-room-recall-small-rooms branch August 13, 2026 01:52
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: room recall_semantic top-200 cap kills small rooms in large DBs

2 participants