-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[UII] Set up knowledge index entry for .integration_knowledge
#231866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
125cf48
e92d637
b6ecec3
738e18b
2b05d08
f672696
fe1cb28
c68c89b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * 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 { AnalyticsServiceSetup, Logger } from '@kbn/core/server'; | ||
| import { IndexEntryType } from '@kbn/elastic-assistant-common'; | ||
| import { AIAssistantKnowledgeBaseDataClient } from '../ai_assistant_data_clients/knowledge_base'; | ||
|
|
||
| const INTEGRATION_KNOWLEDGE_INDEX_NAME = '.integration_knowledge'; | ||
|
|
||
| /** | ||
| * Checks if the integration knowledge index entry already exists | ||
| */ | ||
| export const checkIntegrationKnowledgeIndexEntryExists = async ({ | ||
| kbDataClient, | ||
| logger, | ||
| }: { | ||
| kbDataClient: AIAssistantKnowledgeBaseDataClient; | ||
| logger: Logger; | ||
| }): Promise<boolean> => { | ||
| try { | ||
| const results = await kbDataClient.findDocuments({ | ||
|
jen-huang marked this conversation as resolved.
Outdated
|
||
| page: 1, | ||
| perPage: 1, | ||
| filter: `type:index AND index:${INTEGRATION_KNOWLEDGE_INDEX_NAME}`, | ||
| }); | ||
|
|
||
| const exists = results.total > 0; | ||
| logger.debug(`Integration knowledge index entry exists: ${exists}`); | ||
| return exists; | ||
| } catch (error) { | ||
| logger.debug(`Error checking integration knowledge index entry: ${error.message}`); | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Ensures the integration knowledge index entry exists during Knowledge Base setup. | ||
| * Similar to loadSecurityLabs() but for Index Entries rather than Document Entries. | ||
| */ | ||
| export const ensureIntegrationKnowledgeIndexEntry = async ( | ||
| kbDataClient: AIAssistantKnowledgeBaseDataClient, | ||
| logger: Logger, | ||
| telemetry: AnalyticsServiceSetup | ||
| ): Promise<boolean> => { | ||
| try { | ||
| logger.debug('Checking if integration knowledge index entry exists...'); | ||
|
|
||
| const entryExists = await checkIntegrationKnowledgeIndexEntryExists({ | ||
| kbDataClient, | ||
| logger, | ||
| }); | ||
|
|
||
| if (!entryExists) { | ||
| logger.debug('Creating integration knowledge index entry...'); | ||
|
|
||
| const entry = await kbDataClient.createKnowledgeBaseEntry({ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIU, this will be executed as the current user at the time of the request context factory creation. my concerns:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually executed with I think this should work, as the IndexEntry is marked as WRT
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually just about to pick up a major refactor of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tried this approach but the pattern of using a dummy user felt quite odd, so I reverted it and left the implementation as is.
what do you mean I moved the call to on the Fleet side, we don't do any additional checks before we install a package's KB contents (push documents to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By assets I just meant all the index/component templates and such. Was just commenting that we could create the initial
This is fine. As far as I understand (need to test/confirm though), document creates with no value for the We actually just got confirmation this week from Product that we can tie assistant features to inference API availability, so that means the KB setup process is going to go away. We can now always assume we'll have access to an inference endpoint (and so can ingest documents containing Let's chat when you have a moment and we can see what Søren has to say on that issue as well. |
||
| knowledgeBaseEntry: { | ||
| type: IndexEntryType.value, | ||
| index: INTEGRATION_KNOWLEDGE_INDEX_NAME, | ||
| field: 'content', | ||
| name: 'Integration Knowledge', | ||
| description: | ||
| 'Integration knowledge base containing semantic information about integrations installed via Fleet', | ||
| queryDescription: | ||
| 'Use this tool to search for information about integrations, integration configurations, troubleshooting guides, and best practices', | ||
|
jen-huang marked this conversation as resolved.
Outdated
|
||
| global: true, | ||
| users: [], | ||
| }, | ||
| telemetry, | ||
| }); | ||
|
|
||
| if (entry) { | ||
| logger.info('Integration knowledge index entry created successfully'); | ||
| return true; | ||
| } else { | ||
| logger.warn('Failed to create integration knowledge index entry'); | ||
| return false; | ||
| } | ||
| } else { | ||
| logger.debug('Integration knowledge index entry already exists'); | ||
| return true; | ||
| } | ||
| } catch (error) { | ||
| logger.error(`Error ensuring integration knowledge index entry: ${error.message}`); | ||
| return false; | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.