Skip to content
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

[8.12] [Security Solution] [Elastic AI Assistant] Delete the _Retrieval Augmented Generation (RAG) for Alerts_ Feature Flag (#173809) #173883

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ const AlertsSettingsComponent = ({ knowledgeBase, setUpdatedKnowledgeBaseSetting
<EuiSpacer size="xs" />

<EuiFlexGroup direction="column" gutterSize="none">
<EuiFlexItem grow={false}>
<EuiText color="subdued" size="xs">
<span>{i18n.ASK_QUESTIONS_ABOUT}</span>
</EuiText>
</EuiFlexItem>

<EuiFlexItem
css={css`
width: ${RANGE_CONTAINER_WIDTH}px;
Expand Down Expand Up @@ -106,7 +100,7 @@ const AlertsSettingsComponent = ({ knowledgeBase, setUpdatedKnowledgeBaseSetting

<EuiFlexItem grow={false}>
<EuiText color="subdued" size="xs">
<span>{i18n.LATEST_AND_RISKIEST_OPEN_ALERTS}</span>
<span>{i18n.LATEST_AND_RISKIEST_OPEN_ALERTS(knowledgeBase.latestAlerts)}</span>
</EuiText>
</EuiFlexItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const fetchConnectorArgs: FetchConnectorExecuteAction = {
http: mockHttp,
messages,
onNewReplacements: jest.fn(),
ragOnAlerts: false,
};
describe('API tests', () => {
beforeEach(() => {
Expand Down Expand Up @@ -91,7 +90,6 @@ describe('API tests', () => {
alertsIndexPattern: '.alerts-security.alerts-default',
allow: ['a', 'b', 'c'],
allowReplacement: ['b', 'c'],
ragOnAlerts: true,
replacements: { auuid: 'real.hostname' },
size: 30,
};
Expand Down
4 changes: 0 additions & 4 deletions x-pack/packages/kbn-elastic-assistant/impl/assistant/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export interface FetchConnectorExecuteAction {
http: HttpSetup;
messages: Message[];
onNewReplacements: (newReplacements: Record<string, string>) => void;
ragOnAlerts: boolean;
replacements?: Record<string, string>;
signal?: AbortSignal | undefined;
size?: number;
Expand All @@ -55,7 +54,6 @@ export const fetchConnectorExecuteAction = async ({
http,
messages,
onNewReplacements,
ragOnAlerts,
replacements,
apiConfig,
signal,
Expand Down Expand Up @@ -90,7 +88,6 @@ export const fetchConnectorExecuteAction = async ({
alertsIndexPattern,
allow,
allowReplacement,
ragOnAlerts,
replacements,
size,
});
Expand Down Expand Up @@ -192,7 +189,6 @@ export const fetchConnectorExecuteAction = async ({
response: hasParsableResponse({
alerts,
assistantLangChain,
ragOnAlerts,
})
? getFormattedMessageContent(response.data)
: response.data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,29 +235,12 @@ describe('getBlockBotConversation', () => {
});

describe('getOptionalRequestParams', () => {
it('should return an empty object when ragOnAlerts is false', () => {
const params = {
alerts: true,
alertsIndexPattern: 'indexPattern',
allow: ['a', 'b', 'c'],
allowReplacement: ['b', 'c'],
ragOnAlerts: false, // <-- false
replacements: { key: 'value' },
size: 10,
};

const result = getOptionalRequestParams(params);

expect(result).toEqual({});
});

it('should return an empty object when alerts is false', () => {
const params = {
alerts: false, // <-- false
alertsIndexPattern: 'indexPattern',
allow: ['a', 'b', 'c'],
allowReplacement: ['b', 'c'],
ragOnAlerts: true,
replacements: { key: 'value' },
size: 10,
};
Expand All @@ -267,13 +250,12 @@ describe('getBlockBotConversation', () => {
expect(result).toEqual({});
});

it('should return the optional request params when ragOnAlerts is true and alerts is true', () => {
it('should return the optional request params when alerts is true', () => {
const params = {
alerts: true,
alertsIndexPattern: 'indexPattern',
allow: ['a', 'b', 'c'],
allowReplacement: ['b', 'c'],
ragOnAlerts: true,
replacements: { key: 'value' },
size: 10,
};
Expand All @@ -292,7 +274,6 @@ describe('getBlockBotConversation', () => {
it('should return (only) the optional request params that are defined when some optional params are not provided', () => {
const params = {
alerts: true,
ragOnAlerts: true,
allow: ['a', 'b', 'c'], // all the others are undefined
};

Expand All @@ -305,31 +286,37 @@ describe('getBlockBotConversation', () => {
});

describe('hasParsableResponse', () => {
it('returns true when assistantLangChain is true', () => {
it('returns true when just assistantLangChain is true', () => {
const result = hasParsableResponse({
alerts: false,
assistantLangChain: true,
ragOnAlerts: false,
});

expect(result).toBe(true);
});

it('returns true when ragOnAlerts is true and alerts is true', () => {
it('returns true when just alerts is true', () => {
const result = hasParsableResponse({
alerts: true,
assistantLangChain: false,
ragOnAlerts: true,
});

expect(result).toBe(true);
});

it('returns false when assistantLangChain, ragOnAlerts, and alerts are all false', () => {
it('returns true when both assistantLangChain and alerts are true', () => {
const result = hasParsableResponse({
alerts: true,
assistantLangChain: true,
});

expect(result).toBe(true);
});

it('returns false when both assistantLangChain and alerts are false', () => {
const result = hasParsableResponse({
alerts: false,
assistantLangChain: false,
ragOnAlerts: false,
});

expect(result).toBe(false);
Expand Down
12 changes: 3 additions & 9 deletions x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,13 @@ export const getOptionalRequestParams = ({
alertsIndexPattern,
allow,
allowReplacement,
ragOnAlerts,
replacements,
size,
}: {
alerts: boolean;
alertsIndexPattern?: string;
allow?: string[];
allowReplacement?: string[];
ragOnAlerts: boolean;
replacements?: Record<string, string>;
size?: number;
}): OptionalRequestParams => {
Expand All @@ -119,10 +117,8 @@ export const getOptionalRequestParams = ({
const optionalReplacements = replacements ? { replacements } : undefined;
const optionalSize = size ? { size } : undefined;

if (
!ragOnAlerts || // the feature flag must be enabled
!alerts // the settings toggle must also be enabled
) {
// the settings toggle must be enabled:
if (!alerts) {
return {}; // don't send any optional params
}

Expand All @@ -138,9 +134,7 @@ export const getOptionalRequestParams = ({
export const hasParsableResponse = ({
alerts,
assistantLangChain,
ragOnAlerts,
}: {
alerts: boolean;
assistantLangChain: boolean;
ragOnAlerts: boolean;
}): boolean => assistantLangChain || (ragOnAlerts && alerts);
}): boolean => assistantLangChain || alerts;
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const useSendMessages = (): UseSendMessages => {
assistantStreamingEnabled,
defaultAllow,
defaultAllowReplacement,
ragOnAlerts,
knowledgeBase,
} = useAssistantContext();
const [isLoading, setIsLoading] = useState(false);
Expand All @@ -56,7 +55,6 @@ export const useSendMessages = (): UseSendMessages => {
assistantLangChain: knowledgeBase.assistantLangChain,
assistantStreamingEnabled,
http,
ragOnAlerts, // feature flag
replacements,
messages,
size: knowledgeBase.latestAlerts,
Expand All @@ -74,7 +72,6 @@ export const useSendMessages = (): UseSendMessages => {
knowledgeBase.alerts,
knowledgeBase.assistantLangChain,
knowledgeBase.latestAlerts,
ragOnAlerts,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export interface AssistantProviderProps {
getInitialConversations: () => Record<string, Conversation>;
modelEvaluatorEnabled?: boolean;
nameSpace?: string;
ragOnAlerts?: boolean;
setConversations: React.Dispatch<React.SetStateAction<Record<string, Conversation>>>;
setDefaultAllow: React.Dispatch<React.SetStateAction<string[]>>;
setDefaultAllowReplacement: React.Dispatch<React.SetStateAction<string[]>>;
Expand Down Expand Up @@ -141,7 +140,6 @@ export interface UseAssistantContext {
promptContexts: Record<string, PromptContext>;
modelEvaluatorEnabled: boolean;
nameSpace: string;
ragOnAlerts: boolean;
registerPromptContext: RegisterPromptContext;
selectedSettingsTab: SettingsTabs;
setAllQuickPrompts: React.Dispatch<React.SetStateAction<QuickPrompt[] | undefined>>;
Expand Down Expand Up @@ -183,7 +181,6 @@ export const AssistantProvider: React.FC<AssistantProviderProps> = ({
getInitialConversations,
modelEvaluatorEnabled = false,
nameSpace = DEFAULT_ASSISTANT_NAMESPACE,
ragOnAlerts = false,
setConversations,
setDefaultAllow,
setDefaultAllowReplacement,
Expand Down Expand Up @@ -328,7 +325,6 @@ export const AssistantProvider: React.FC<AssistantProviderProps> = ({
modelEvaluatorEnabled,
promptContexts,
nameSpace,
ragOnAlerts,
registerPromptContext,
selectedSettingsTab,
setAllQuickPrompts: setLocalStorageQuickPrompts,
Expand Down Expand Up @@ -374,7 +370,6 @@ export const AssistantProvider: React.FC<AssistantProviderProps> = ({
nameSpace,
onConversationsUpdated,
promptContexts,
ragOnAlerts,
registerPromptContext,
selectedSettingsTab,
setDefaultAllow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const mockUseAssistantContext = {
prepend: jest.fn(),
},
},
ragOnAlerts: true,
setAllSystemPrompts: jest.fn(),
setConversations: jest.fn(),
};
Expand Down Expand Up @@ -210,7 +209,7 @@ describe('Knowledge base settings', () => {
expect(queryByTestId('knowledgeBaseActionButton')).not.toBeInTheDocument();
});

it('renders the alerts settings when ragOnAlerts is true', () => {
it('renders the alerts settings', () => {
const { getByTestId } = render(
<TestProviders>
<KnowledgeBaseSettings {...defaultProps} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface Props {
*/
export const KnowledgeBaseSettings: React.FC<Props> = React.memo(
({ knowledgeBase, setUpdatedKnowledgeBaseSettings }) => {
const { http, ragOnAlerts } = useAssistantContext();
const { http } = useAssistantContext();
const {
data: kbStatus,
isLoading,
Expand Down Expand Up @@ -303,12 +303,10 @@ export const KnowledgeBaseSettings: React.FC<Props> = React.memo(

<EuiSpacer size="s" />

{ragOnAlerts && (
<AlertsSettings
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={setUpdatedKnowledgeBaseSettings}
/>
)}
<AlertsSettings
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={setUpdatedKnowledgeBaseSettings}
/>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@ export const ASK_QUESTIONS_ABOUT = i18n.translate(
}
);

export const LATEST_AND_RISKIEST_OPEN_ALERTS = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettings.latestAndRiskiestOpenAlertsLabel',
{
defaultMessage: 'latest and riskiest open and acknowledged alerts in your environment.',
}
);
export const LATEST_AND_RISKIEST_OPEN_ALERTS = (alertsCount: number) =>
i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettings.latestAndRiskiestOpenAlertsLabel',
{
defaultMessage:
'Send AI Assistant information about your {alertsCount} newest and riskiest open or acknowledged alerts.',
values: { alertsCount },
}
);

export const YOUR_ANONYMIZATION_SETTINGS = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettings.yourAnonymizationSettingsLabel',
{
defaultMessage: 'Your Anonymization settings will be applied to the alerts.',
defaultMessage: 'Your anonymization settings will apply to these alerts.',
}
);

export const SELECT_FEWER_ALERTS = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettings.selectFewerAlertsLabel',
{
defaultMessage:
"Select fewer alerts if the model's maximum context length is frequently exceeded.",
defaultMessage: "Send fewer alerts if the model's context window is too small.",
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ export const allowedExperimentalValues = Object.freeze({
*/
assistantModelEvaluation: false,

/**
* Enables Retrieval Augmented Generation (RAG) on Alerts in the assistant
*/
assistantRagOnAlerts: false,

/*
* Enables the new user details flyout displayed on the Alerts page and timeline.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const AssistantProvider: React.FC = ({ children }) => {

const { signalIndexName } = useSignalIndex();
const alertsIndexPattern = signalIndexName ?? undefined;
const ragOnAlerts = useIsExperimentalFeatureEnabled('assistantRagOnAlerts');
const toasts = useAppToasts() as unknown as IToasts; // useAppToasts is the current, non-deprecated method of getting the toasts service in the Security Solution, but it doesn't return the IToasts interface (defined by core)

return (
Expand All @@ -82,7 +81,6 @@ export const AssistantProvider: React.FC = ({ children }) => {
assistantStreamingEnabled={assistantStreamingEnabled}
modelEvaluatorEnabled={isModelEvaluationEnabled}
nameSpace={nameSpace}
ragOnAlerts={ragOnAlerts}
setConversations={setConversations}
setDefaultAllow={setDefaultAllow}
setDefaultAllowReplacement={setDefaultAllowReplacement}
Expand Down
Loading