Skip to content

Conversation

@sorenlouv
Copy link
Member

@sorenlouv sorenlouv commented Jun 18, 2025

Closes #224084

This improves the knowledge base retrieval by rewriting the user prompt before querying Elasticsearch. The LLM is asked to rewrite the prompt taking into account screen description and conversation history. We then use the LLM-generated prompt as the search query.

Other changes:

  • Remove screenContext from being used verbatim as ES query. This was causing noise and leading to bad results
  • Take conversation history into account: with query rewriting, the LLM has access to the entire conversation history. This context will be embedded into the generated prompt along side screen context

@sorenlouv sorenlouv added backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Jun 18, 2025
@sorenlouv sorenlouv changed the title [Obs AI Assistant] Add HyDE query rewriting [Obs AI Assistant] Add query rewriting Jun 19, 2025
@sorenlouv sorenlouv marked this pull request as ready for review June 19, 2025 12:06
@sorenlouv sorenlouv requested a review from a team as a code owner June 19, 2025 12:06
@botelastic botelastic bot added ci:project-deploy-observability Create an Observability project Team:Obs AI Assistant Observability AI Assistant labels Jun 19, 2025
@elasticmachine
Copy link
Contributor

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

@github-actions
Copy link
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!)

@sorenlouv sorenlouv force-pushed the add-query-rewriting branch from 54036a7 to 207a1bc Compare June 19, 2025 12:29
@sorenlouv sorenlouv marked this pull request as draft June 19, 2025 13:16
@sorenlouv sorenlouv marked this pull request as ready for review June 23, 2025 09:16
@sorenlouv sorenlouv requested a review from a team as a code owner June 23, 2025 09:16
@sorenlouv sorenlouv requested a review from a team as a code owner June 23, 2025 13:01
? [`--xpack.fleet.registryUrl=http://localhost:${dockerRegistryPort}`]
: []),
// @ts-expect-error
...(options?.kbnTestServer?.serverArgs ?? []),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you doing this given the error we throw on line 44 if options.kbnServerArgs is set?

I think you can customize the kbnServer args in specific configs but not in this shared one if I remember correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey!

I want to enable debug logging in Kibana for the Obs AI Assistant plugin when running the Obs AI Assistant tests:
https://github.com/sorenlouv/kibana/blob/add-query-rewriting/x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.ai_assistant.stateful.config.ts

What's the right way to do this?

Why are you doing this given the error we throw on line 44 if options.kbnServerArgs is set?

btw yes, we throw an error for options.kbnServerArgs but not for options.kbnTestServer afaict.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure, maybe someone from @elastic/appex-qa has more context on why we don't allow sending options.kbnServerArgs and if this usage of adding options?.kbnTestServer?.serverArgs is fine.

maybe @dmlemeshko

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.

Added a few comments.
I tested recalling and scoring in a normal conversation, contextual insights and via the evaluation framework scenario.
LGTM

Copy link
Member

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

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

extended logger change LGTM

@sorenlouv sorenlouv enabled auto-merge (squash) June 24, 2025 14:24
@elasticmachine
Copy link
Contributor

elasticmachine commented Jun 24, 2025

💛 Build succeeded, but was flaky

  • Buildkite Build
  • Commit: f49da1f
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-224498-f49da1f950e0

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #49 / Stateful Observability - Deployment-agnostic API integration tests SyntheticsAPITests SyntheticsEnablement [PUT] /internal/uptime/service/enablement auto re-enables api key when invalidated

Metrics [docs]

✅ unchanged

History

@sorenlouv sorenlouv merged commit da41b47 into elastic:main Jun 24, 2025
11 checks passed
@kibanamachine
Copy link
Contributor

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 224498

Questions ?

Please refer to the Backport tool documentation

@sorenlouv sorenlouv deleted the add-query-rewriting branch June 24, 2025 16:35
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request Jun 25, 2025
Closes elastic#224084

This improves the knowledge base retrieval by rewriting the user prompt
before querying Elasticsearch. The LLM is asked to rewrite the prompt
taking into account screen description and conversation history. We then
use the LLM-generated prompt as the search query.

Other changes:

- Remove `screenContext` from being used verbatim as ES query. This was
causing noise and leading to bad results
- Take conversation history into account: with query rewriting, the LLM
has access to the entire conversation history. This context will be
embedded into the generated prompt along side screen context

---------

Co-authored-by: Viduni Wickramarachchi <[email protected]>
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 26, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 224498 locally
cc: @sorenlouv

@viduni94
Copy link
Contributor

💚 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

viduni94 pushed a commit to viduni94/kibana that referenced this pull request Jun 26, 2025
Closes elastic#224084

This improves the knowledge base retrieval by rewriting the user prompt
before querying Elasticsearch. The LLM is asked to rewrite the prompt
taking into account screen description and conversation history. We then
use the LLM-generated prompt as the search query.

Other changes:

- Remove `screenContext` from being used verbatim as ES query. This was
causing noise and leading to bad results
- Take conversation history into account: with query rewriting, the LLM
has access to the entire conversation history. This context will be
embedded into the generated prompt along side screen context

---------

Co-authored-by: Viduni Wickramarachchi <[email protected]>
(cherry picked from commit da41b47)

# Conflicts:
#	x-pack/solutions/observability/plugins/observability_ai_assistant_app/scripts/evaluation/scenarios/kb/index.spec.ts
#	x-pack/test/api_integration/deployment_agnostic/apis/observability/ai_assistant/complete/functions/execute_query.spec.ts
#	x-pack/test/api_integration/deployment_agnostic/apis/observability/ai_assistant/complete/functions/get_alerts_dataset_info.spec.ts
#	x-pack/test/api_integration/deployment_agnostic/apis/observability/ai_assistant/complete/functions/get_dataset_info.spec.ts
#	x-pack/test/api_integration/deployment_agnostic/apis/observability/ai_assistant/complete/functions/retrieve_elastic_doc.spec.ts
#	x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.ai_assistant.stateful.config.ts
viduni94 added a commit that referenced this pull request Jun 27, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [[Obs AI Assistant] Add query rewriting
(#224498)](#224498)

<!--- Backport version: 10.0.1 -->

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-24T16:19:15Z","message":"[Obs
AI Assistant] Add query rewriting (#224498)\n\nCloses
https://github.com/elastic/kibana/issues/224084\n\nThis improves the
knowledge base retrieval by rewriting the user prompt\nbefore querying
Elasticsearch. The LLM is asked to rewrite the prompt\ntaking into
account screen description and conversation history. We then\nuse the
LLM-generated prompt as the search query.\n\nOther changes:\n\n- Remove
`screenContext` from being used verbatim as ES query. This was\ncausing
noise and leading to bad results\n- Take conversation history into
account: with query rewriting, the LLM\nhas access to the entire
conversation history. This context will be\nembedded into the generated
prompt along side screen context\n\n---------\n\nCo-authored-by: Viduni
Wickramarachchi
<[email protected]>","sha":"da41b47f1d2b297449377722ea0804880f0588ff","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport
missing","Team:Obs AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0"],"title":"[Obs
AI Assistant] Add query
rewriting","number":224498,"url":"https://github.com/elastic/kibana/pull/224498","mergeCommit":{"message":"[Obs
AI Assistant] Add query rewriting (#224498)\n\nCloses
https://github.com/elastic/kibana/issues/224084\n\nThis improves the
knowledge base retrieval by rewriting the user prompt\nbefore querying
Elasticsearch. The LLM is asked to rewrite the prompt\ntaking into
account screen description and conversation history. We then\nuse the
LLM-generated prompt as the search query.\n\nOther changes:\n\n- Remove
`screenContext` from being used verbatim as ES query. This was\ncausing
noise and leading to bad results\n- Take conversation history into
account: with query rewriting, the LLM\nhas access to the entire
conversation history. This context will be\nembedded into the generated
prompt along side screen context\n\n---------\n\nCo-authored-by: Viduni
Wickramarachchi
<[email protected]>","sha":"da41b47f1d2b297449377722ea0804880f0588ff"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/224498","number":224498,"mergeCommit":{"message":"[Obs
AI Assistant] Add query rewriting (#224498)\n\nCloses
https://github.com/elastic/kibana/issues/224084\n\nThis improves the
knowledge base retrieval by rewriting the user prompt\nbefore querying
Elasticsearch. The LLM is asked to rewrite the prompt\ntaking into
account screen description and conversation history. We then\nuse the
LLM-generated prompt as the search query.\n\nOther changes:\n\n- Remove
`screenContext` from being used verbatim as ES query. This was\ncausing
noise and leading to bad results\n- Take conversation history into
account: with query rewriting, the LLM\nhas access to the entire
conversation history. This context will be\nembedded into the generated
prompt along side screen context\n\n---------\n\nCo-authored-by: Viduni
Wickramarachchi
<[email protected]>","sha":"da41b47f1d2b297449377722ea0804880f0588ff"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Søren Louv-Jansen <[email protected]>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 27, 2025
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 ci:project-deploy-observability Create an Observability project release_note:fix Team:Obs AI Assistant Observability AI Assistant v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Obs AI Assistant] HyDE-style query rewriting

6 participants