Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparse_vector field support #168186

Merged
1 change: 1 addition & 0 deletions packages/kbn-field-utils/src/utils/field_types.ts
Expand Up @@ -36,6 +36,7 @@ export enum KNOWN_FIELD_TYPES {
RANK_FEATURES = 'rank_features',
POINT = 'point',
SHAPE = 'shape',
SPARSE_VECTOR = 'sparse_vector',
STRING = 'string',
TEXT = 'text',
VERSION = 'version',
Expand Down
Expand Up @@ -118,6 +118,10 @@ export function getFieldTypeDescription(type?: string) {
return i18n.translate('fieldUtils.fieldNameDescription.shapeField', {
defaultMessage: 'Arbitrary cartesian geometries.',
});
case KNOWN_FIELD_TYPES.SPARSE_VECTOR:
return i18n.translate('fieldUtils.fieldNameDescription.sparseVectorField', {
defaultMessage: 'Records sparse vectors of float values.',
});
case KNOWN_FIELD_TYPES.STRING:
return i18n.translate('fieldUtils.fieldNameDescription.stringField', {
defaultMessage: 'Full text such as the body of an email or a product description.',
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-field-utils/src/utils/get_field_type_name.ts
Expand Up @@ -123,6 +123,10 @@ export function getFieldTypeName(type?: string) {
return i18n.translate('fieldUtils.fieldNameIcons.shapeFieldAriaLabel', {
defaultMessage: 'Shape',
});
case KNOWN_FIELD_TYPES.SPARSE_VECTOR:
return i18n.translate('fieldUtils.fieldNameIcons.sparseVectorFieldAriaLabel', {
defaultMessage: 'Sparse vector',
});
case KNOWN_FIELD_TYPES.STRING:
return i18n.translate('fieldUtils.fieldNameIcons.stringFieldAriaLabel', {
defaultMessage: 'String',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/kbn-react-field/src/field_icon/field_icon.tsx
Expand Up @@ -32,6 +32,7 @@ export interface FieldIconProps extends Omit<EuiTokenProps, 'iconType'> {
| '_source'
| 'point'
| 'shape'
| 'sparse_vector'
| 'string'
| string
| 'nested'
Expand Down Expand Up @@ -69,6 +70,7 @@ export const typeToEuiIconMap: Partial<Record<string, EuiTokenProps>> = {
_source: { iconType: 'editorCodeBlock', color: 'gray' },
point: { iconType: 'tokenShape' }, // there is no separate icon for `point` yet
shape: { iconType: 'tokenShape' },
sparse_vector: { iconType: 'tokenDenseVector' },
Copy link
Member

Choose a reason for hiding this comment

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

Same question here, do we want to use tokenDenseVector or should we create a new token for sparse vector?

Copy link
Contributor

Choose a reason for hiding this comment

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

@andreadelrio do we have an icon we can use or add to eui?

Copy link
Member Author

Choose a reason for hiding this comment

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

Andrea is already pinged in elastic/eui#7257 (comment). 😉 My plan is to open a separate PR when that's ready.

string: { iconType: 'tokenString' },
text: { iconType: 'tokenString' },
keyword: { iconType: 'tokenKeyword' },
Expand Down
Expand Up @@ -44,7 +44,7 @@ describe('updateMlInferenceMappings', () => {
input_one_expanded: {
properties: {
predicted_value: {
type: 'rank_features',
type: 'sparse_vector',
},
model_id: {
type: 'keyword',
Expand All @@ -54,7 +54,7 @@ describe('updateMlInferenceMappings', () => {
input_two_expanded: {
properties: {
predicted_value: {
type: 'rank_features',
type: 'sparse_vector',
},
model_id: {
type: 'keyword',
Expand Down
Expand Up @@ -77,7 +77,7 @@ const generateTextExpansionMappingProperties = (sourceFields: string[], targetFi
type: 'keyword',
},
predicted_value: {
type: 'rank_features',
type: 'sparse_vector',
},
},
},
Expand All @@ -97,7 +97,7 @@ const formDefaultElserMappingProps = (sourceFields: string[]) => {
type: 'keyword',
},
predicted_value: {
type: 'rank_features',
type: 'sparse_vector',
},
},
},
Expand Down
Expand Up @@ -851,6 +851,23 @@ export const TYPE_DEFINITION: { [key in DataType]: DataTypeDefinition } = {
</p>
),
},
sparse_vector: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @carlosdelest, just a question: why are we adding these changes to the Index management plugin?
Did you mean to add support for the sparse_vector field type in the Mappings editor?

Screenshot 2023-10-06 at 17 52 47

Copy link
Member Author

Choose a reason for hiding this comment

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

@ElenaStoeva , thanks for pointing that out - I totally missed it.

I've made the changes here.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying! Tested locally and LGTM.

label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.sparseVectorDescription', {
defaultMessage: 'Sparse vector',
}),
value: 'sparse_vector',
documentation: {
main: 'sparse-vector.html',
},
description: () => (
<p>
<FormattedMessage
id="xpack.idxMgmt.mappingsEditor.dataType.sparseVectorLongDescription"
defaultMessage="Sparse vector fields index features and weights, useful for document scoring."
/>
</p>
),
},
point: {
label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.pointDescription', {
defaultMessage: 'Point',
Expand Down
Expand Up @@ -58,6 +58,7 @@ export type MainType =
| 'rank_features'
| 'shape'
| 'search_as_you_type'
| 'sparse_vector'
| 'date'
| 'date_nanos'
| 'geo_point'
Expand Down