Skip to content

Commit

Permalink
[Security KB] Fix setup KB (elastic#201175)
Browse files Browse the repository at this point in the history
## Summary

Fix an issue with auto-recovery of Knowledge Base setup.

When the KB setup was initialized on an undersized cluster, the model
failed to deploy correctly. This resulted in the KB ending up in a
broken state, repeatedly displaying the Setup KB button.

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 1cb56d7)
  • Loading branch information
patrykkopycinski committed Nov 22, 2024
1 parent 25884bd commit 1111369
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,22 @@ export class AIAssistantKnowledgeBaseDataClient extends AIAssistantDataClient {
public createInferenceEndpoint = async () => {
const elserId = await this.options.getElserId();
this.options.logger.debug(`Deploying ELSER model '${elserId}'...`);
const esClient = await this.options.elasticsearchClientPromise;

try {
const esClient = await this.options.elasticsearchClientPromise;
await esClient.inference.delete({
inference_id: ASSISTANT_ELSER_INFERENCE_ID,
// it's being used in the mapping so we need to force delete
force: true,
});
this.options.logger.debug(`Deleted existing inference endpoint for ELSER model '${elserId}'`);
} catch (error) {
this.options.logger.error(
`Error deleting inference endpoint for ELSER model '${elserId}':\n${error}`
);
}

try {
await esClient.inference.put({
task_type: 'sparse_embedding',
inference_id: ASSISTANT_ELSER_INFERENCE_ID,
Expand All @@ -198,6 +211,9 @@ export class AIAssistantKnowledgeBaseDataClient extends AIAssistantDataClient {
task_settings: {},
},
});

// await for the model to be deployed
await this.isInferenceEndpointExists();
} catch (error) {
this.options.logger.error(
`Error creating inference endpoint for ELSER model '${elserId}':\n${error}`
Expand Down

0 comments on commit 1111369

Please sign in to comment.