Skip to content

Commit e79d6bf

Browse files
viduni94qn895
authored andcommitted
[Obs AI Assistant] Only show ELSER in EIS if available (elastic#220096)
1 parent 8744361 commit e79d6bf

File tree

7 files changed

+138
-29
lines changed

7 files changed

+138
-29
lines changed

x-pack/platform/packages/shared/kbn-ai-assistant/src/knowledge_base/select_model_and_install_knowledge_base.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ export function SelectModelAndInstallKnowledgeBase({
4949

5050
const { inferenceEndpoints, isLoading: isLoadingEndpoints, error } = useInferenceEndpoints();
5151

52+
const modelOptions: ModelOptionsData[] = getModelOptionsForInferenceEndpoints({
53+
endpoints: inferenceEndpoints,
54+
});
55+
5256
useEffect(() => {
53-
if (!selectedInferenceId && inferenceEndpoints.length) {
54-
setSelectedInferenceId(inferenceEndpoints[0].inference_id);
57+
if (!selectedInferenceId && modelOptions?.length) {
58+
setSelectedInferenceId(modelOptions[0].key);
5559
}
56-
}, [inferenceEndpoints, selectedInferenceId]);
60+
}, [modelOptions, selectedInferenceId]);
5761

5862
const handleInstall = () => {
5963
if (selectedInferenceId) {
6064
onInstall(selectedInferenceId);
6165
}
6266
};
6367

64-
const modelOptions: ModelOptionsData[] = getModelOptionsForInferenceEndpoints({
65-
endpoints: inferenceEndpoints,
66-
});
67-
6868
const superSelectOptions = modelOptions.map((option: ModelOptionsData) => ({
6969
value: option.key,
7070
inputDisplay: option.label,

x-pack/platform/packages/shared/kbn-ai-assistant/src/utils/get_model_options_for_inference_endpoints.test.ts

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,100 @@ import {
1414
ModelOptionsData,
1515
} from './get_model_options_for_inference_endpoints';
1616
import type { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils';
17+
import {
18+
ELSER_ON_ML_NODE_INFERENCE_ID,
19+
E5_LARGE_IN_EIS_INFERENCE_ID,
20+
E5_SMALL_INFERENCE_ID,
21+
ELSER_IN_EIS_INFERENCE_ID,
22+
} from '@kbn/observability-ai-assistant-plugin/public';
1723

1824
describe('getModelOptionsForInferenceEndpoints', () => {
1925
it('maps known inference endpoints to user-friendly titles and descriptions', () => {
2026
const endpoints = [
21-
{ inference_id: '.elser-2-elasticsearch' },
22-
{ inference_id: '.multilingual-e5-small-elasticsearch' },
27+
{ inference_id: ELSER_ON_ML_NODE_INFERENCE_ID },
28+
{ inference_id: E5_SMALL_INFERENCE_ID },
2329
] as InferenceAPIConfigResponse[];
2430

25-
const options: ModelOptionsData[] = getModelOptionsForInferenceEndpoints({ endpoints });
31+
const options: ModelOptionsData[] = getModelOptionsForInferenceEndpoints({
32+
endpoints,
33+
});
2634

2735
expect(options).toEqual([
2836
{
29-
key: '.elser-2-elasticsearch',
37+
key: ELSER_ON_ML_NODE_INFERENCE_ID,
3038
label: elserTitle,
3139
description: elserDescription,
3240
},
3341
{
34-
key: '.multilingual-e5-small-elasticsearch',
42+
key: E5_SMALL_INFERENCE_ID,
3543
label: e5SmallTitle,
3644
description: e5SmallDescription,
3745
},
3846
]);
3947
});
48+
49+
it('shows only ELSER in EIS when both ELSER models are available', () => {
50+
const endpoints = [
51+
{ inference_id: ELSER_ON_ML_NODE_INFERENCE_ID },
52+
{ inference_id: ELSER_IN_EIS_INFERENCE_ID },
53+
{ inference_id: E5_SMALL_INFERENCE_ID },
54+
] as InferenceAPIConfigResponse[];
55+
56+
const options = getModelOptionsForInferenceEndpoints({
57+
endpoints,
58+
});
59+
60+
expect(options.map((o) => o.key)).toEqual([ELSER_IN_EIS_INFERENCE_ID, E5_SMALL_INFERENCE_ID]);
61+
});
62+
63+
it('shows only E5-large in EIS when both E5 (small and large) models are available', () => {
64+
const endpoints = [
65+
{ inference_id: ELSER_ON_ML_NODE_INFERENCE_ID },
66+
{ inference_id: E5_SMALL_INFERENCE_ID },
67+
{ inference_id: E5_LARGE_IN_EIS_INFERENCE_ID },
68+
] as InferenceAPIConfigResponse[];
69+
70+
const options = getModelOptionsForInferenceEndpoints({
71+
endpoints,
72+
});
73+
74+
expect(options.map((o) => o.key)).toEqual([
75+
ELSER_ON_ML_NODE_INFERENCE_ID,
76+
E5_LARGE_IN_EIS_INFERENCE_ID,
77+
]);
78+
});
79+
80+
it('shows only EIS models when both ELSER and E5-large pre-configured endpoints are available in EIS', () => {
81+
const endpoints = [
82+
{ inference_id: ELSER_ON_ML_NODE_INFERENCE_ID },
83+
{ inference_id: ELSER_IN_EIS_INFERENCE_ID },
84+
{ inference_id: E5_SMALL_INFERENCE_ID },
85+
{ inference_id: E5_LARGE_IN_EIS_INFERENCE_ID },
86+
] as InferenceAPIConfigResponse[];
87+
88+
const options = getModelOptionsForInferenceEndpoints({
89+
endpoints,
90+
});
91+
92+
expect(options.map((o) => o.key)).toEqual([
93+
ELSER_IN_EIS_INFERENCE_ID,
94+
E5_LARGE_IN_EIS_INFERENCE_ID,
95+
]);
96+
});
97+
98+
it('does not show any EIS models if EIS pre-configured endpoints are not available', () => {
99+
const endpoints = [
100+
{ inference_id: ELSER_ON_ML_NODE_INFERENCE_ID },
101+
{ inference_id: E5_SMALL_INFERENCE_ID },
102+
] as InferenceAPIConfigResponse[];
103+
104+
const options = getModelOptionsForInferenceEndpoints({
105+
endpoints,
106+
});
107+
108+
expect(options.map((o) => o.key)).toEqual([
109+
ELSER_ON_ML_NODE_INFERENCE_ID,
110+
E5_SMALL_INFERENCE_ID,
111+
]);
112+
});
40113
});

x-pack/platform/packages/shared/kbn-ai-assistant/src/utils/get_model_options_for_inference_endpoints.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
import { i18n } from '@kbn/i18n';
99
import { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils';
10+
import {
11+
ELSER_ON_ML_NODE_INFERENCE_ID,
12+
E5_LARGE_IN_EIS_INFERENCE_ID,
13+
E5_SMALL_INFERENCE_ID,
14+
ELSER_IN_EIS_INFERENCE_ID,
15+
} from '@kbn/observability-ai-assistant-plugin/public';
1016

1117
export interface ModelOptionsData {
1218
key: string;
@@ -63,19 +69,19 @@ const PRECONFIGURED_INFERENCE_ENDPOINT_METADATA: Record<
6369
string,
6470
{ title: string; description: string }
6571
> = {
66-
'.elser-2-elasticsearch': {
72+
[ELSER_ON_ML_NODE_INFERENCE_ID]: {
6773
title: elserTitle,
6874
description: elserDescription,
6975
},
70-
'.elser-v2-elastic': {
76+
[ELSER_IN_EIS_INFERENCE_ID]: {
7177
title: elserTitle,
7278
description: elserDescription,
7379
},
74-
'.multilingual-e5-small-elasticsearch': {
80+
[E5_SMALL_INFERENCE_ID]: {
7581
title: e5SmallTitle,
7682
description: e5SmallDescription,
7783
},
78-
'.multilingual-e5-large-elasticsearch': {
84+
[E5_LARGE_IN_EIS_INFERENCE_ID]: {
7985
title: e5LargeTitle,
8086
description: e5LargeDescription,
8187
},
@@ -86,22 +92,30 @@ export const getModelOptionsForInferenceEndpoints = ({
8692
}: {
8793
endpoints: InferenceAPIConfigResponse[];
8894
}): ModelOptionsData[] => {
89-
// TODO: add logic to show the EIS models if EIS is enabled, if not show the other models
90-
const preConfiguredEndpoints = endpoints
91-
.map((endpoint) => {
92-
const meta = PRECONFIGURED_INFERENCE_ENDPOINT_METADATA[endpoint.inference_id];
95+
const hasElserEIS = endpoints.some((ep) => ep.inference_id === ELSER_IN_EIS_INFERENCE_ID);
96+
const hasE5EIS = endpoints.some((ep) => ep.inference_id === E5_LARGE_IN_EIS_INFERENCE_ID);
97+
98+
return endpoints
99+
.filter((endpoint) => {
100+
// if ELSER exists in EIS, skip the other ELSER model
101+
if (endpoint.inference_id === ELSER_ON_ML_NODE_INFERENCE_ID && hasElserEIS) {
102+
return false;
103+
}
93104

94-
if (!meta) {
95-
return undefined;
105+
if (endpoint.inference_id === E5_SMALL_INFERENCE_ID && hasE5EIS) {
106+
return false;
96107
}
97108

109+
// Only include preconfigured endpoints and skip custom endpoints
110+
return Boolean(PRECONFIGURED_INFERENCE_ENDPOINT_METADATA[endpoint.inference_id]);
111+
})
112+
.map((endpoint) => {
113+
const meta = PRECONFIGURED_INFERENCE_ENDPOINT_METADATA[endpoint.inference_id]!;
114+
98115
return {
99116
key: endpoint.inference_id,
100117
label: meta.title,
101118
description: meta.description,
102119
};
103-
})
104-
.filter(Boolean) as ModelOptionsData[];
105-
106-
return preConfiguredEndpoints;
120+
});
107121
};

x-pack/platform/plugins/shared/observability_ai_assistant/common/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ export {
5252
export { concatenateChatCompletionChunks } from './utils/concatenate_chat_completion_chunks';
5353

5454
export { ShortIdTable } from './utils/short_id_table';
55+
56+
export {
57+
ELSER_ON_ML_NODE_INFERENCE_ID,
58+
ELSER_IN_EIS_INFERENCE_ID,
59+
E5_SMALL_INFERENCE_ID,
60+
E5_LARGE_IN_EIS_INFERENCE_ID,
61+
} from './preconfigured_inference_ids';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
export const ELSER_ON_ML_NODE_INFERENCE_ID = '.elser-2-elasticsearch';
9+
export const ELSER_IN_EIS_INFERENCE_ID = '.elser-v2-elastic';
10+
11+
export const E5_SMALL_INFERENCE_ID = '.multilingual-e5-small-elasticsearch';
12+
export const E5_LARGE_IN_EIS_INFERENCE_ID = '.multilingual-e5-large-elastic'; // TODO: verify the inference ID once it's created in EIS

x-pack/platform/plugins/shared/observability_ai_assistant/public/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export {
6969
ConversationAccess,
7070
KnowledgeBaseType,
7171
KnowledgeBaseState,
72+
ELSER_ON_ML_NODE_INFERENCE_ID,
73+
ELSER_IN_EIS_INFERENCE_ID,
74+
E5_SMALL_INFERENCE_ID,
75+
E5_LARGE_IN_EIS_INFERENCE_ID,
7276
} from '../common';
7377

7478
export type {

x-pack/platform/plugins/shared/observability_ai_assistant/server/service/index_assets/update_existing_index_assets.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
*/
77

88
import type { CoreSetup, Logger } from '@kbn/core/server';
9+
import { ELSER_ON_ML_NODE_INFERENCE_ID } from '../../../common';
910
import type { ObservabilityAIAssistantPluginStartDependencies } from '../../types';
1011
import { createOrUpdateConversationIndexAssets } from './create_or_update_conversation_index_assets';
1112
import { createOrUpdateKnowledgeBaseIndexAssets } from './create_or_update_knowledge_base_index_assets';
1213
import { hasKbWriteIndex } from '../knowledge_base_service/has_kb_index';
1314
import { getInferenceIdFromWriteIndex } from '../knowledge_base_service/get_inference_id_from_write_index';
1415
import { resourceNames } from '..';
1516

16-
export const DEFAULT_INFERENCE_ENDPOINT = '.elser-2-elasticsearch';
17-
1817
export async function updateExistingIndexAssets({
1918
logger,
2019
core,
@@ -48,7 +47,7 @@ export async function updateExistingIndexAssets({
4847
logger.debug(
4948
`Current KB write index does not have an inference_id. This is to be expected for indices created before 8.16`
5049
);
51-
return DEFAULT_INFERENCE_ENDPOINT;
50+
return ELSER_ON_ML_NODE_INFERENCE_ID;
5251
});
5352

5453
await createOrUpdateKnowledgeBaseIndexAssets({ logger, core, inferenceId: currentInferenceId });

0 commit comments

Comments
 (0)