Skip to content

Commit

Permalink
[8.18] [Onboarding] Hide the semantic_text banner if there exists a s…
Browse files Browse the repository at this point in the history
…emantic_text field (elastic#210676) (elastic#212792)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[Onboarding] Hide the semantic_text banner if there exists a
semantic_text field
(elastic#210676)](elastic#210676)

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

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

<!--BACKPORT [{"author":{"name":"Saikat
Sarkar","email":"132922331+saikatsarkar056@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-02-28T11:25:30Z","message":"[Onboarding]
Hide the semantic_text banner if there exists a semantic_text field
(elastic#210676)\n\nIn this PR, we covered the following changes:\n\n- Do not
display the banner it after semantic text fields have been\nadded\n-
Update messaging to be more explicit on the automatic chunking that
is\nbeing handled in the background\n\n<img width=\"1717\"
alt=\"Screenshot 2025-02-26 at 3 53
40 PM\"\nsrc=\"https://github.com/user-attachments/assets/f7aecf30-b7ca-4add-a543-a76f975e372a\"\n/>\n\n\n\n-
- - \n\nCloses
https://github.com/elastic/search-team/issues/7874\n\n---------\n\nCo-authored-by:
Liam Thompson
<32779855+leemthompo@users.noreply.github.com>","sha":"bbc3b451f19f16352234c5c9f4312af5b6a641aa","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","v8.18.0","v9.1.0"],"title":"[Onboarding]
Hide the semantic_text banner if there exists a semantic_text
field","number":210676,"url":"https://github.com/elastic/kibana/pull/210676","mergeCommit":{"message":"[Onboarding]
Hide the semantic_text banner if there exists a semantic_text field
(elastic#210676)\n\nIn this PR, we covered the following changes:\n\n- Do not
display the banner it after semantic text fields have been\nadded\n-
Update messaging to be more explicit on the automatic chunking that
is\nbeing handled in the background\n\n<img width=\"1717\"
alt=\"Screenshot 2025-02-26 at 3 53
40 PM\"\nsrc=\"https://github.com/user-attachments/assets/f7aecf30-b7ca-4add-a543-a76f975e372a\"\n/>\n\n\n\n-
- - \n\nCloses
https://github.com/elastic/search-team/issues/7874\n\n---------\n\nCo-authored-by:
Liam Thompson
<32779855+leemthompo@users.noreply.github.com>","sha":"bbc3b451f19f16352234c5c9f4312af5b6a641aa"}},"sourceBranch":"main","suggestedTargetBranches":["8.18"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212755","number":212755,"state":"MERGED","mergeCommit":{"sha":"ea8008511d7eb12514d7e5d0a112d2797ad72091","message":"[9.0]
[Onboarding] Hide the semantic_text banner if there exists a
semantic_text field (elastic#210676) (elastic#212755)\n\n# Backport\n\nThis will
backport the following commits from `main` to `9.0`:\n- [[Onboarding]
Hide the semantic_text banner if there exists a\nsemantic_text
field\n(elastic#210676)](https://github.com/elastic/kibana/pull/210676)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
Saikat Sarkar
<132922331+saikatsarkar056@users.noreply.github.com>"}},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210676","number":210676,"mergeCommit":{"message":"[Onboarding]
Hide the semantic_text banner if there exists a semantic_text field
(elastic#210676)\n\nIn this PR, we covered the following changes:\n\n- Do not
display the banner it after semantic text fields have been\nadded\n-
Update messaging to be more explicit on the automatic chunking that
is\nbeing handled in the background\n\n<img width=\"1717\"
alt=\"Screenshot 2025-02-26 at 3 53
40 PM\"\nsrc=\"https://github.com/user-attachments/assets/f7aecf30-b7ca-4add-a543-a76f975e372a\"\n/>\n\n\n\n-
- - \n\nCloses
https://github.com/elastic/search-team/issues/7874\n\n---------\n\nCo-authored-by:
Liam Thompson
<32779855+leemthompo@users.noreply.github.com>","sha":"bbc3b451f19f16352234c5c9f4312af5b6a641aa"}}]}]
BACKPORT-->

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
saikatsarkar056 and elasticmachine authored Mar 4, 2025
1 parent 47001f3 commit 3e10be9
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
engines: `${ENTERPRISE_SEARCH_DOCS}engines.html`,
indexApi: `${ELASTICSEARCH_DOCS}docs-index_.html`,
inferenceApiCreate: `${ELASTICSEARCH_DOCS}put-inference-api.html`,
inferenceApisConfigureChunking: `${ELASTICSEARCH_DOCS}inference-apis.html#infer-chunking-config`,
ingestionApis: `${ELASTICSEARCH_DOCS}search-with-elasticsearch.html`,
ingestPipelines: `${ELASTICSEARCH_DOCS}ingest-pipeline-search.html`,
knnSearch: `${ELASTICSEARCH_DOCS}knn-search.html`,
Expand Down
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export interface DocLinks {
readonly engines: string;
readonly indexApi: string;
readonly inferenceApiCreate: string;
readonly inferenceApisConfigureChunking: string;
readonly ingestionApis: string;
readonly ingestPipelines: string;
readonly knnSearch: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22467,7 +22467,6 @@
"xpack.idxMgmt.indexDetails.mappings.mappingsViewButtonGroupAriaLabel": "Groupe de bouton de l'affichage des mappings",
"xpack.idxMgmt.indexDetails.mappings.reloadButtonLabel": "Recharger",
"xpack.idxMgmt.indexDetails.mappings.saveMappings": "Enregistrer les mappings",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.description": "{label} Ajoutez un champ à votre mapping et choisissez \"Semantic text\" pour commencer.",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.descriptionForPlatinumLicense": "{label} Mettez à niveau votre licence pour ajouter les types de champ semantic_text à vos index.\"",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.dismiss": "Rejeter",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.semanticTextFieldAvailable": "Le type de champ semantic_text est maintenant disponible !",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22324,7 +22324,6 @@
"xpack.idxMgmt.indexDetails.mappings.mappingsViewButtonGroupAriaLabel": "マッピングビューボタングループ",
"xpack.idxMgmt.indexDetails.mappings.reloadButtonLabel": "再読み込み",
"xpack.idxMgmt.indexDetails.mappings.saveMappings": "マッピングを保存",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.description": "{label} 開始するには、フィールドをマッピングに追加して、Semantic_textを選択してください。",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.descriptionForPlatinumLicense": "{label} semantic_textフィールド型をインデックスに追加するには、ライセンスをアップグレードしてください。'",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.dismiss": "閉じる",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.semanticTextFieldAvailable": "semantic_textフィールド型が利用できるようになりました。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22407,7 +22407,6 @@
"xpack.idxMgmt.indexDetails.mappings.mappingsViewButtonGroupAriaLabel": "映射视图按钮组",
"xpack.idxMgmt.indexDetails.mappings.reloadButtonLabel": "重新加载",
"xpack.idxMgmt.indexDetails.mappings.saveMappings": "保存映射",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.description": "{label} 将字段添加到您的映射并选择“语义文本”以开始使用。",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.descriptionForPlatinumLicense": "{label} 升级许可证以将 semantic_text 字段类型添加到您的索引。'",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.dismiss": "关闭",
"xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.semanticTextFieldAvailable": "semantic_text 字段类型现已可用!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,67 @@ describe('<IndexDetailsPage />', () => {
});
});

describe('Semantic Text Banner', () => {
const mockIndexMappingResponseWithoutSemanticText: any = {
...testIndexMappings.mappings,
properties: {
...testIndexMappings.mappings.properties,
name: {
type: 'text',
},
},
};

const mockIndexMappingResponseWithSemanticText: any = {
...testIndexMappings.mappings,
properties: {
...testIndexMappings.mappings.properties,
name: {
type: 'text',
},
sem_text: {
type: 'semantic_text',
inference_id: '.elser-2-elasticsearch',
},
title: {
type: 'text',
copy_to: ['sem_text'],
},
},
};

beforeEach(async () => {
await act(async () => {
testBed = await setup({
httpSetup,
dependencies: {
core: {
application: { capabilities: { ml: { canGetTrainedModels: true } } },
},
},
});
});
});

it('semantic text banner is visible if there is no semantic_text field in the mapping', async () => {
httpRequestsMockHelpers.setLoadIndexMappingResponse(testIndexName, {
mappings: mockIndexMappingResponseWithoutSemanticText,
});
testBed.component.update();
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Mappings);
expect(testBed.actions.mappings.isSemanticTextBannerVisible()).toBe(true);
});

it('semantic text banner is not visible if there exists a semantic_text field in the mapping', async () => {
httpRequestsMockHelpers.setLoadIndexMappingResponse(testIndexName, {
mappings: mockIndexMappingResponseWithSemanticText,
});
testBed.component.update();
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Mappings);
expect(testBed.actions.mappings.isSemanticTextBannerVisible()).toBe(false);
});
});

describe('Mappings tab', () => {
beforeEach(async () => {
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Mappings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe('When semantic_text is enabled', () => {
expect(find('indexDetailsMappingsSemanticTextBanner').text()).toContain(
'semantic_text field type now available!'
);

expect(find('indexDetailsMappingsSemanticTextBanner').text()).toContain(
'Documents will be automatically chunked to fit model context limits, to avoid truncation.'
);
});

it('should hide the banner if dismiss is clicked', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export const DetailsPageMappingsContent: FunctionComponent<{
prefix: 'pendingFieldListId',
});

const hasSemanticText = hasSemanticTextField(state.fields);

const [isAddingFields, setAddingFields] = useState<boolean>(false);

useUnsavedChangesPrompt({
Expand Down Expand Up @@ -220,7 +222,6 @@ export const DetailsPageMappingsContent: FunctionComponent<{

const updateMappings = useCallback(
async (forceSaveMappings?: boolean) => {
const hasSemanticText = hasSemanticTextField(state.fields);
let inferenceToModelIdMap = state.inferenceToModelIdMap;
setIsUpdatingMappings(true);
try {
Expand Down Expand Up @@ -539,7 +540,7 @@ export const DetailsPageMappingsContent: FunctionComponent<{
</EuiFilterGroup>
</EuiFlexItem>
</EuiFlexGroup>
{hasMLPermissions && (
{hasMLPermissions && !hasSemanticText && (
<EuiFlexItem grow={true}>
<SemanticTextBanner
isSemanticTextEnabled={isSemanticTextEnabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiPanel, EuiText } from '@elastic/eui';
import {
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiLink,
EuiPanel,
EuiText,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import { documentationService } from '../../../../services';

interface SemanticTextBannerProps {
isSemanticTextEnabled: boolean;
Expand All @@ -31,10 +39,10 @@ const defaultLicenseMessage = (
/>
);

const platinumLicenseMessage = (
const getPlatinumLicenseMessage = () => (
<FormattedMessage
id="xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.description"
defaultMessage="{label} Add a field to your mapping and choose 'Semantic text' to get started."
defaultMessage="{label} Add a field to your mapping and choose 'Semantic text' to get started. Documents will be automatically chunked to fit model context limits, to avoid truncation. {learnMore}"
values={{
label: (
<strong>
Expand All @@ -44,6 +52,14 @@ const platinumLicenseMessage = (
/>
</strong>
),
learnMore: (
<EuiLink href={documentationService.getConfigureChunkingDocLink()} target="_blank">
<FormattedMessage
id="xpack.idxMgmt.indexDetails.mappings.semanticTextBanner.learnMore"
defaultMessage="Learn more"
/>
</EuiLink>
),
}}
/>
);
Expand All @@ -57,11 +73,11 @@ export function SemanticTextBanner({

return isSemanticTextBannerDisplayable && isSemanticTextEnabled ? (
<>
<EuiPanel color="success" data-test-subj="indexDetailsMappingsSemanticTextBanner">
<EuiFlexGroup>
<EuiPanel color="accentSecondary" data-test-subj="indexDetailsMappingsSemanticTextBanner">
<EuiFlexGroup alignItems="center">
<EuiFlexItem>
<EuiText size="m" color="success">
{isPlatinumLicense ? platinumLicenseMessage : defaultLicenseMessage}
<EuiText size="m" color="primary">
{isPlatinumLicense ? getPlatinumLicenseMessage() : defaultLicenseMessage}
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DocumentationService {
private indexSettings: string = '';
private indexTemplates: string = '';
private indexV1: string = '';
private inferenceApisConfigureChunking: string = '';
private mapping: string = '';
private mappingAnalyzer: string = '';
private mappingCoerce: string = '';
Expand Down Expand Up @@ -81,6 +82,7 @@ class DocumentationService {
this.indexManagement = links.management.indexManagement;
this.indexSettings = links.elasticsearch.indexSettings;
this.indexTemplates = links.elasticsearch.indexTemplates;
this.inferenceApisConfigureChunking = links.enterpriseSearch.inferenceApisConfigureChunking;
this.indexV1 = links.apis.putIndexTemplateV1;
this.mapping = links.elasticsearch.mapping;
this.mappingAnalyzer = links.elasticsearch.mappingAnalyzer;
Expand Down Expand Up @@ -159,6 +161,10 @@ class DocumentationService {
return this.indexManagement;
}

public getConfigureChunkingDocLink() {
return this.inferenceApisConfigureChunking;
}

public getIndicesComponentTemplate() {
return this.indicesComponentTemplate;
}
Expand Down

0 comments on commit 3e10be9

Please sign in to comment.