-
Notifications
You must be signed in to change notification settings - Fork 1.1k
global semantic search: neural sparse search #10696
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
base: feature/global-semantic-search-neural-sparse
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,10 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { AppCategory } from 'opensearch-dashboards/public'; | ||
import { AppCategory, HttpStart } from 'opensearch-dashboards/public'; | ||
import { ChromeNavLink } from './nav_links'; | ||
import { ChromeRegistrationNavLink, NavGroupItemInMap } from './nav_group'; | ||
import { NavGroupStatus } from '../../../core/types'; | ||
|
||
type KeyOf<T> = keyof T; | ||
|
||
export const sortBy = <T>(key: KeyOf<T>) => { | ||
|
@@ -240,12 +239,13 @@ export function setIsCategoryOpen(id: string, isOpen: boolean, storage: Storage) | |
storage.setItem(getCategoryLocalStorageKey(id), `${isOpen}`); | ||
} | ||
|
||
export function searchNavigationLinks( | ||
export async function searchNavigationLinks( | ||
allAvailableCaseId: string[], | ||
navGroupMap: Record<string, NavGroupItemInMap>, | ||
query: string | ||
query: string, | ||
http?: HttpStart | ||
) { | ||
return allAvailableCaseId.flatMap((useCaseId) => { | ||
const allSearchAbleLinks = allAvailableCaseId.flatMap((useCaseId) => { | ||
const navGroup = navGroupMap[useCaseId]; | ||
if (!navGroup) return []; | ||
|
||
|
@@ -255,27 +255,49 @@ export function searchNavigationLinks( | |
|
||
return links | ||
.filter((link) => { | ||
const title = link.title; | ||
return !link.hidden && !link.disabled && !parentNavLinkIds.includes(link.id); | ||
}) | ||
.map((link) => { | ||
let parentNavLinkTitle; | ||
// parent title also taken into consideration for search its sub items | ||
if (link.parentNavLinkId) { | ||
parentNavLinkTitle = navGroup.navLinks.find( | ||
(navLink) => navLink.id === link.parentNavLinkId | ||
)?.title; | ||
} | ||
const titleMatch = title && title.toLowerCase().includes(query.toLowerCase()); | ||
const parentTitleMatch = | ||
parentNavLinkTitle && parentNavLinkTitle.toLowerCase().includes(query.toLowerCase()); | ||
return ( | ||
!link.hidden && | ||
!link.disabled && | ||
(titleMatch || parentTitleMatch) && | ||
!parentNavLinkIds.includes(link.id) | ||
); | ||
}) | ||
.map((link) => ({ | ||
...link, | ||
navGroup, | ||
})); | ||
return { | ||
...link, | ||
parentNavLinkTitle, | ||
navGroup, | ||
}; | ||
}); | ||
}); | ||
|
||
try { | ||
console.log('All links:', allSearchAbleLinks); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
const linksContext = allSearchAbleLinks.map((link) => ({ | ||
id: link.id, | ||
title: link.title, | ||
description: link.description ?? link.title, | ||
})); | ||
const semanticSearchResult = await http?.post('/api/workspaces/_semantic_search', { | ||
body: JSON.stringify({ | ||
query: query, | ||
links: linksContext, | ||
}), | ||
}); | ||
|
||
const finalResult = semanticSearchResult | ||
.map((link: any) => { | ||
const originalFullLink = allSearchAbleLinks.find((fullLink) => fullLink.id === link.id); | ||
return originalFullLink || null; | ||
}) | ||
.filter(Boolean) as Array<ChromeRegistrationNavLink & ChromeNavLink>; | ||
|
||
console.log('Final Semantic Search Result (from backend): ', finalResult); | ||
return finalResult; | ||
} catch (error) { | ||
console.error('Frontend API call error for semantic search:', error); | ||
throw error; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,7 @@ export class DiscoverPlugin | |
core.application.register({ | ||
id: PLUGIN_ID, | ||
title: 'Discover', | ||
description: 'Analyze your data in OpenSearch and visualize key metrics.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for curiosity, would the performance of semantic search be more accurate if we can have a more explanatory and detailed description for each application? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it will imrpove the relevance. We can enrich them in the future. |
||
updater$: this.appStateUpdater.asObservable(), | ||
order: 1000, | ||
workspaceAvailability: WorkspaceAvailability.insideWorkspace, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: comment need changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reminding!