Skip to content

Add deep AI search to rerank all components in selected sources#2430

Open
Mbeaulne wants to merge 1 commit into
06-18-build_broader_ai_candidate_pools_for_component_searchfrom
06-18-improve_ai_rerank_payload_for_component_search
Open

Add deep AI search to rerank all components in selected sources#2430
Mbeaulne wants to merge 1 commit into
06-18-build_broader_ai_candidate_pools_for_component_searchfrom
06-18-improve_ai_rerank_payload_for_component_search

Conversation

@Mbeaulne

@Mbeaulne Mbeaulne commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds a Deep AI search button alongside the existing AI (smart) search button. While the standard AI search sends a limited, curated set of candidate components to the reranker, Deep AI search sends the entire searchable index — lexical hits first so truncating providers still see the most likely matches early — allowing the model to rerank across every available component in the selected sources.

Key changes:

  • Introduces buildDeepAiCandidateMatches, which builds a candidate pool from all indexed components (no cap), ordered with lexical matches first and remaining components appended alphabetically.
  • Exposes canDeepRerank and deepRerank from useComponentSearchV2State and wires them into both the Dashboard and Editor search UIs.
  • Enriches RerankCandidate with richer I/O metadata (type and description, not just names) and a source field, giving the model more signal when ranking.
  • Refactors the shared startAiSearch / startRerank helpers to accept an arbitrary candidate list, removing duplication between the standard and deep paths.
  • Updates componentReferenceToCandidate to accept an optional source argument and serialize I/O types (including complex object types) via JSON.stringify.

Related Issue and Pull requests

Type of Change

  • Bug fix
  • New feature
  • Improvement
  • Cleanup/Refactor
  • Breaking change
  • Documentation update

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Screenshots (if applicable)

Test Instructions

  1. Open the component search panel (Dashboard or Editor).
  2. Enter a non-empty query.
  3. Confirm the Deep AI search button appears and is enabled when an AI provider is configured.
  4. Click Deep AI search and verify that results are reranked across all components in the selected sources, not just the top lexical candidates.
  5. Confirm the existing AI search (sparkles) button still behaves as before.
  6. Verify the button is disabled when the query is empty or no AI provider is configured.

Additional Comments

scoreAllCandidates is intentionally set to false for deep rerank to avoid scoring overhead across the full index on every result row. The standard AI search retains scoreAllCandidates: true so relevance percentages continue to appear on displayed results.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

🎩 Preview

A preview build has been created at: 06-18-improve_ai_rerank_payload_for_component_search/817441b

@Mbeaulne Mbeaulne changed the title Improve AI rerank payload for component search Add deep AI search to rerank all components in selected sources Jun 18, 2026
@Mbeaulne Mbeaulne marked this pull request as ready for review June 18, 2026 17:59
@Mbeaulne Mbeaulne requested a review from a team as a code owner June 18, 2026 17:59
candidates,
seenDigests,
lexicalSearch(index, trimmedQuery, {
limit: index.length,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 This is an AI-generated code review comment.

[HIGH] Deep search builds an unbounded candidate pool: lexicalSearch(index, ..., { limit: index.length }) followed by appending every remaining entry with Number.MAX_SAFE_INTEGER, then JSON.stringify-ing each candidate into a billed LLM rerank prompt. Output is bounded (scoreAllCandidates: false → ≤20) but input is not — there is no cap, truncation, or confirmation. Cap the deep pool at a high-but-finite N (and/or surface a confirmation when the pool is very large). At minimum, make Number.MAX_SAFE_INTEGER a deliberate, documented bound rather than effectively unlimited.

const candidates: LexicalMatch[] = [];
const seenDigests = new Set<string>();
const allLexicalMatches = lexicalSearch(filteredIndex, query, {
limit: filteredIndex.length,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 This is an AI-generated code review comment.

[HIGH] Same unbounded-deep-pool concern on the Dashboard surface: lexicalSearch(filteredIndex, ..., { limit: filteredIndex.length }) then every remaining sortedIndex entry is appended, and the whole pool is JSON.stringify-ed into a billed LLM rerank with no input cap or confirmation. Bound the deep pool to a finite N or confirm before sending a very large pool; document the worst-case prompt size.

</Button>
<Button
variant="outline"
onClick={handleDeepAiSearch}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 This is an AI-generated code review comment.

[MEDIUM] This "Deep AI search" Button gives no busy/in-progress feedback while isReranking, unlike the sibling Sparkles button which sets a dynamic aria-label. Add e.g. aria-label={isReranking ? "Deep AI search in progress" : "Deep AI search"} (and consider a busy indicator) so the disabled-while-reranking state is announced to assistive tech.

};

const handleSmartSearch = () => {
const startAiSearch = (matches: LexicalMatch[]) => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 This is an AI-generated code review comment.

[LOW] startAiSearch passes no scoreAllCandidates for either smart or deep, so both default to false here, whereas the Editor uses true for smart / false for deep. Routing the new deep button through this shared helper cements a smart/deep behavior divergence between the two surfaces. Consider passing a flag (as the Editor’s startRerank does) for parity.

const trimmedQuery = query.trim();
const lexicalMatches = buildLexicalMatches(index, trimmedQuery);
const aiCandidateMatches = buildAiCandidateMatches(index, trimmedQuery);
const deepAiCandidateMatches = buildDeepAiCandidateMatches(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 This is an AI-generated code review comment.

[LOW] buildDeepAiCandidateMatches (full-index lexicalSearch + full [...index].sort()) runs every render though it is only needed at click time. React Compiler memoizes this, so it is not a correctness bug. Optionally, compute only .length/enabled-state during render and build the ordered pool lazily inside the deep handler.

@Mbeaulne

Copy link
Copy Markdown
Collaborator Author

🤖 This is an AI-generated code review comment.

[MEDIUM] src/hooks/useNaturalLanguageComponentSearch.ts ~lines 38-50 — The rerank mutation passes no AbortSignal, so a now-much-heavier deep rerank cannot be cancelled if the user retypes. Pre-existing, but materially amplified by this feature. Follow-up: thread signal into the mutation so a new query aborts the in-flight deep call.

(Posted as a PR-level comment because this file has no changed lines in the diff to anchor an inline comment to.)

@Mbeaulne Mbeaulne force-pushed the 06-18-improve_ai_rerank_payload_for_component_search branch from 7d30372 to c443c7a Compare June 18, 2026 19:12
@Mbeaulne Mbeaulne force-pushed the 06-18-build_broader_ai_candidate_pools_for_component_search branch from d363ca7 to 60b076d Compare June 18, 2026 19:12
@Mbeaulne Mbeaulne force-pushed the 06-18-improve_ai_rerank_payload_for_component_search branch from c443c7a to 9fdd3d5 Compare June 18, 2026 20:28
@Mbeaulne Mbeaulne force-pushed the 06-18-build_broader_ai_candidate_pools_for_component_search branch from 60b076d to 455266e Compare June 18, 2026 20:28
@Mbeaulne Mbeaulne force-pushed the 06-18-improve_ai_rerank_payload_for_component_search branch from 9fdd3d5 to d9e254e Compare June 18, 2026 20:49
@Mbeaulne Mbeaulne force-pushed the 06-18-build_broader_ai_candidate_pools_for_component_search branch 2 times, most recently from 4a246ee to 8cc6222 Compare June 18, 2026 21:02
@Mbeaulne Mbeaulne force-pushed the 06-18-improve_ai_rerank_payload_for_component_search branch from d9e254e to 1351eea Compare June 18, 2026 21:02
@Mbeaulne Mbeaulne force-pushed the 06-18-build_broader_ai_candidate_pools_for_component_search branch from 8cc6222 to 88f3546 Compare June 18, 2026 21:16
@Mbeaulne Mbeaulne force-pushed the 06-18-improve_ai_rerank_payload_for_component_search branch from 1351eea to 817441b Compare June 18, 2026 21:16
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