Skip to content

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

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

[Obs AI Assistant] Use update-by-query for semantic_text migration#220255
sorenlouv merged 5 commits intoelastic:mainfrom
sorenlouv:move-semantic-text-migration-to-update-by-query

Conversation

@sorenlouv
Copy link
Member

@sorenlouv sorenlouv commented May 6, 2025

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 as a code owner May 7, 2025 09:03
@botelastic botelastic bot added ci:project-deploy-observability Create an Observability project Team:Obs AI Assistant Observability AI Assistant labels May 7, 2025
@elasticmachine
Copy link
Contributor

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

@github-actions
Copy link
Contributor

github-actions bot commented May 7, 2025

🤖 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!)

Copy link
Contributor

@viduni94 viduni94 left a comment

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
Copy link
Member Author

sorenlouv commented May 8, 2025

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

@elasticmachine
Copy link
Contributor

elasticmachine commented May 8, 2025

💚 Build Succeeded

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

Metrics [docs]

✅ unchanged

History

Copy link
Contributor

@viduni94 viduni94 left a comment

Choose a reason for hiding this comment

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

LGTM

@viduni94
Copy link
Contributor

viduni94 commented May 8, 2025

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
10 checks passed
@sorenlouv sorenlouv deleted the move-semantic-text-migration-to-update-by-query branch May 8, 2025 21:52
@kibanamachine
Copy link
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
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 added a commit to sorenlouv/kibana that referenced this pull request May 9, 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": "*" } }
      ]
    }
  }
}
```

(cherry picked from commit 96d1692)
@sorenlouv
Copy link
Member 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
Member 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 added a commit to sorenlouv/kibana that referenced this pull request May 9, 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.

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": "*" } }
      ]
    }
  }
}
```

(cherry picked from commit 96d1692)
@sorenlouv
Copy link
Member 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 added a commit to sorenlouv/kibana that referenced this pull request May 9, 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.

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": "*" } }
      ]
    }
  }
}
```

(cherry picked from commit 96d1692)
@sorenlouv
Copy link
Member 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

sorenlouv added a commit to sorenlouv/kibana that referenced this pull request May 9, 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.

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": "*" } }
      ]
    }
  }
}
```

(cherry picked from commit 96d1692)
kdelemme pushed a commit to kdelemme/kibana that referenced this pull request May 9, 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": "*" } }
      ]
    }
  }
}
```
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 12, 2025
@kibanamachine
Copy link
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
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 added 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 added 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 added 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 added 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
Member Author

Follow-up to avoid excessive error messages: #221152

sorenlouv added 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

Labels

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