Skip to content

Commit

Permalink
sparse_vector field support (elastic#168186)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest authored and dej611 committed Oct 17, 2023
1 parent 5cfd218 commit cf06e41
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 4 deletions.
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' },
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: {
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 @@ -958,6 +975,7 @@ export const MAIN_TYPES: MainType[] = [
'rank_features',
'search_as_you_type',
'shape',
'sparse_vector',
'text',
'token_count',
'histogram',
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

0 comments on commit cf06e41

Please sign in to comment.