Skip to content

fix(search): rank matching sections and expand grouped results - #288

Open
cjfit wants to merge 6 commits into
mainfrom
vigilante/search-section-matches
Open

cjfit wants to merge 6 commits into
mainfrom
vigilante/search-section-matches

Conversation

@cjfit

@cjfit cjfit commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Merge order

No dependencies. Rebased onto main at 9525cd4.

Summary

Search preserves distinct matching sections while keeping long pages from filling the initial results. Each page initially shows two matches; an expansion control reveals the rest without closing the dialog. Matching page titles and sections rank ahead of loosely related results.

On the saved 36-query benchmark, corrected top-five coverage improves from 21/36 to 30/36, matching the recorded Algolia result. Fifteen queries improve their expected-page rank; none regress.

Fix

Fuse keyword and semantic evidence by section URL, retain the strongest keyword representative and its highlights, and rank each page by its strongest section. Retrieve both the strongest semantic sections and the best section from each leading page. Require informative keyword terms and weight embeddings by corpus page frequency. Prefer exact page titles, then titles containing all query words, before exact headings and snippets; literal queries let fused rankings order keyword pages.

QA

Browser verification in Chrome and Firefox remains pending; automated dialog coverage uses jsdom. Use a docs preview built with DOCS_SEMANTIC_SEARCH=1 for these steps.

  1. Open the preview home page, open search, and enter STUN. Check that the “STUN and NAT” page leads incidental snippets mentioning STUN. Repeat with code-server and check that its workspace-access guide leads.
  2. Search for port forwarding. Find a page with a “Show … more matches” control. Select it with the keyboard and confirm the dialog stays open and exposes the remaining matching sections.
  3. Select a section match and confirm navigation reaches that heading. Reopen search, expand a group, and change the query to Claude Code; confirm groups collapse again and the matching client guide is easy to find.

Pages to compare

The URLs below are the automatic branch router preview, which serves published docs and does not yet exercise this branch's rebuilt search bundle. A docs preview with semantic search enabled is still required for browser QA. Branch aliases serve the latest deployment and require a Vercel login.

What to check Production Preview
Search ranking and expansion https://coder.com/beta-docs/ https://coder-docs-router-git-vigilante-search-section-matches.coderite.app/beta-docs/
STUN result and section navigation https://coder.com/beta-docs/admin/networking/stun/ https://coder-docs-router-git-vigilante-search-section-matches.coderite.app/beta-docs/admin/networking/stun/
File Browser result https://coder.com/beta-docs/user-guides/workspace-access/filebrowser/ https://coder-docs-router-git-vigilante-search-section-matches.coderite.app/beta-docs/user-guides/workspace-access/filebrowser/

Testing

  • Package builds, docs-next typecheck, and all 371 docs-next tests pass after rebasing. Changed TypeScript passes lint and formatting. The two new ranking regressions fail against the previous implementation and pass with the fix.
  • The real-corpus hybrid static build passes: 476 pages and 4,219 semantic sections. Local validation ran on Node 26.11.1.
  • Benchmark measurements use the saved October 28 corpus: 463 pages and 4,012 sections. Our metric counts rendered selectable rows, including page headers and expansion controls; Algolia counts hits. Two moved expected URLs are corrected below. The newly rebuilt corpus has not been rebenchmarked.
Corrected metric Before branch This branch Recorded Algolia
Top 1 17/36 23/36 23/36
Top 5 21/36 30/36 30/36
Top 10 27/36 32/36 30/36
Top 20 28/36 34/36 30/36

Largest gains include workspace files (52 → 5), local browser app (46 → 2), login expires (27 → 1), MCP tools (12 → 1), and STUN (9 → 1). Without URL corrections, top-five coverage improves from 20/36 to 29/36, also matching recorded Algolia. The final refinement improves a separate 20-query set from 9/20 to 10/20 at five rows without worsening any expected-page ranks. Remaining gaps include encrypted database, inject user credentials, deploy offline, choose instance size, shell customization, and keep disk.

Upstream

No. This is the engine's custom hybrid retrieval and grouped-results behavior, composed through existing Fumadocs extension points.

Linear: no issue linked.


🤖 Built with AI assistance.

@vercel

vercel Bot commented Oct 29, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
coder-docs Ready Ready Preview Oct 29, 2026 8:09pm UTC
coder-docs-router Ready Ready Preview Oct 29, 2026 8:09pm UTC

Request Review

@cjfit
cjfit marked this pull request as ready for review October 29, 2026 20:16
@cjfit
cjfit requested a review from nickvigilante as a code owner October 29, 2026 20:16
@cjfit
cjfit marked this pull request as draft November 13, 2026 17:41

@nickvigilante nickvigilante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I read the full diff (semantic-search.ts, hybrid-search.tsx, semantic-index.mjs, the tests and the ARCHITECTURE.md changes). I did not build the branch or run the tests, so everything below comes from reading the code and the PR body.

The approach is sound. Fusing by section URL instead of page, ranking a page by its strongest section, and weighting embeddings by page frequency each address a real failure in the old fuse. The new tests are the right shape: they cover the anchor-level fusion, the exact-title tiers, the once-per-page weighting and the dialog's multi-match rendering. The ## Upstream answer is reasonable.

Blocking

  1. The branch conflicts with main. GitHub shows it as conflicting and the PR says it was rebased onto 9525cd4, which is weeks old. The benchmark numbers (463 pages, 4,012 sections, saved October 28 corpus) also predate that rebase and the current corpus. Please rebase and rebenchmark on the rebuilt corpus, since the PR itself says that has not been done.

  2. The QA section no longer matches how this repo previews. The "Pages to compare" table uses coder.com/beta-docs/... and the router branch alias. Production is now https://coder.com/docs/<path>/, and the PR itself says the router preview does not exercise the rebuilt search bundle. Docs-site changes are previewed through engine-pr-preview.yml, which comments a URL once a docs-preview reviewer approves the deploy. The steps also need a build with DOCS_SEMANTIC_SEARCH=1, so please say how a reviewer gets that preview. The Chrome and Firefox pass is still marked pending, and AGENTS.md says the PR gets merged after it is checked in a browser, so it needs to happen before merge.

Worth fixing or answering

  1. Keyword recall when the semantic index is not available. keywordSearchClient sets threshold: 0, which in Orama means every remaining query word must match. hybridSearchClient still returns the keyword-only result before the semantic index has loaded, and permanently if that download fails (the 30 second timeout path). In that window a natural-language query such as how do I expire my login can return no results, where the old default matched any term. With vectors loaded the fuse masks this, but the PR only measures that case. Either keep the default threshold for the keyword-only path and apply the all-terms requirement only when fusing, or add a test that pins the no-vector behaviour and say in the PR that the narrower result is intended.

  2. expanding ref in HybridSearchDialog. The dialog only stays open after "Show N more matches" because onOpenChange swallows exactly one call after the action sets the ref. If Fumadocs ever calls onOpenChange zero times after an action's onSelect, the ref stays true and the next real close, such as Escape, is ignored once. If it calls it twice, the dialog closes anyway. The dialog test covers the expansion, but nothing covers Escape after an expansion. A test for that would pin the assumption, or the ref could be cleared on a timer or effect.

  3. Evaluation confidence. The ranking tiers, the 0.75 and 0.25 weights and the stop-word list were tuned against the 36-query set, and the separate 20-query check moved only from 9/20 to 10/20. The top-five parity with Algolia is encouraging, but I would describe the result as "no regressions found" rather than a general improvement, and I'd add more queries before the next round of tuning. It would also help to say how the two expected URLs were corrected, since the corrected metric is the headline number.

Nits, not blocking

  • createCorpusEmbeddingModel re-quantizes an already int8 table with one global scale. Rows for corpus-wide tokens, whose weight is near log 2 against a maximum near log N, keep only a few bits. The benchmark already includes that cost, but it is worth a line in ARCHITECTURE.md.
  • QUERY_STOP_WORDS is English only and compares the raw whitespace-separated word, so how? is not removed. That is probably fine for these docs, but say so.

I'm not approving, so this review can't count toward merging.


🤖 Built with AI assistance.

@cjfit
cjfit force-pushed the vigilante/search-section-matches branch from 4687c2a to 63844a7 Compare November 24, 2026 18:25
@nickvigilante
nickvigilante marked this pull request as ready for review November 24, 2026 18:28
@nickvigilante
nickvigilante requested a review from a team as a code owner November 24, 2026 18:28
@cjfit
cjfit deployed to docs-preview November 24, 2026 18:30 — with GitHub Actions Active
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Docs preview deployment

Rendered with docs-engine f002c04 from coder/coder at b911ed9782c807d521a21f6990697723b3562351: https://coder-docs-2sx6paiey.coderite.app

The preview is behind Vercel authentication; sign in with your Coder Vercel account.

@nickvigilante nickvigilante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Cedric, thanks for this. I read the diff at 63844a7 first and formed a view from the code, then checked it against the preview notes from a manual pass in Chrome. Nobody has run the branch in a browser for this review, so anything about live behaviour below is read from the code and marked as inferred. packages/docs-next/src/semantic-search.test.ts passes on its own (22 of 22), and the workflow change is one added env: line that touches no trigger, environment, secret or permission.

The section-level model is a good shape: fusing by section URL, keeping a page's position equal to its best section, and fetching both the strongest sections and the best section per leading page all do what ARCHITECTURE.md says, and the ranking is deterministic. I would not merge it until the three P1s below are dealt with.

Why STUN and "login expires" come out that way

STUN is a tuning limit. exactResultMatch in packages/docs-next/src/semantic-search.ts gives tier 3 to any page whose title contains every query word, so for the one-word query STUN, "Self-host a STUN server" and "STUN and NAT" are both tier 3 and the fused score decides the order. I reproduced it with fuseResults on synthetic inputs: whichever page the vectors prefer leads. No test puts two tier-3 titles in play, and the QA step that promises "STUN and NAT leads" is not guaranteed by the code. A cheap tie-break inside tier 3, such as the fraction of title words that are query words, plus a test with both titles present, would fix it.

"Login expires" is a defect, and it predates this PR. After the tiers, fuseResults pins the page of the top vector section first and the first keyword page second, whatever their fused scores. In my reproduction a page that appears in both lists scores about 0.0162 and loses to a vector-only page at about 0.0123, which matches the order the preview shows. ARCHITECTURE.md now says "the fused section ranks determine the remaining page order", which is only true after those two pins. I reproduced this on synthetic inputs and could not confirm it against the preview's real corpus.

P1

The vector pin defeats the fusion for non-literal queries. semantic-search.ts around lines 1080-1089, where order is built from exactPages, firstVector, firstKeyword and groups.keys(). login expires puts a CLI reference page first because it holds the top vector section, ahead of the page both sources agree on. I would pin only when no source agrees, or drop the vector pin and keep firstKeyword only for a keyword hit the vectors did not return, and add a test with an agreeing and a disagreeing page.

threshold: 0 makes the keyword-only path return nothing for many natural-language queries. packages/docs-next/src/hybrid-search.tsx lines 407-415. The old call used the library default, which in this Orama fork is threshold 1 (any term). With 0, every term has to appear in a single record, and a record is one page title, one heading or one paragraph. The stop-word list is short, so what is a workspace, why does my build fail and tokens that expire still need what, why or that in the same paragraph. The semantic path masks this once the index has loaded, but hybridSearchClient returns the raw keyword results whenever the index is empty, which is the case while the download is in flight, after a failure, and after the 30 second timeout. After a failure the cached promise is deleted, so every later keystroke starts a new download. In that state those queries show "No results found" where they used to show partial matches. This is the keyword-only regression I was worried about, it is inferred from the code and not run, and no test calls the client with the index missing and a multi-word query. I would use threshold: 0 only when the semantic index is ready, or fall back to the default threshold when the strict search returns nothing.

Textual and semantic conflict with #407. #407 (product-scoped search) changes hybridSearchClient(from, product?, keyword = staticClient({ from, tag: product })) and vectorSearch(query, index, product?), and deletes ProductLabelsContext. This PR rewrites the same signature to default to keywordSearchClient(from), rewrites the body of vectorSearch that #407 edits, and keeps ProductLabelsContext. The merge will conflict, and a careless resolution loses scoping silently: keywordSearchClient(from) takes no tag, so the keyword side would stop filtering by product while the vector side still does, and a code-server reader would get Coder keyword hits. Whichever PR lands second needs keywordSearchClient(from, tag), the product filter applied before candidates are pushed in the new vectorSearch, and a test that searches under a product and asserts no foreign-product row appears.

P2

The expand control has no context for assistive technology and resets the active row. hybrid-search.tsx lines 455-471. The action row is a listbox option whose only text is Show 3 more matches, repeated for every group, so a screen-reader user cannot tell which page it expands, and nothing announces the change. When expanded changes, items changes identity and SearchDialogList in fumadocs-ui 16.19.0 runs setActive(items[0].id) in a layout effect (dialog/search.js around line 224), so after Enter on the expander the active descendant jumps back to the first result. This is inferred from the library source, and a keyboard pass that only watches the dialog stay open would not show it. I would name the page in the label (for example Show 3 more matches in Port forwarding), keep the active id on the first newly revealed row, and add a polite live region. This is the accessible-name rule in AGENTS.md.

The expanding ref guards the close handler with a flag instead of the event. hybrid-search.tsx lines 438 and 482-486. It works today because fumadocs calls onOpenChange(false) synchronously after item.onSelect(), and Escape goes through the same wrapper with the flag false, which matches the Escape result in the manual pass. If the library ever skips the close call for an action, the flag stays true and the next real Escape or overlay click is swallowed once. Handing the dialog its own onSelect that does not call onOpenChange, or resetting the flag in a microtask, would be sturdier. Related: #340 passes onSelect={sendSearchGoal}, and the library calls onSelectProp(item) after an action too, so each "Show more" click would send a search goal unless that handler filters item.type === "action". That is worth deciding before both land.

The exact tier overrides the fusion for any common single word. semantic-search.ts lines 953-955 and the sort at line 1053 (b.exact - a.exact || b.score - a.score). Any page whose title contains the query word is tier 3 and beats every non-title result regardless of score, so for workspace, template or agents every page with the word in its title outranks every section result. Matching is also exact-token: the title is split on non-word characters but the query only on whitespace, so self host will not match self-host, workspaces will not match workspace, and STUN? will not match stun. These are tuning limits and not crashes, and ARCHITECTURE.md does not say that tier 3 is flat or that the keyword-only path is now strict.

Not verified

I did not open a browser, so the keyboard flow, focus, announcements and section landing are from the manual pass and the fumadocs source. I did not run the slow-network or timeout path, so the threshold: 0 finding is from reading hybridSearchClient, preloadSemanticIndex and the Orama threshold rule. I did not run hybrid-search.test.tsx, because a failing jsdom assertion can exhaust memory in this environment. The 36-query benchmark and its expected URLs were not available, so the 17/23, 21/30, 27/32 and 28/34 figures are taken from the PR text. I did not measure layout shift or run axe.


🤖 Built with AI assistance.

cjfit and others added 5 commits November 30, 2026 10:52
Preserve distinct section matches while keeping long pages from crowding the initial results. Prioritize exact matches, require informative keyword terms, and weight semantic tokens by page frequency to improve retrieval.

Cover section ranking, group expansion, and build/browser embedding consistency with regression tests.

Assisted-by: AI
Promote page titles containing every query word ahead of exact section matches. Let fused rankings order keyword pages for literal queries so keyword-only hits do not displace results supported by both sources.

Improve corrected top-five coverage from 28/36 to 30/36 on the saved corpus without regressing labeled queries. Add regression tests and document the ranking order.

Assisted-by: AI
Fumadocs 16.17 highlights matches with the CSS Custom Highlight API and no longer wraps them in <mark>, so exact-match comparison has nothing to strip. Update the ranking tests to the plain record content the index now returns.

Assisted-by: AI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
publish-version.yml passes DOCS_SEMANTIC_SEARCH from the repository variable, but the preview build did not, so previews only exercised keyword search.

Assisted-by: AI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since #407 the keyword side searches only the active product's tag, so the
fixture needs one for its keyword hits to count.

Assisted-by: AI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Without the semantic index, a query that matches no record with every
  word falls back to matching any word, so natural-language questions
  aren't empty while vectors load or after they fail. Fused rankings are
  unchanged.
- The expansion row names its page, moves the active row to the first
  revealed match and announces it. The flag that keeps the dialog open
  resets in a microtask, so it can't swallow a later close.
- ARCHITECTURE.md now says the pins precede the fused order, that titles
  with every query word form one tier, and how word matching works.

Assisted-by: AI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cjfit

cjfit commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, Nick. Addressed in 9103c7f. I measured every change against today's corpus (145 queries: our 117-query set plus your examples) before keeping it, and dropped anything that moved a ranking.

P1 threshold: 0: fixed. Before the semantic index loads (or if it fails), an empty all-words result now falls back to any-word matching. Keyword-only "No results" dropped from 37 to 6 of 145, and fused rankings are unchanged. Tested in hybrid-search.test.tsx.

P1 #407 conflict: handled in the rebase. keywordSearchClient(from, tag) and vectorSearch(query, index, product) both scope to the product, and #407's test covers no rows from the other product, with and without vectors.

P1 vector pin: pushing back on this one. On the real corpus, login expires returns nothing from the all-words keyword search, so its order comes entirely from the vectors, not the pin. I tried pinning only when the sources share no page, and pinning unless they agree elsewhere. Both moved the right page down for workspace, what is a workspace and --wildcard-access-url. I've corrected ARCHITECTURE.md to say the pins come first and fused ranking orders the pages after them.

P2 expand control: fixed. The row reads "Show 3 more matches in ", the active row moves to the first revealed match, and a polite live region announces it.

P2 expanding flag: fixed. It resets in a microtask, and the dialog test now checks that selecting a result after an expansion still closes the dialog. The onSelect filtering for "Show more" belongs in #340.

P2 title tier: pushing back. I tried breaking ties by how much of the title the query covers, plus splitting on hyphens. It fixed STUN but moved "Access your workspace" from #1 to #3 for workspace and reordered Claude Code and template. I'd rather not trade one regression for another. I've documented that this tier is flat and how word matching works (no hyphen splitting or plurals) in ARCHITECTURE.md. A STUN-specific fix can follow once we have the labeled benchmark back to tune against.

🤖 Generated with Claude Code

@cjfit
cjfit deployed to docs-preview November 30, 2026 23:44 — with GitHub Actions Active
@nickvigilante

Copy link
Copy Markdown
Collaborator

Hi Cedric, thanks for the quick turnaround. I ran the preview on 9103c7f in Chrome, and the expand control checks all pass: the row names its page, the active row moves to the first revealed match without the list jumping, the live region announces it, Escape closes, and selecting a revealed match closes the dialog. The top results for the queries we had a baseline for are unchanged.

Two things I'd like your view on before this merges.

  1. REST API endpoint pages now lead for generic words. On the preview, "template" returns five endpoint pages ("Get template version by template ID and name", "List template builder base templates", and so on), and "workspace" starts with "Get workspace metadata by ID" and "Update workspace metadata by ID". I think this comes from the title tier (any title containing every query word) meeting the per-operation API pages that landed in feat(api-reference): render the REST API reference with fumadocs-openapi #273, which put hundreds of titles containing "workspace" or "template" into that tier. Your 145-query numbers may predate that index change, so it might not show up in them. Could you re-run those two queries against a build that includes the API reference? One fix to consider is keeping /reference/api/ pages out of the title tier, or ranking them below guides.
  2. The live-region text survives closing the dialog. After Escape or navigating, reopening shows the old "Showing 10 more matches in …" text until the query changes. It looks like the revealed state is only cleared on a query change. Clearing it when the dialog closes would fix it, and it is minor.

The part I could not check in a browser is the keyword-only fallback (blocking the semantic files and searching a question). I'll try that myself. Everything else I'd approve as it is.


🤖 Built with AI assistance.

This branch was successfully deployed

1 active deployment
docs-preview — 9103c7f2 Deployed Nov 30, 2026 by cjfit via preview / deploy preview #149
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.

2 participants