forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Obs AI Assistant] Use architecture-specific elser model (elastic#205851
) Closes elastic#205852 When installing the Obs knowledge base it will always install the model `.elser_model_2`. For Linux with an x86-64 CPU an optimised version of Elser exists (`elser_model_2_linux-x86_64`). We should use that when possible. After this change the inference endpoint will use `.elser_model_2_linux-x86_64` on supported hardware: ![image](https://github.com/user-attachments/assets/fedc6700-877a-47ab-a3b8-055db53407d0) (cherry picked from commit ad3b988)
- Loading branch information
Showing
5 changed files
with
63 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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
53 changes: 53 additions & 0 deletions
53
...on/observability_ai_assistant/server/service/knowledge_base_service/get_elser_model_id.ts
This file contains 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,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { Logger } from '@kbn/logging'; | ||
import { CoreSetup } from '@kbn/core-lifecycle-server'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import { ObservabilityAIAssistantPluginStartDependencies } from '../../types'; | ||
|
||
export async function getElserModelId({ | ||
core, | ||
logger, | ||
}: { | ||
core: CoreSetup<ObservabilityAIAssistantPluginStartDependencies>; | ||
logger: Logger; | ||
}) { | ||
const defaultModelId = '.elser_model_2'; | ||
const [_, pluginsStart] = await core.getStartServices(); | ||
|
||
// Wait for the license to be available so the ML plugin's guards pass once we ask for ELSER stats | ||
const license = await firstValueFrom(pluginsStart.licensing.license$); | ||
if (!license.hasAtLeast('enterprise')) { | ||
return defaultModelId; | ||
} | ||
|
||
try { | ||
// Wait for the ML plugin's dependency on the internal saved objects client to be ready | ||
const { ml } = await core.plugins.onSetup<{ | ||
ml: { | ||
trainedModelsProvider: ( | ||
request: {}, | ||
soClient: {} | ||
) => { getELSER: () => Promise<{ model_id: string }> }; | ||
}; | ||
}>('ml'); | ||
|
||
if (!ml.found) { | ||
throw new Error('Could not find ML plugin'); | ||
} | ||
|
||
const elserModelDefinition = await ml.contract | ||
.trainedModelsProvider({} as any, {} as any) // request, savedObjectsClient (but we fake it to use the internal user) | ||
.getELSER(); | ||
|
||
return elserModelDefinition.model_id; | ||
} catch (error) { | ||
logger.error(`Failed to resolve ELSER model definition: ${error}`); | ||
return defaultModelId; | ||
} | ||
} |
This file contains 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 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