Skip to content

Cache BM25 search index and entity map build - #647

Open
d-oit wants to merge 1 commit into
mainfrom
perf/search-retrieval-cache-17414998455414137689
Open

Cache BM25 search index and entity map build#647
d-oit wants to merge 1 commit into
mainfrom
perf/search-retrieval-cache-17414998455414137689

Conversation

@d-oit

@d-oit d-oit commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Implemented reference-based caching in the BM25 search retrieval engine (src/lib/search/retrieval.ts). This avoids costly re-tokenization and index rebuilding for consecutive queries (e.g. character-by-character search input typing) when the underlying entities and claims arrays have not changed referentially. The optimization yields an ~84% reduction in average query execution time on large datasets. All tests and quality gates pass.


PR created automatically by Jules for task 17414998455414137689 started by @d-oit

Introduces reference-based caching of computed index entries and the entity map in the BM25 retrieval search engine. This avoids rebuilding indices and re-tokenizing on every keystroke query when underlying entities/claims lists remain unchanged. Average benchmark search execution time on large datasets was reduced from 16.43ms to 2.60ms (~84% reduction).

Co-authored-by: d-oit <6849456+d-oit@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
do-knowledge-studio Ready Ready Preview, v0 Aug 12, 2026 1:14am

@deepsource-io

deepsource-io Bot commented Aug 12, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in b3604d7...f8bd025 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Aug 12, 2026 1:14a.m. Review ↗
Python Aug 12, 2026 1:14a.m. Review ↗
Shell Aug 12, 2026 1:14a.m. Review ↗
SQL Aug 12, 2026 1:14a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

let cachedAvgDl = 0

/** Run a BM25 full-text search over entities and claims. */
export const search = (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`search` has a cyclomatic complexity of 7 with "medium" risk


A function with high cyclomatic complexity can be hard to understand and
maintain. Cyclomatic complexity is a software metric that measures the number of
independent paths through a function. A higher cyclomatic complexity indicates
that the function has more decision points and is more complex.

@owl-watch owl-watch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🦉 OwlWatch reviewed this change — 1 new finding(s).

Additional findings:

  • [MEDIUM · tracker] Division by zero when avgDl is zero in bm25Score (src/lib/search/retrieval.ts:117)

@codacy-production

Copy link
Copy Markdown
Contributor

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity

Metric Results
Complexity 4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant