diff --git a/x-pack/plugins/observability_ai_assistant/server/functions/context.ts b/x-pack/plugins/observability_ai_assistant/server/functions/context.ts index 9efa69ca81bd8..74c7048c383d1 100644 --- a/x-pack/plugins/observability_ai_assistant/server/functions/context.ts +++ b/x-pack/plugins/observability_ai_assistant/server/functions/context.ts @@ -122,23 +122,33 @@ export function registerContextFunction({ }; } - const { relevantDocuments, scores } = await scoreSuggestions({ - suggestions, - queries: queriesOrUserPrompt, - messages, - client, - connectorId, - signal, - logger: resources.logger, - }); - - return { - content: { ...content, learnings: relevantDocuments as unknown as Serializable }, - data: { - scores, + try { + const { relevantDocuments, scores } = await scoreSuggestions({ suggestions, - }, - }; + queries: queriesOrUserPrompt, + messages, + client, + connectorId, + signal, + logger: resources.logger, + }); + + return { + content: { ...content, learnings: relevantDocuments as unknown as Serializable }, + data: { + scores, + suggestions, + }, + }; + } catch (error) { + return { + content: { ...content, learnings: suggestions.slice(0, 5) }, + data: { + error, + suggestions, + }, + }; + } } return new Observable((subscriber) => {