Skip to content

perf(conversations): rank cross-thread hits before materializing#64

Merged
senamakel merged 1 commit into
tinyhumansai:mainfrom
senamakel:drift/d1-rank-before-clone-cross-thread
Jul 10, 2026
Merged

perf(conversations): rank cross-thread hits before materializing#64
senamakel merged 1 commit into
tinyhumansai:mainfrom
senamakel:drift/d1-rank-before-clone-cross-thread

Conversation

@senamakel

Copy link
Copy Markdown
Member

Module

memory::conversations::inverted_index

What

Ports OpenHuman host commit 007a99b62 — drift-ledger row D1 of the TinyCortex memory migration. The cross-thread inverted-index search cloned the KB-sized CrossThreadHit (content, message_id, created_at) for every Phase-2 match, then sorted by score and truncated to limit. Phase 2 can leave thousands of candidates while callers ask for 3–10 results, so ~99% of those clones were immediately discarded.

Now ranks on cheap borrowed keys first — (doc_id, matched: usize, created_at: &str) — truncates to limit, and materializes the heavy CrossThreadHit only for the survivors.

Behavior parity

Ranking by matched (usize) is order-equivalent to ranking by score = matched / total_terms because total_terms is a positive constant, so the returned order (score desc, then created_at desc tiebreak) is unchanged. Scores in the returned hits are still matched / total_terms.

Tests

cargo test --lib conversations::inverted_index — 16 pass, incl. new ranks_by_score_then_recency_before_truncating (more matches than limit; asserts the top-(score, recency) hits survive truncation, pinning that ranking happens before the cut).

Gates host workstream W7 (long-tail cutover — conversations).

https://claude.ai/code/session_01X39btnEnHSTuPSYYvgyjrb

Port OpenHuman host commit 007a99b62 (drift ledger D1). The cross-thread
inverted-index search cloned the KB-sized `CrossThreadHit` (content,
message_id, created_at) for *every* Phase-2 match, then sorted and
truncated to `limit`. Phase 2 can leave thousands of candidates while
callers ask for 3-10 results, so ~99% of those clones were discarded.

Now rank on cheap borrowed keys first — `(doc_id, matched: usize,
created_at: &str)` — truncate to `limit`, and materialize the heavy
`CrossThreadHit` only for the survivors. Ranking by `matched` (usize) is
order-equivalent to ranking by `score = matched / total_terms` since
`total_terms` is a positive constant, so returned order is unchanged.
Pinned by the new `ranks_by_score_then_recency_before_truncating` test.
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a66b0481-65ae-49b8-9985-0e26d63bd7f4

📥 Commits

Reviewing files that changed from the base of the PR and between 33dda94 and ec95ead.

📒 Files selected for processing (2)
  • src/memory/conversations/inverted_index.rs
  • src/memory/conversations/inverted_index_tests.rs

Comment @coderabbitai help to get the list of available commands.

@senamakel
senamakel merged commit a8e10f7 into tinyhumansai:main Jul 10, 2026
1 of 2 checks passed
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.

1 participant