Skip to content

Commit

Permalink
[ML] File data visualizer: only list sparse_embedding and text_embedd…
Browse files Browse the repository at this point in the history
…ing inference endpoints (#196577)

When listing the inference endpoints available for the semantic text
field, we should only list `sparse_embedding` and `text_embedding`
types.

<img width="353" alt="image"
src="https://github.com/user-attachments/assets/95526f2b-e293-4e01-be79-b87e1ecb9a75">



This PR adds a check to the `data_visualizer/inference_endpoints`
endpoint to ensure only `sparse_embedding` and `text_embedding` types
are used and they have at least one allocation.
NOTE, the allocation check is currently commented out waiting on an es
change. elastic/elasticsearch#115095

Also renames the endpoint from `data_visualizer/inference_services` ->
`data_visualizer/inference_endpoints`
And renames variables which were incorrectly named "service" rather than
"endpoint"
  • Loading branch information
jgowdyelastic authored Oct 21, 2024
1 parent 608cc70 commit fb412ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const SemanticTextForm: FC<Props> = ({ addCombinedField, hasNameCollision
const {
services: { http },
} = useDataVisualizerKibana();
const [inferenceServices, setInferenceServices] = useState<EuiSelectOption[]>([]);
const [selectedInference, setSelectedInference] = useState<string | undefined>();
const [inferenceEndpoints, setInferenceEndpoints] = useState<EuiSelectOption[]>([]);
const [selectedInferenceEndpoint, setSelectedInferenceEndpoint] = useState<string | undefined>();
const [selectedFieldOption, setSelectedFieldOption] = useState<string | undefined>();
const [renameToFieldOption, setRenameToFieldOption] = useState<string>('');
const [fieldError, setFieldError] = useState<string | undefined>();
Expand All @@ -61,17 +61,17 @@ export const SemanticTextForm: FC<Props> = ({ addCombinedField, hasNameCollision

useEffect(() => {
http
.fetch<InferenceInferenceEndpointInfo[]>('/internal/data_visualizer/inference_services', {
.fetch<InferenceInferenceEndpointInfo[]>('/internal/data_visualizer/inference_endpoints', {
method: 'GET',
version: '1',
})
.then((response) => {
const inferenceServiceOptions = response.map((service) => ({
value: service.inference_id,
text: service.inference_id,
const inferenceEndpointOptions = response.map((endpoint) => ({
value: endpoint.inference_id,
text: endpoint.inference_id,
}));
setInferenceServices(inferenceServiceOptions);
setSelectedInference(inferenceServiceOptions[0]?.value ?? undefined);
setInferenceEndpoints(inferenceEndpointOptions);
setSelectedInferenceEndpoint(inferenceEndpointOptions[0]?.value ?? undefined);
});
}, [http]);

Expand All @@ -88,7 +88,7 @@ export const SemanticTextForm: FC<Props> = ({ addCombinedField, hasNameCollision
renameToFieldOption === '' ||
renameToFieldOption === undefined ||
selectedFieldOption === undefined ||
selectedInference === undefined
selectedInferenceEndpoint === undefined
) {
return;
}
Expand All @@ -103,7 +103,7 @@ export const SemanticTextForm: FC<Props> = ({ addCombinedField, hasNameCollision
newMappings.properties![renameToFieldOption ?? selectedFieldOption] = {
// @ts-ignore types are missing semantic_text
type: 'semantic_text',
inference_id: selectedInference,
inference_id: selectedInferenceEndpoint,
};
return newMappings;
},
Expand Down Expand Up @@ -138,12 +138,12 @@ export const SemanticTextForm: FC<Props> = ({ addCombinedField, hasNameCollision

const isInvalid = useMemo(() => {
return (
!selectedInference ||
!selectedInferenceEndpoint ||
!selectedFieldOption ||
renameToFieldOption === '' ||
fieldError !== undefined
);
}, [selectedInference, selectedFieldOption, renameToFieldOption, fieldError]);
}, [selectedInferenceEndpoint, selectedFieldOption, renameToFieldOption, fieldError]);

return (
<>
Expand Down Expand Up @@ -185,13 +185,13 @@ export const SemanticTextForm: FC<Props> = ({ addCombinedField, hasNameCollision

<EuiFormRow
label={i18n.translate('xpack.dataVisualizer.file.semanticTextForm.inferenceLabel', {
defaultMessage: 'Inference service',
defaultMessage: 'Inference endpoint',
})}
>
<EuiSelect
options={inferenceServices}
value={selectedInference}
onChange={(e) => setSelectedInference(e.target.value)}
options={inferenceEndpoints}
value={selectedInferenceEndpoint}
onChange={(e) => setSelectedInferenceEndpoint(e.target.value)}
/>
</EuiFormRow>

Expand Down
19 changes: 17 additions & 2 deletions x-pack/plugins/data_visualizer/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ export function routes(coreSetup: CoreSetup<StartDeps, unknown>, logger: Logger)
}
);

/**
* @apiGroup DataVisualizer
*
* @api {get} /internal/data_visualizer/inference_endpoints Returns a list of inference endpoints which are currently deployed
* @apiName inferenceEndpoints
* @apiDescription Returns a list of inference endpoints where the underlying model is currently deployed
*/
router.versioned
.get({
path: '/internal/data_visualizer/inference_services',
path: '/internal/data_visualizer/inference_endpoints',
access: 'internal',
options: {
tags: ['access:fileUpload:analyzeFile'],
Expand All @@ -87,7 +94,15 @@ export function routes(coreSetup: CoreSetup<StartDeps, unknown>, logger: Logger)
inference_id: '_all',
});

return response.ok({ body: endpoints });
const filteredInferenceEndpoints = endpoints.filter((endpoint) => {
return (
endpoint.task_type === 'sparse_embedding' || endpoint.task_type === 'text_embedding'
// TODO: add this back in when the fix has made it into es in 8.16
// && endpoint.service_settings.num_allocations > 0
);
});

return response.ok({ body: filteredInferenceEndpoints });
} catch (e) {
return response.customError(wrapError(e));
}
Expand Down

0 comments on commit fb412ca

Please sign in to comment.