-
Notifications
You must be signed in to change notification settings - Fork 6
ENG-1734 Add Roam semantic search to Advanced Node Search #1186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
trangdoan982
wants to merge
11
commits into
main
Choose a base branch
from
eng-1734-add-semantic-search-for-sync-enabled-graphs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e289dd9
ENG-1734 Add Roam semantic search to Advanced Node Search
trangdoan982 9c80e1e
ENG-1734 Remove discourseNodeSemanticSearch unit tests from PR scope.
trangdoan982 894901f
ENG-1734 Fix docked search snapshot with async semantic search.
trangdoan982 3b97b9b
ENG-1734 Simplify dock handling and fix sort reactivity.
trangdoan982 aebb862
Revert AGENTS.md changes from ENG-1734 branch.
trangdoan982 1bf4f21
ENG-1734 Unify semantic and keyword search on ScoredSearchHit.
trangdoan982 dccf234
ENG-1734 Rename discourse node search modules and APIs for clarity.
trangdoan982 053d5da
ENG-1734 Clarify unsorted vs sorted search result state in hook.
trangdoan982 2339198
ENG-1734 Add temporary debug logs for semantic vs miniSearch results.
trangdoan982 3286231
Merge branch 'main' into eng-1734-add-semantic-search-for-sync-enable…
trangdoan982 7acc534
ENG-1734 Remove debug logs and address review feedback.
trangdoan982 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import type { DiscourseNode } from "~/utils/getDiscourseNodes"; | ||
| import { | ||
| runRoamSemanticSearch, | ||
| type AdminSearchResultItem, | ||
| } from "~/utils/discourseNodeSearchProviders"; | ||
|
|
||
| export const SEMANTIC_SEARCH_MIN_DISCOURSE_RESULTS = 5; | ||
|
|
||
| export type DiscourseSearchHitSource = "semantic" | "keyword"; | ||
|
|
||
| export type DiscourseSearchHit = { | ||
| uid: string; | ||
| text: string; | ||
| type?: string; | ||
| nodeTypeLabel?: string; | ||
| score: number; | ||
| source: DiscourseSearchHitSource; | ||
| }; | ||
|
|
||
| export const shouldUseRoamSemanticSearch = (): boolean => | ||
| window.roamAlphaAPI.data.semanticSearchEnabled(); | ||
|
|
||
| export const combineDiscourseSearchResults = ({ | ||
| semantic, | ||
| keyword, | ||
| }: { | ||
| semantic: DiscourseSearchHit[]; | ||
| keyword: DiscourseSearchHit[]; | ||
| }): DiscourseSearchHit[] => { | ||
| const seenUids = new Set(semantic.map((hit) => hit.uid)); | ||
| const combined = [...semantic]; | ||
|
|
||
| keyword.forEach((hit) => { | ||
| if (seenUids.has(hit.uid)) return; | ||
| seenUids.add(hit.uid); | ||
| combined.push(hit); | ||
| }); | ||
|
|
||
| return combined; | ||
| }; | ||
|
|
||
| const toSemanticHit = (item: AdminSearchResultItem): DiscourseSearchHit => ({ | ||
| uid: item.uid, | ||
| text: item.text, | ||
| type: item.type, | ||
| nodeTypeLabel: item.nodeTypeLabel, | ||
| score: item.score ?? 0, | ||
| source: "semantic", | ||
| }); | ||
|
|
||
| export const searchDiscourseNodesWithSemanticFallback = async ({ | ||
| nodeTypes, | ||
| query, | ||
| runKeywordSearch, | ||
| }: { | ||
| nodeTypes: DiscourseNode[]; | ||
| query: string; | ||
| runKeywordSearch: () => DiscourseSearchHit[]; | ||
| }): Promise<DiscourseSearchHit[]> => { | ||
| const trimmedQuery = query.trim(); | ||
| if (!trimmedQuery) return []; | ||
|
|
||
| if (!shouldUseRoamSemanticSearch()) { | ||
| return runKeywordSearch(); | ||
| } | ||
|
|
||
| try { | ||
| const providerResult = await runRoamSemanticSearch({ | ||
| nodeTypes, | ||
| query: trimmedQuery, | ||
| }); | ||
| const semanticHits = providerResult.filteredResults.map(toSemanticHit); | ||
|
|
||
| if ( | ||
| providerResult.filteredResultCount >= | ||
| SEMANTIC_SEARCH_MIN_DISCOURSE_RESULTS | ||
| ) { | ||
| return semanticHits; | ||
| } | ||
|
|
||
| return combineDiscourseSearchResults({ | ||
| semantic: semanticHits, | ||
| keyword: runKeywordSearch(), | ||
| }); | ||
| } catch { | ||
| return runKeywordSearch(); | ||
| } | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.