Skip to content

Commit

Permalink
[Search] [Playground] fix semantic_text issue (elastic#207054)
Browse files Browse the repository at this point in the history
## Summary

This fixes an issue in playground where the generated query is using a
multi_match. This is because the field is now defined as a text field
and Playground was treating the field as a text field and using it in a
multi-match.

This fix detects if the field is declared in the mappings API as
semantic_text and what the model_id is.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
joemcelroy and kibanamachine authored Jan 17, 2025
1 parent 3ca02b3 commit 7987527
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const SPARSE_SEMANTIC_FIELD_FIELD_CAPS = {
indices: ['test-index2'],
fields: {
infer_field: {
semantic_text: {
type: 'semantic_text',
text: {
type: 'text',
metadata_field: false,
searchable: false,
searchable: true,
aggregatable: false,
},
},
Expand Down Expand Up @@ -127,10 +127,10 @@ export const DENSE_SEMANTIC_FIELD_FIELD_CAPS = {
indices: ['test-index2'],
fields: {
infer_field: {
semantic_text: {
type: 'semantic_text',
text: {
type: 'text',
metadata_field: false,
searchable: false,
searchable: true,
aggregatable: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,9 @@ export const parseFieldsCapabilities = (
(indexModelIdField) => indexModelIdField.index === index
)!;
const nestedField = isFieldNested(fieldKey, fieldCapsResponse);
const semanticFieldMapping = getSemanticField(fieldKey, semanticTextFields);

if (isFieldInIndex(field, 'semantic_text', index)) {
const semanticFieldMapping = getSemanticField(fieldKey, semanticTextFields);

if (isFieldInIndex(field, 'text', index) && semanticFieldMapping) {
// only use this when embeddingType and inferenceId is defined
// this requires semantic_text field to be set up correctly and ingested
if (
Expand All @@ -260,7 +259,7 @@ export const parseFieldsCapabilities = (
field: fieldKey,
inferenceId: semanticFieldMapping.inferenceId,
embeddingType: semanticFieldMapping.embeddingType,
indices: (field.semantic_text.indices as string[]) || indicesPresentIn,
indices: (field.text.indices as string[]) || indicesPresentIn,
};

acc[index].semantic_fields.push(semanticField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function streamFactory(logger: Logger, isCloud: boolean = false): StreamF
);

if (line === undefined) {
logger.error('Stream chunk must not be undefined.');
logDebugMessage('Stream chunk must not be undefined.');
return;
}

Expand Down

0 comments on commit 7987527

Please sign in to comment.