Skip to content

Commit 835705b

Browse files
committed
initial commit
Signed-off-by: Zhenxing Shen <[email protected]>
1 parent d1e06a9 commit 835705b

File tree

4 files changed

+69
-15
lines changed

4 files changed

+69
-15
lines changed

config/opensearch_dashboards.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OpenSearch Dashboards is served by a back end server. This setting specifies the port to use.
2-
#server.port: 5601
2+
# server.port: 5602
33

44
# Specifies the address to which the OpenSearch Dashboards server will bind. IP addresses and host names are both valid values.
55
# The default is 'localhost', which usually means remote machines will not be able to connect.
@@ -379,3 +379,28 @@
379379

380380
# Set the value to true to enable the new UI for savedQueries in Discover
381381
# data.savedQueriesNewUI.enabled: true
382+
# for olly2
383+
workspace.enabled: true
384+
savedObjects.permission.enabled: true
385+
data_source.enabled: true
386+
uiSettings:
387+
overrides:
388+
'home:useNewHomePage': true
389+
'courier:batchSearches': false
390+
'query:enhancements:enabled': true
391+
defaults:
392+
'theme:darkMode': false
393+
assistant.alertInsight.enabled: true
394+
assistant.chat.enabled: true
395+
assistant.smartAnomalyDetector.enabled: true
396+
assistant.text2viz.enabled: true
397+
queryEnhancements.queryAssist.summary.enabled: true
398+
observability.query_assist.enabled: true
399+
# opensearch.hosts: ['http://k8s-ruanyl-opensear-0b8ea918c5-897697169.us-west-1.elb.amazonaws.com:80']
400+
opensearch.hosts:
401+
['http://k8s-zxshende-opensear-89396f29f2-469603532.us-east-1.elb.amazonaws.com:80']
402+
# opensearch.hosts: ['http://localhost:9200']
403+
opensearch.username: 'admin'
404+
opensearch.password: 'myStrongPassword123!'
405+
opensearchDashboards.dashboardAdmin.users: ['admin']
406+
server.port: 5602

src/core/public/chrome/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ export async function searchNavigationLinks(
292292
const originalFullLink = allSearchAbleLinks.find((fullLink) => fullLink.id === link.id);
293293
return originalFullLink || null;
294294
})
295-
// .filter(Boolean) as (ChromeRegistrationNavLink & ChromeNavLink)[];
296295
.filter(Boolean) as Array<ChromeRegistrationNavLink & ChromeNavLink>;
297296

298297
console.log('Final Semantic Search Result (from backend): ', finalResult);

src/plugins/workspace/public/plugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ export class WorkspacePlugin
345345
title: i18n.translate('workspace.settings.workspaceDetail', {
346346
defaultMessage: 'Workspace Detail',
347347
}),
348+
description:
349+
"Define and manage a workspace's details, including its name, description, use case, icon color, and privacy settings.",
348350
navLinkStatus: core.chrome.navGroup.getNavGroupEnabled()
349351
? AppNavLinkStatus.visible
350352
: AppNavLinkStatus.hidden,
@@ -362,6 +364,7 @@ export class WorkspacePlugin
362364
title: i18n.translate('workspace.settings.workspaceCollaborators', {
363365
defaultMessage: 'Collaborators',
364366
}),
367+
description: 'Manage workspace access and permissions.',
365368
navLinkStatus: core.chrome.navGroup.getNavGroupEnabled()
366369
? AppNavLinkStatus.visible
367370
: AppNavLinkStatus.hidden,

src/plugins/workspace/server/routes/index.ts

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const updateWorkspaceAttributesSchema = schema.object({
116116

117117
// Declare a variable outside the route handler to cache the model.
118118
let semanticExtractor: any = null;
119+
let answerer: any = null;
119120

120121
export function registerRoutes({
121122
client,
@@ -367,13 +368,19 @@ export function registerRoutes({
367368
try {
368369
const { query, links } = req.body;
369370

370-
// Filter links to ensure they have a description for the semantic search
371-
let linksWithDescription = links.filter((link) => !!link.description);
372-
linksWithDescription = Array.from(new Set(linksWithDescription.map((link) => link.id))).map(
373-
(id) => linksWithDescription.find((link) => link.id === id)!
374-
);
375-
376371
console.log('-------------Enter semanticSearch (Node.js)-------------');
372+
if (!answerer) {
373+
const startTime = performance.now();
374+
answerer = await pipeline(
375+
'question-answering',
376+
'Xenova/tiny-random-RoFormerForQuestionAnswering'
377+
);
378+
const endTime = performance.now();
379+
const loadingTimeMs = endTime - startTime;
380+
381+
console.log('Answer loaded and ready for inference.');
382+
console.log(`Answer loading took: ${loadingTimeMs.toFixed(2)} ms`);
383+
}
377384

378385
// Load the model only once and reuse it later
379386
if (!semanticExtractor) {
@@ -393,7 +400,7 @@ export function registerRoutes({
393400

394401
// Generate embeddings for links
395402
const linkEmbeddings = await Promise.all(
396-
linksWithDescription.map(async (link) => {
403+
links.map(async (link) => {
397404
const titleOutput = await semanticExtractor(link.title, {
398405
pooling: 'mean',
399406
normalize: true,
@@ -409,13 +416,13 @@ export function registerRoutes({
409416
descriptionEmbedding = Array.from(descOutput.data) as number[];
410417
}
411418

412-
const WEIGHT_TITLE = 0.7;
413-
const WEIGHT_DESC = 0.3;
419+
const titleWeight = 0.7;
420+
const descWeight = 0.3;
414421

415422
let combinedEmbedding: number[] = [];
416423

417424
combinedEmbedding = titleEmbedding.map(
418-
(val, i) => val * WEIGHT_TITLE + descriptionEmbedding![i] * WEIGHT_DESC
425+
(val, i) => val * titleWeight + descriptionEmbedding![i] * descWeight
419426
);
420427

421428
return { ...link, embedding: combinedEmbedding };
@@ -430,18 +437,38 @@ export function registerRoutes({
430437
// Calculate scores and sort
431438
const scored = linkEmbeddings.map((link) => ({
432439
...link,
433-
// score: cosineSimilarity(queryEmbedding as number[], link.embedding as number[]),
434440
score: cos_sim(queryEmbedding as number[], link.embedding as number[]),
435441
}));
436442

437443
scored.sort((a, b) => b.score - a.score);
438444

439445
const semanticSearchResult = scored
440-
.slice(0, 8)
441-
.filter((item) => item.score > 0.08)
446+
.slice(0, 5)
447+
.filter((item) => item.score > 0.2)
442448
.map(({ embedding, ...rest }) => rest);
443449
console.log('semanticSearchResult: ', semanticSearchResult);
444450

451+
const qaResults = [];
452+
453+
for (const link of links) {
454+
const answer = await answerer(query, link.description);
455+
if (answer && answer.answer) {
456+
qaResults.push({
457+
linkId: link.id,
458+
title: link.title,
459+
description: link.description,
460+
answer: answer.answer,
461+
score: answer.score,
462+
});
463+
}
464+
}
465+
466+
qaResults.sort((a, b) => b.score - a.score);
467+
468+
const finalQaResults = qaResults.slice(0, 5).filter((item) => item.score > 0.1);
469+
470+
console.log('Question Answering: ', finalQaResults);
471+
445472
return res.ok({ body: semanticSearchResult });
446473
} catch (error) {
447474
console.error('Error during semantic search:', error);

0 commit comments

Comments
 (0)