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

[Security Assistant] Conversation pagination refactor #211831

Merged
merged 100 commits into from
Mar 3, 2025

Conversation

stephmilovic
Copy link
Contributor

@stephmilovic stephmilovic commented Feb 19, 2025

Summary

This pull request introduces several improvements and optimizations to the assistant UI and backend logic to address performance issues, particularly Out of Memory (OOM) errors, and enhance the overall user experience. Key updates include pagination support, reduced data fetches, and cleaner logic for conversation management.

Key Changes:

  • Pagination for Conversations: Refactors the assistant UI to support pagination, reducing memory usage by loading only a subset of conversations at a time. As the user scrolls, more conversations are loaded
  • Group conversations by date: Categorizes the chat history based on updatedAt date of the conversation.
  • Optimized Fetching: Updates the fetch logic to prevent loading message data for every conversation request, making requests smaller and more efficient.
  • Conversation Creation Logic: Removes default conversations and ensures a conversation is not created until the first message is sent. This applies to various triggers such as new chats, attack discovery, alert/event invocations, and data quality dashboard, and detection rule actions.
  • Assistant Settings Refactor: Updates the logic in the assistant settings to align with the new pagination structure.
  • Content-Specific Hooks: Eliminates unnecessary usage of useSettingsUpdater and replaces it with more appropriate hooks like useSystemPromptUpdater and useConversationsUpdater, streamlining state management.
  • Unique Conversations for Triggered Actions: Creates a unique conversation for each new chat initiated from various sources, including alerts, events, DQD, the rules table toolbar, rule status failed callouts, and rule creation forms. This ensures more accurate conversation tracking and better user interaction.

Issue Links:

  • Resolves #192714
  • Resolves multiple SDH related to OOM errors.

Additional Notes:

  • This work aims to mitigate performance bottlenecks caused by fetching excessive data and creating unnecessary conversations.
  • Pagination is implemented to improve the scalability of the assistant UI, ensuring it can handle larger datasets more effectively.

Testing

  • This PR needs lots of manual testing. Perform all of the AI Assistant Settings actions, create conversations, delete conversations, invoke conversations from all the different possible invocation areas.
  • Use the create conversation script to create conversations over wide date range to ensure both pagination and group conversations by date are working. Note that you will be unable to update these conversations from AI Assistant Settings due to the user profile_uid bug.
    • node x-pack/solutions/security/plugins/elastic_assistant/scripts/create_conversations --count 150

@stephmilovic stephmilovic added release_note:fix Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Security Generative AI Security Generative AI v9.1.0 v8.19.0 labels Feb 19, 2025
@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked out, tested locally, and code reviewed -- LGTM!

Thanks for this giant effort and refactoring @stephmilovic! Really appreciate you taking the time to pair and go over the changes and last couple issues we found. The code base is in a much better spot with all of your changes here! 🙂 🚀

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
automaticImport 732 723 -9
securitySolution 7106 7099 -7
total -16

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/elastic-assistant 144 135 -9

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
automaticImport 1.1MB 1.1MB -154.0B
securitySolution 8.9MB 8.9MB -9.2KB
total -9.3KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 85.9KB 85.6KB -364.0B
Unknown metric groups

API count

id before after diff
@kbn/elastic-assistant 172 164 -8

ESLint disabled line counts

id before after diff
@kbn/elastic-assistant 14 13 -1

Total ESLint disabled count

id before after diff
@kbn/elastic-assistant 15 14 -1

History

cc @stephmilovic

@stephmilovic stephmilovic merged commit 095fc22 into elastic:main Mar 3, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/13640012888

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts

You might need to backport the following PRs to 8.x:
- [AI Assistant] Fixed DataClient find method to pass fields param to esClient.msearch (#212465)
- [EUI Visual Refresh][Security Gen AI] Add support for borealis theme (#202393)

Manual backport

To create the backport manually run:

node scripts/backport --pr 211831

Questions ?

Please refer to the Backport tool documentation

stephmilovic added a commit to stephmilovic/kibana that referenced this pull request Mar 3, 2025
(cherry picked from commit 095fc22)

# Conflicts:
#	x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/assistant_header/index.tsx
#	x-pack/platform/packages/shared/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.tsx
#	x-pack/platform/packages/shared/kbn-elastic-assistant/impl/data_anonymization/settings/anonymization_settings_management/index.tsx
#	x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_data_clients/find.ts
@stephmilovic
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

stephmilovic added a commit that referenced this pull request Mar 4, 2025
…#212997)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Assistant] Conversation pagination refactor
(#211831)](#211831)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"stephanie.milovic@elastic.co"},"sourceCommit":{"committedDate":"2025-03-03T20:41:20Z","message":"[Security
Assistant] Conversation pagination refactor
(#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v9.1.0","v8.19.0"],"title":"[Security Assistant]
Conversation pagination
refactor","number":211831,"url":"https://github.com/elastic/kibana/pull/211831","mergeCommit":{"message":"[Security
Assistant] Conversation pagination refactor
(#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211831","number":211831,"mergeCommit":{"message":"[Security
Assistant] Conversation pagination refactor
(#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Mar 4, 2025
…211831) (elastic#212997)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Assistant] Conversation pagination refactor
(elastic#211831)](elastic#211831)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"stephanie.milovic@elastic.co"},"sourceCommit":{"committedDate":"2025-03-03T20:41:20Z","message":"[Security
Assistant] Conversation pagination refactor
(elastic#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v9.1.0","v8.19.0"],"title":"[Security Assistant]
Conversation pagination
refactor","number":211831,"url":"https://github.com/elastic/kibana/pull/211831","mergeCommit":{"message":"[Security
Assistant] Conversation pagination refactor
(elastic#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211831","number":211831,"mergeCommit":{"message":"[Security
Assistant] Conversation pagination refactor
(elastic#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels release_note:fix Team:Security Generative AI Security Generative AI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Assistant] - Conversation pagination, default conversations, and new conversation creation
8 participants