[8.14] [Search] [Playground] present message when no documents are returned (#183219) (#183251)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[Search] [Playground] present message when no documents are returned
(#183219)](https://github.com/elastic/kibana/pull/183219)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Joe
McElroy","email":"joseph.mcelroy@elastic.co"},"sourceCommit":{"committedDate":"2024-05-13T09:55:54Z","message":"[Search]
[Playground] present message when no documents are returned
(#183219)\n\n## Summary\r\n\r\nHappens when index uses bm25 retrieval.
Currently if no documents are\r\nreturned, no message appears and
confusing to the user happened and how\r\nthey can improve it. With this
change, it tells them what happened and a\r\nlink to how to improve
this.\r\n\r\n<img width=\"1018\"
alt=\"image\"\r\nsrc=\"88564932-377f-4c7a-9c83-f7b3d0651a73\">\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
Liam Thompson
<32779855+leemthompo@users.noreply.github.com>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"3e743fee00195a7c074c9308941d75e28df1e5cc","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:EnterpriseSearch","v8.14.0","v8.15.0"],"title":"[Search]
[Playground] present message when no documents are
returned","number":183219,"url":"https://github.com/elastic/kibana/pull/183219","mergeCommit":{"message":"[Search]
[Playground] present message when no documents are returned
(#183219)\n\n## Summary\r\n\r\nHappens when index uses bm25 retrieval.
Currently if no documents are\r\nreturned, no message appears and
confusing to the user happened and how\r\nthey can improve it. With this
change, it tells them what happened and a\r\nlink to how to improve
this.\r\n\r\n<img width=\"1018\"
alt=\"image\"\r\nsrc=\"88564932-377f-4c7a-9c83-f7b3d0651a73\">\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
Liam Thompson
<32779855+leemthompo@users.noreply.github.com>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"3e743fee00195a7c074c9308941d75e28df1e5cc"}},"sourceBranch":"main","suggestedTargetBranches":["8.14"],"targetPullRequestStates":[{"branch":"8.14","label":"v8.14.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/183219","number":183219,"mergeCommit":{"message":"[Search]
[Playground] present message when no documents are returned
(#183219)\n\n## Summary\r\n\r\nHappens when index uses bm25 retrieval.
Currently if no documents are\r\nreturned, no message appears and
confusing to the user happened and how\r\nthey can improve it. With this
change, it tells them what happened and a\r\nlink to how to improve
this.\r\n\r\n<img width=\"1018\"
alt=\"image\"\r\nsrc=\"88564932-377f-4c7a-9c83-f7b3d0651a73\">\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
Liam Thompson
<32779855+leemthompo@users.noreply.github.com>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"3e743fee00195a7c074c9308941d75e28df1e5cc"}}]}]
BACKPORT-->

Co-authored-by: Joe McElroy <joseph.mcelroy@elastic.co>
This commit is contained in:
Kibana Machine 2024-05-13 07:14:07 -04:00 committed by GitHub
parent 57b5dc49d5
commit b75bb780be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 181 additions and 6 deletions

View file

@ -48,4 +48,21 @@ Refer to <<playground-context, Optimize context>> for more information.
Retrievers make it easier to compose and test different retrieval strategies in your search pipelines.
====
// TODO: uncomment and add to note once following page is live
//Refer to {ref}/retrievers-overview.html[documentation] for a high level overview of retrievers.
Refer to {ref}/retrievers-overview.html[documentation] for a high level overview of retrievers.
[float]
[[playground-hidden-fields]]
=== Hidden fields
The query editor shows fields which make sense for the user to search on, but not all fields in your documents are visible from the editor.
Available field types:
- Semantic fields like `sparse_vector` or `dense_vector` fields where the embeddings have been created from a inference processor
- `text` fields
Hidden Field Types:
- non `text` fields like `keyword` fields
- fields that are not indexed
- semantic fields where the embeddings have not been created from a inference processor
- nested fields

View file

@ -955,6 +955,10 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
},
playground: {
chatPlayground: `${KIBANA_DOCS}playground.html`,
retrievalOptimize: `${KIBANA_DOCS}playground-query.html#playground-query-relevance`,
retrieval: `${KIBANA_DOCS}playground-query.html`,
context: `${KIBANA_DOCS}playground-context.html`,
hiddenFields: `${KIBANA_DOCS}playground-query.html#playground-hidden-fields`,
},
});
};

View file

@ -650,6 +650,10 @@ export interface DocLinks {
};
readonly playground: {
readonly chatPlayground: string;
readonly retrievalOptimize: string;
readonly retrieval: string;
readonly context: string;
readonly hiddenFields: string;
};
}

View file

@ -9,11 +9,19 @@ import { DocLinks } from '@kbn/doc-links';
class PlaygroundDocLinks {
public chatPlayground: string = '';
public retrievalOptimize: string = '';
public retrieval: string = '';
public context: string = '';
public hiddenFields: string = '';
constructor() {}
setDocLinks(newDocLinks: DocLinks) {
this.chatPlayground = newDocLinks.playground.chatPlayground;
this.retrievalOptimize = newDocLinks.playground.retrievalOptimize;
this.retrieval = newDocLinks.playground.retrieval;
this.context = newDocLinks.playground.context;
this.hiddenFields = newDocLinks.playground.hiddenFields;
}
}

View file

@ -103,7 +103,7 @@ export const EditContextFlyout: React.FC<EditContextFlyoutProps> = ({ onClose })
defaultMessage="Context is the information you provide to the LLM, by selecting fields from your Elasticsearch documents. Optimize context for better results."
/>
<EuiLink
href={docLinks.chatPlayground}
href={docLinks.context}
target="_blank"
data-test-subj="context-optimization-documentation-link"
>

View file

@ -0,0 +1,88 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';
import { render, screen } from '@testing-library/react';
import { AssistantMessage } from './assistant_message';
import { FormProvider, useForm } from 'react-hook-form';
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
// for tooltip
jest.mock('../../hooks/use_llms_models', () => ({
useLLMsModels: () => [
{ value: 'model1', promptTokenLimit: 100 },
{ value: 'model2', promptTokenLimit: 200 },
],
}));
const MockFormProvider = ({ children }: { children: React.ReactElement }) => {
const methods = useForm({
values: {
indices: ['index1', 'index2'],
},
});
return (
<IntlProvider locale="en">
<FormProvider {...methods}>{children}</FormProvider>
</IntlProvider>
);
};
describe('AssistantMessage component', () => {
const mockMessage = {
content: 'Test content',
createdAt: new Date(),
citations: [],
retrievalDocs: [{ content: '', metadata: { _id: '1', _index: 'index', _score: 1 } }],
inputTokens: { context: 20, total: 10 },
};
it('renders message content correctly', () => {
const { getByText } = render(
<MockFormProvider>
<AssistantMessage message={mockMessage} />
</MockFormProvider>
);
expect(getByText('Test content')).toBeInTheDocument();
expect(screen.getByTestId('retrieval-docs-comment')).toBeInTheDocument();
expect(screen.getByTestId('retrieval-docs-button')).toHaveTextContent('1 document sources');
expect(screen.getByTestId('token-tooltip-button')).toHaveTextContent('10 tokens sent');
});
it('renders message content correctly with no retrieval docs', () => {
const { getByText } = render(
<MockFormProvider>
<AssistantMessage
message={{
...mockMessage,
retrievalDocs: [],
}}
/>
</MockFormProvider>
);
expect(getByText('Test content')).toBeInTheDocument();
expect(screen.queryByTestId('retrieval-docs-comment')).not.toBeInTheDocument();
expect(screen.getByTestId('retrieval-docs-comment-no-docs')).toBeInTheDocument();
});
it('renders message content correctly with citations', () => {
render(
<MockFormProvider>
<AssistantMessage
message={{
...mockMessage,
citations: [
{ content: 'Citation content', metadata: { _id: '1', _index: 'index', _score: 1 } },
],
}}
/>
</MockFormProvider>
);
expect(screen.getByTestId('assistant-message-citations')).toBeInTheDocument();
});
});

View file

@ -13,6 +13,7 @@ import {
EuiButtonEmpty,
EuiComment,
EuiFlexGroup,
EuiLink,
EuiSpacer,
EuiText,
EuiTitle,
@ -21,6 +22,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { css } from '@emotion/react';
import { docLinks } from '../../../common/doc_links';
import { RetrievalDocsFlyout } from './retrieval_docs_flyout';
import type { AIMessage as AIMessageType } from '../../types';
@ -52,6 +54,7 @@ export const AssistantMessage: React.FC<AssistantMessageProps> = ({ message }) =
<EuiComment
username={username}
timelineAvatar="dot"
data-test-subj="retrieval-docs-comment"
event={
<>
<EuiText size="s">
@ -68,6 +71,7 @@ export const AssistantMessage: React.FC<AssistantMessageProps> = ({ message }) =
css={{ blockSize: 'auto' }}
size="s"
flush="left"
data-test-subj="retrieval-docs-button"
onClick={() => setIsDocsFlyoutOpen(true)}
>
<FormattedMessage
@ -87,11 +91,50 @@ export const AssistantMessage: React.FC<AssistantMessageProps> = ({ message }) =
}
/>
)}
{retrievalDocs?.length === 0 && (
<EuiComment
username={username}
timelineAvatar="dot"
data-test-subj="retrieval-docs-comment-no-docs"
event={
<>
<EuiText size="s">
<p>
<FormattedMessage
id="xpack.searchPlayground.chat.message.assistant.noRetrievalDocs"
defaultMessage="Unable to retrieve documents based on the provided question and query."
/>
{` `}
</p>
</EuiText>
<EuiLink
href={docLinks.retrievalOptimize}
target="_blank"
data-test-subj="retrieval-optimization-documentation-link"
>
<FormattedMessage
id="xpack.searchPlayground.chat.message.assistant.noRetrievalDocs.learnMore"
defaultMessage=" Learn more."
/>
</EuiLink>
{isDocsFlyoutOpen && (
<RetrievalDocsFlyout
onClose={() => setIsDocsFlyoutOpen(false)}
retrievalDocs={retrievalDocs}
/>
)}
</>
}
/>
)}
<EuiComment
username={username}
event={i18n.translate('xpack.searchPlayground.chat.message.assistant.event.responded', {
defaultMessage: 'responded',
})}
data-test-subj="assistant-message"
timestamp={
createdAt &&
i18n.translate('xpack.searchPlayground.chat.message.assistant.createdAt', {
@ -137,7 +180,7 @@ export const AssistantMessage: React.FC<AssistantMessageProps> = ({ message }) =
{!!citations?.length && (
<>
<EuiSpacer size="l" />
<EuiTitle size="xs">
<EuiTitle size="xs" data-test-subj="assistant-message-citations">
<p>
<FormattedMessage
id="xpack.searchPlayground.chat.message.assistant.citations.title"

View file

@ -101,7 +101,7 @@ describe('SourcesPanelForStartChat component', () => {
noFieldsIndicesWarning: 'index1',
});
render(<SourcesPanelForStartChat />);
render(<SourcesPanelForStartChat />, { wrapper: Wrapper });
expect(screen.getByTestId('NoIndicesFieldsMessage')).toBeInTheDocument();
expect(screen.getByTestId('NoIndicesFieldsMessage')).toHaveTextContent('index1');
});

View file

@ -144,6 +144,17 @@ export const ViewQueryFlyout: React.FC<ViewQueryFlyoutProps> = ({ onClose }) =>
defaultMessage="This query will be used to search your indices. Customize by choosing which
fields in your Elasticsearch documents to search."
/>
{` `}
<EuiLink
href={docLinks.retrievalOptimize}
target="_blank"
data-test-subj="query-optimize-documentation-link"
>
<FormattedMessage
id="xpack.searchPlayground.viewQuery.flyout.learnMoreQueryOptimizeLink"
defaultMessage="Learn more."
/>
</EuiLink>
</p>
</EuiText>
</EuiFlyoutHeader>
@ -236,9 +247,9 @@ export const ViewQueryFlyout: React.FC<ViewQueryFlyoutProps> = ({ onClose }) =>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiLink
href={docLinks.chatPlayground}
href={docLinks.hiddenFields}
target="_blank"
data-test-subj="context-optimization-documentation-link"
data-test-subj="hidden-fields-documentation-link"
>
<FormattedMessage
id="xpack.searchPlayground.viewQuery.flyout.learnMoreLink"