Skip to content

[Obs AI Assistant] Use update-by-query for semantic_text migration - #220255

Merged
sorenlouv merged 5 commits into
elastic:mainfrom
sorenlouv:move-semantic-text-migration-to-update-by-query
May 8, 2025
Merged

sorenlouv merged 5 commits into
elastic:mainfrom
sorenlouv:move-semantic-text-migration-to-update-by-query

Conversation

@sorenlouv

@sorenlouv sorenlouv commented May 6, 2025 •

Copy link
Copy Markdown
Contributor

Closes: #220339

Background
The semantic_text migration will migrate content from text field to semantic_text field. It does so with a recursive function that continuously retrieves knowledge base entries if they do not contain semantic_text and updates them accordingly.

Problem
It is possible to save empty knowledge base entries (#220342) where text and semantic_text will be empty. Doing this will cause the migration script to run indefinitely leading to OOM on the affected clusters.

Solution

Rewrite the recursive function to updateByQuery where Elasticsearch will paginate through entries and updating them.

Workarounds for clusters that cannot / won't upgrade

Temporary workaround is to delete empty knowledge base entries:

POST .kibana-observability-ai-assistant-kb/_delete_by_query
{
  "query": {
    "bool": {
      "must": [{ "exists": { "field": "text" }}],
      "must_not": [ { "wildcard": { "text": "*" } }
      ]
    }
  }
}

If you want to perform a dry run (find offending documents without deleting them) run this:

GET .kibana-observability-ai-assistant-kb/_search
{
  "query": {
    "bool": {
      "must": [{ "exists": { "field": "text" }}],
      "must_not": [ { "wildcard": { "text": "*" } }
      ]
    }
  }
}

@sorenlouv
sorenlouv marked this pull request as ready for review May 7, 2025 09:03
@sorenlouv
sorenlouv requested a review from a team May 7, 2025 09:03
@elasticmachine

Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant)

@github-actions

github-actions Bot commented May 7, 2025

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@viduni94 viduni94 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've verified that the inifnite loop doesn't happen anymore.

Steps I tested:

  1. Checkout main
  2. Create a user instructions
  3. Clear the user instruction by clearing the text
  4. Re-start kibana
  5. Noticed the infinite loop

Next:

  1. Checked out this PR
  2. Re-started Kibana
  3. There was no infinite loop in the migration ✅

However, I did notice a log related to a lock can't be released. Made a comment about it.

@sorenlouv

sorenlouv commented May 8, 2025 •

Copy link
Copy Markdown
Contributor Author

I've verified that the inifnite loop doesn't happen anymore.

Thank you so much for manually testing this flow. Much appreciated!

However, I did notice a log related to a lock can't be released. Made a comment about it.

Hmm, that's a little concerning. Thanks for letting me know. Looking into it.
Update: Really good catch! This was indeed a bug in the LockManager. I've opened a separate PR that fixes that: #220476

Søren Louv-Jansen added 2 commits May 8, 2025 10:59
@elasticmachine

elasticmachine commented May 8, 2025 •

Copy link
Copy Markdown
Contributor

💚 Build Succeeded

  • Buildkite Build
  • Commit: 4f7406c
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-220255-4f7406c30407

Metrics [docs]

✅ unchanged

History

@viduni94 viduni94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@viduni94

viduni94 commented May 8, 2025

Copy link
Copy Markdown
Contributor

Thank you so much for manually testing this flow. Much appreciated!

Anytime :)

I've opened a separate PR that fixes that: #220476

Awesome, thanks @sorenlouv

@sorenlouv
sorenlouv merged commit 96d1692 into elastic:main May 8, 2025
@sorenlouv
sorenlouv deleted the move-semantic-text-migration-to-update-by-query branch May 8, 2025 21:52
@kibanamachine

Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.17, 8.18, 8.19, 9.0

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

@kibanamachine

Copy link
Copy Markdown
Contributor

💔 All backports failed

Status Branch Result
❌ 8.17 Backport failed because of merge conflicts
❌ 8.18 Backport failed because of merge conflicts
❌ 8.19 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.19:
- [Obs AI Assistant] Make API tests more resilient (#220503)
❌ 9.0 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 220255

Questions ?

Please refer to the Backport tool documentation

@sorenlouv

Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
✅ 8.19

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

Questions ?

Please refer to the Backport tool documentation

@sorenlouv

Copy link
Copy Markdown
Contributor Author

💔 Some backports could not be created

Status Branch Result
❌ 9.0 An unhandled error occurred. Please see the logs for details
❌ 8.18 An unhandled error occurred. Please see the logs for details
✅ 8.17

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 220255

Questions ?

Please refer to the Backport tool documentation

@sorenlouv

Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
✅ 8.18

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

Questions ?

Please refer to the Backport tool documentation

@sorenlouv

Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
✅ 9.0

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

Questions ?

Please refer to the Backport tool documentation

@kibanamachine

Copy link
Copy Markdown
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @sorenlouv

1 similar comment
@kibanamachine

Copy link
Copy Markdown
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @sorenlouv

sorenlouv pushed a commit that referenced this pull request May 14, 2025
…tion (#220255) (#220642)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Obs AI Assistant] Use update-by-query for semantic_text migration
(#220255)](#220255)

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

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"soren.louv@elastic.co"},"sourceCommit":{"committedDate":"2025-05-08T21:52:33Z","message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v8.17.7","v8.18.2","v9.0.2"],"title":"[Obs
AI Assistant] Use update-by-query for semantic_text
migration","number":220255,"url":"https://github.com/elastic/kibana/pull/220255","mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220255","number":220255,"mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/220640","number":220640,"state":"OPEN"},{"branch":"8.17","label":"v8.17.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
sorenlouv pushed a commit that referenced this pull request May 14, 2025
…tion (#220255) (#220646)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[Obs AI Assistant] Use update-by-query for semantic_text migration
(#220255)](#220255)

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

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"soren.louv@elastic.co"},"sourceCommit":{"committedDate":"2025-05-08T21:52:33Z","message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v8.17.7","v8.18.2","v9.0.2"],"title":"[Obs
AI Assistant] Use update-by-query for semantic_text
migration","number":220255,"url":"https://github.com/elastic/kibana/pull/220255","mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},"sourceBranch":"main","suggestedTargetBranches":["8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220255","number":220255,"mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/220640","number":220640,"state":"OPEN"},{"branch":"8.17","label":"v8.17.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/220642","number":220642,"state":"OPEN"},{"branch":"8.18","label":"v8.18.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
sorenlouv pushed a commit that referenced this pull request May 14, 2025
…tion (#220255) (#220640)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Obs AI Assistant] Use update-by-query for semantic_text migration
(#220255)](#220255)

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

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"soren.louv@elastic.co"},"sourceCommit":{"committedDate":"2025-05-08T21:52:33Z","message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v8.17.7","v8.18.2","v9.0.2"],"title":"[Obs
AI Assistant] Use update-by-query for semantic_text
migration","number":220255,"url":"https://github.com/elastic/kibana/pull/220255","mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","8.17","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220255","number":220255,"mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
sorenlouv pushed a commit that referenced this pull request May 14, 2025
…ion (#220255) (#220647)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Obs AI Assistant] Use update-by-query for semantic_text migration
(#220255)](#220255)

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

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"soren.louv@elastic.co"},"sourceCommit":{"committedDate":"2025-05-08T21:52:33Z","message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v8.17.7","v8.18.2","v9.0.2"],"title":"[Obs
AI Assistant] Use update-by-query for semantic_text
migration","number":220255,"url":"https://github.com/elastic/kibana/pull/220255","mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},"sourceBranch":"main","suggestedTargetBranches":["9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220255","number":220255,"mergeCommit":{"message":"[Obs
AI Assistant] Use update-by-query for semantic_text migration
(#220255)\n\nCloses:
https://github.com/elastic/kibana/issues/220339\n\n**Background**\nThe
`semantic_text` migration will migrate content from `text` field
to\n`semantic_text` field. It does so with a recursive function
that\ncontinuously retrieves knowledge base entries if they do not
contain\n`semantic_text` and updates them
accordingly.\n\n**Problem**\nIt is possible to save empty knowledge base
entries\n(#220342) where `text`
and\n`semantic_text` will be empty. Doing this will cause the
migration\nscript to run indefinitely leading to OOM on the affected
clusters.\n\n## Workarounds for clusters that cannot / won't
upgrade\n\nTemporary workaround is to delete empty knowledge base
entries:\n\n```jsonc\nPOST
.kibana-observability-ai-assistant-kb/_delete_by_query\n{\n \"query\":
{\n \"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```\n\nIf you want to perform a dry run (find offending documents
without\ndeleting them) run this:\n```jsonc\nGET
.kibana-observability-ai-assistant-kb/_search\n{\n \"query\": {\n
\"bool\": {\n \"must\": [{ \"exists\": { \"field\": \"text\" }}],\n
\"must_not\": [ { \"wildcard\": { \"text\": \"*\" } }\n ]\n }\n
}\n}\n```","sha":"96d1692ae20172ea3d8a5f7062c55c10d38ed9a2"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/220640","number":220640,"state":"OPEN"},{"branch":"8.17","label":"v8.17.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/220642","number":220642,"state":"OPEN"},{"branch":"8.18","label":"v8.18.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/220646","number":220646,"state":"OPEN"},{"branch":"9.0","label":"v9.0.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 14, 2025
@sorenlouv

Copy link
Copy Markdown
Contributor Author

Follow-up to avoid excessive error messages: #221152

sorenlouv pushed a commit that referenced this pull request May 28, 2025
## Background
The semantic text migration was added in 8.17 along with the move to
semantic_text field (#186499).

## Suggestion

We should remove the semantic_text migration starting in 9.1. Reasons:

- The migration has recently caused severe disruption on a number of
clusters (#220255).
- The migration may no longer be needed. Users are required to upgrade
Elasticsearch to 8.18 in order to update to 9.0, or 8.19 to upgrade to
9.1. This could mean that users are guaranteed to have run the migration
previously, when upgrading Kibana to 9.1 (needs to be double checked
with Kibana folks)

---------

Co-authored-by: Viduni Wickramarachchi <viduni.ushanka@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
…lastic#220255)

Closes: elastic#220339

**Background**
The `semantic_text` migration will migrate content from `text` field to
`semantic_text` field. It does so with a recursive function that
continuously retrieves knowledge base entries if they do not contain
`semantic_text` and updates them accordingly.

**Problem**
It is possible to save empty knowledge base entries
(elastic#220342) where `text` and
`semantic_text` will be empty. Doing this will cause the migration
script to run indefinitely leading to OOM on the affected clusters.

## Workarounds for clusters that cannot / won't upgrade

Temporary workaround is to delete empty knowledge base entries:

```jsonc
POST .kibana-observability-ai-assistant-kb/_delete_by_query
{
  "query": {
    "bool": {
      "must": [{ "exists": { "field": "text" }}],
      "must_not": [ { "wildcard": { "text": "*" } }
      ]
    }
  }
}
```

If you want to perform a dry run (find offending documents without
deleting them) run this:
```jsonc
GET .kibana-observability-ai-assistant-kb/_search
{
  "query": {
    "bool": {
      "must": [{ "exists": { "field": "text" }}],
      "must_not": [ { "wildcard": { "text": "*" } }
      ]
    }
  }
}
```
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
## Background
The semantic text migration was added in 8.17 along with the move to
semantic_text field (elastic#186499).

## Suggestion

We should remove the semantic_text migration starting in 9.1. Reasons:

- The migration has recently caused severe disruption on a number of
clusters (elastic#220255).
- The migration may no longer be needed. Users are required to upgrade
Elasticsearch to 8.18 in order to update to 9.0, or 8.19 to upgrade to
9.1. This could mean that users are guaranteed to have run the migration
previously, when upgrading Kibana to 9.1 (needs to be double checked
with Kibana folks)

---------

Co-authored-by: Viduni Wickramarachchi <viduni.ushanka@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
qn895 pushed a commit to qn895/kibana that referenced this pull request Jun 3, 2025
…lastic#220255)

Closes: elastic#220339

**Background**
The `semantic_text` migration will migrate content from `text` field to
`semantic_text` field. It does so with a recursive function that
continuously retrieves knowledge base entries if they do not contain
`semantic_text` and updates them accordingly.

**Problem**
It is possible to save empty knowledge base entries
(elastic#220342) where `text` and
`semantic_text` will be empty. Doing this will cause the migration
script to run indefinitely leading to OOM on the affected clusters.

## Workarounds for clusters that cannot / won't upgrade

Temporary workaround is to delete empty knowledge base entries:

```jsonc
POST .kibana-observability-ai-assistant-kb/_delete_by_query
{
  "query": {
    "bool": {
      "must": [{ "exists": { "field": "text" }}],
      "must_not": [ { "wildcard": { "text": "*" } }
      ]
    }
  }
}
```

If you want to perform a dry run (find offending documents without
deleting them) run this:
```jsonc
GET .kibana-observability-ai-assistant-kb/_search
{
  "query": {
    "bool": {
      "must": [{ "exists": { "field": "text" }}],
      "must_not": [ { "wildcard": { "text": "*" } }
      ]
    }
  }
}
```
zacharyparikh pushed a commit to zacharyparikh/kibana that referenced this pull request Jun 4, 2025
## Background
The semantic text migration was added in 8.17 along with the move to
semantic_text field (elastic#186499).

## Suggestion

We should remove the semantic_text migration starting in 9.1. Reasons:

- The migration has recently caused severe disruption on a number of
clusters (elastic#220255).
- The migration may no longer be needed. Users are required to upgrade
Elasticsearch to 8.18 in order to update to 9.0, or 8.19 to upgrade to
9.1. This could mean that users are guaranteed to have run the migration
previously, when upgrading Kibana to 9.1 (needs to be double checked
with Kibana folks)

---------

Co-authored-by: Viduni Wickramarachchi <viduni.ushanka@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Obs AI Assistant] semantic_text migration may run indefinitely leading to OOM

4 participants