Skip to content

Commit

Permalink
[Security Solution][Elastic AI Assistant] Refactors Knowledge Base fe…
Browse files Browse the repository at this point in the history
…ature flag to UI feature toggle (#167935)

## Summary

This PR refactors the `assistantLangChain` code feature flag introduced
in #164908, to be a UI feature
toggle that users can enable/disable via the `Knowledge Base` assistant
advanced settings.


Left image shows the feature disabled, and the right image shows the
feature partly enabled. If ELSER is configured, the UI will attempt to
install all resources automatically for a one-click UX, however if ELSER
is not configured, or there are failures, the user can manually enable
the Knowledge Base or ES|QL base documentation:

<p align="center">
<img width="400"
src="https://github.com/elastic/kibana/assets/2946766/be85522e-b2f5-4a39-9f0e-d359424caf37"
/> <img width="400"
src="https://github.com/elastic/kibana/assets/2946766/d901c4f8-2184-4fb7-8c59-f2ff877118b9"
/>
</p> 




Also, since this code feature flag was shared with the model evaluator
experimental feature, a `modelEvaluatorEnabled` flag has been plumbed to
fully decouple the two settings. Now _only the_ model evaluator is
enabled when setting security Solution Advanced setting:

```
xpack.securitySolution.enableExperimental: ['assistantModelEvaluation']
```

and the previous `assistantLangChain` code feature flag is now enabled
by simply toggling on the Knowledge Base in the settings shown above.

> [!NOTE]
> Even if ELSER isn't configured, and the knowledge base/docs aren't
setup, if the Knowledge Base is enabled, the LangChain code path will
still be enabled as intended, but we can change this behavior if testing
shows this is not ideal.


### Checklist

Delete any items that are not applicable to this PR.

- [X] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)added
to match the most common scenarios
- [X] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
  • Loading branch information
spong authored Oct 3, 2023
1 parent ce5ae7d commit e74e5e2
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 309 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { useAssistantContext } from '../../assistant_context';
import { AnonymizationSettings } from '../../data_anonymization/settings/anonymization_settings';
import { QuickPromptSettings } from '../quick_prompts/quick_prompt_settings/quick_prompt_settings';
import { SystemPromptSettings } from '../prompt_editor/system_prompt/system_prompt_modal/system_prompt_settings';
import { AdvancedSettings } from './advanced_settings/advanced_settings';
import { KnowledgeBaseSettings } from '../../knowledge_base/knowledge_base_settings/knowledge_base_settings';
import { ConversationSettings } from '../conversations/conversation_settings/conversation_settings';
import { TEST_IDS } from '../constants';
import { useSettingsUpdater } from './use_settings_updater/use_settings_updater';
Expand All @@ -45,15 +45,15 @@ export const CONVERSATIONS_TAB = 'CONVERSATION_TAB' as const;
export const QUICK_PROMPTS_TAB = 'QUICK_PROMPTS_TAB' as const;
export const SYSTEM_PROMPTS_TAB = 'SYSTEM_PROMPTS_TAB' as const;
export const ANONYMIZATION_TAB = 'ANONYMIZATION_TAB' as const;
export const ADVANCED_TAB = 'ADVANCED_TAB' as const;
export const KNOWLEDGE_BASE_TAB = 'KNOWLEDGE_BASE_TAB' as const;
export const EVALUATION_TAB = 'EVALUATION_TAB' as const;

export type SettingsTabs =
| typeof CONVERSATIONS_TAB
| typeof QUICK_PROMPTS_TAB
| typeof SYSTEM_PROMPTS_TAB
| typeof ANONYMIZATION_TAB
| typeof ADVANCED_TAB
| typeof KNOWLEDGE_BASE_TAB
| typeof EVALUATION_TAB;
interface Props {
defaultConnectorId?: string;
Expand All @@ -68,7 +68,7 @@ interface Props {

/**
* Modal for overall Assistant Settings, including conversation settings, quick prompts, system prompts,
* anonymization, functions (coming soon!), and advanced settings.
* anonymization, knowledge base, and evaluation via the `isModelEvaluationEnabled` feature flag.
*/
export const AssistantSettings: React.FC<Props> = React.memo(
({
Expand All @@ -79,17 +79,19 @@ export const AssistantSettings: React.FC<Props> = React.memo(
selectedConversation: defaultSelectedConversation,
setSelectedConversationId,
}) => {
const { assistantLangChain, http, selectedSettingsTab, setSelectedSettingsTab } =
const { modelEvaluatorEnabled, http, selectedSettingsTab, setSelectedSettingsTab } =
useAssistantContext();
const {
conversationSettings,
defaultAllow,
defaultAllowReplacement,
knowledgeBase,
quickPromptSettings,
systemPromptSettings,
setUpdatedConversationSettings,
setUpdatedDefaultAllow,
setUpdatedDefaultAllowReplacement,
setUpdatedKnowledgeBaseSettings,
setUpdatedQuickPromptSettings,
setUpdatedSystemPromptSettings,
saveSettings,
Expand Down Expand Up @@ -236,17 +238,15 @@ export const AssistantSettings: React.FC<Props> = React.memo(
>
<EuiIcon type="eyeClosed" size="l" />
</EuiKeyPadMenuItem>
{assistantLangChain && (
<EuiKeyPadMenuItem
id={ADVANCED_TAB}
label={i18n.ADVANCED_MENU_ITEM}
isSelected={selectedSettingsTab === ADVANCED_TAB}
onClick={() => setSelectedSettingsTab(ADVANCED_TAB)}
>
<EuiIcon type="advancedSettingsApp" size="l" />
</EuiKeyPadMenuItem>
)}
{assistantLangChain && (
<EuiKeyPadMenuItem
id={KNOWLEDGE_BASE_TAB}
label={i18n.KNOWLEDGE_BASE_MENU_ITEM}
isSelected={selectedSettingsTab === KNOWLEDGE_BASE_TAB}
onClick={() => setSelectedSettingsTab(KNOWLEDGE_BASE_TAB)}
>
<EuiIcon type="notebookApp" size="l" />
</EuiKeyPadMenuItem>
{modelEvaluatorEnabled && (
<EuiKeyPadMenuItem
id={EVALUATION_TAB}
label={i18n.EVALUATION_MENU_ITEM}
Expand Down Expand Up @@ -307,7 +307,12 @@ export const AssistantSettings: React.FC<Props> = React.memo(
setUpdatedDefaultAllowReplacement={setUpdatedDefaultAllowReplacement}
/>
)}
{selectedSettingsTab === ADVANCED_TAB && <AdvancedSettings />}
{selectedSettingsTab === KNOWLEDGE_BASE_TAB && (
<KnowledgeBaseSettings
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={setUpdatedKnowledgeBaseSettings}
/>
)}
{selectedSettingsTab === EVALUATION_TAB && <EvaluationSettings />}
</EuiSplitPanel.Inner>
<EuiSplitPanel.Inner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export const ANONYMIZATION_MENU_ITEM = i18n.translate(
}
);

export const ADVANCED_MENU_ITEM = i18n.translate(
'xpack.elasticAssistant.assistant.settings.settingsAdvancedMenuItemTitle',
export const KNOWLEDGE_BASE_MENU_ITEM = i18n.translate(
'xpack.elasticAssistant.assistant.settings.settingsKnowledgeBaseMenuItemTitle',
{
defaultMessage: 'Advanced',
defaultMessage: 'Knowledge Base',
}
);

Expand Down
Loading

0 comments on commit e74e5e2

Please sign in to comment.