Skip to content

Commit

Permalink
[Enterprise Search] remove trained model names (#141713) (#141721)
Browse files Browse the repository at this point in the history
Due to restrictions around Kibana spaces with trained models we do not
want to return model names to the UI or include them in documents
processed by ml inference.

(cherry picked from commit 1bdfd0e)

Co-authored-by: Rodney Norris <[email protected]>
  • Loading branch information
kibanamachine and TattdCodeMonkey authored Sep 24, 2022
1 parent 89749ae commit e92f098
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 27 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/enterprise_search/common/types/pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
export interface InferencePipeline {
isDeployed: boolean;
pipelineName: string;
trainedModelName: string;
types: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
EuiPopover,
EuiPopoverTitle,
EuiText,
EuiTextColor,
EuiTitle,
} from '@elastic/eui';

Expand All @@ -35,7 +34,6 @@ import { PipelinesLogic } from './pipelines_logic';

export const InferencePipelineCard: React.FC<InferencePipeline> = ({
pipelineName,
trainedModelName,
isDeployed,
types,
}) => {
Expand Down Expand Up @@ -129,9 +127,6 @@ export const InferencePipelineCard: React.FC<InferencePipeline> = ({
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup>
<EuiFlexItem>
<EuiTextColor color="subdued">{trainedModelName}</EuiTextColor>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup gutterSize="m" justifyContent="flexEnd">
{isDeployed && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ export const MlInferencePipelineProcessorsCard: React.FC = () => {
<EuiFlexGroup direction="column" gutterSize="s">
{inferencePipelines.map((item: InferencePipeline, index: number) => (
<EuiFlexItem key={index}>
<InferencePipelineCard
trainedModelName={item.trainedModelName}
pipelineName={item.pipelineName}
isDeployed={item.isDeployed}
types={item.types}
/>
<InferencePipelineCard {...item} />
</EuiFlexItem>
))}
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
fetchMlInferencePipelineProcessorNames,
fetchMlInferencePipelineProcessors,
fetchPipelineProcessorInferenceData,
InferencePipelineData,
} from './fetch_ml_inference_pipeline_processors';

const mockGetPipeline = {
Expand Down Expand Up @@ -190,13 +191,11 @@ const trainedModelDataObject = {
'trained-model-id-1': {
isDeployed: false,
pipelineName: 'ml-inference-pipeline-1',
trainedModelName: 'trained-model-id-1',
types: ['lang_ident', 'ner'],
},
'trained-model-id-2': {
isDeployed: true,
pipelineName: 'ml-inference-pipeline-2',
trainedModelName: 'trained-model-id-2',
types: ['pytorch', 'ner'],
},
};
Expand Down Expand Up @@ -391,7 +390,7 @@ describe('fetchAndAddTrainedModelData lib function', () => {
Promise.resolve(mockGetTrainedModelStats)
);

const pipelines: InferencePipeline[] = [
const pipelines: InferencePipelineData[] = [
{
isDeployed: false,
pipelineName: 'ml-inference-pipeline-1',
Expand All @@ -406,7 +405,7 @@ describe('fetchAndAddTrainedModelData lib function', () => {
},
];

const expected: InferencePipeline[] = [
const expected: InferencePipelineData[] = [
{
isDeployed: false,
pipelineName: 'ml-inference-pipeline-1',
Expand Down Expand Up @@ -555,7 +554,6 @@ describe('fetchMlInferencePipelineProcessors lib function', () => {
{
isDeployed: false,
pipelineName: 'ml-inference-pipeline-3',
trainedModelName: 'trained-model-id-1',
types: ['lang_ident', 'ner'],
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { BUILT_IN_MODEL_TAG } from '@kbn/ml-plugin/common/constants/data_frame_a
import { InferencePipeline } from '../../../common/types/pipelines';
import { getInferencePipelineNameFromIndexName } from '../../utils/ml_inference_pipeline_utils';

export type InferencePipelineData = InferencePipeline & {
trainedModelName: string;
};

export const fetchMlInferencePipelineProcessorNames = async (
client: ElasticsearchClient,
indexName: string
Expand All @@ -37,7 +41,7 @@ export const fetchMlInferencePipelineProcessorNames = async (
export const fetchPipelineProcessorInferenceData = async (
client: ElasticsearchClient,
mlInferencePipelineProcessorNames: string[]
): Promise<InferencePipeline[]> => {
): Promise<InferencePipelineData[]> => {
const mlInferencePipelineProcessorConfigs = await client.ingest.getPipeline({
id: mlInferencePipelineProcessorNames.join(),
});
Expand All @@ -62,7 +66,7 @@ export const fetchPipelineProcessorInferenceData = async (

return pipelineProcessorData;
},
[] as InferencePipeline[]
[] as InferencePipelineData[]
);
};

Expand All @@ -81,13 +85,13 @@ export const getMlModelTypesForModelConfig = (trainedModel: MlTrainedModelConfig
export const getMlModelConfigsForModelIds = async (
client: ElasticsearchClient,
trainedModelNames: string[]
): Promise<Record<string, InferencePipeline>> => {
): Promise<Record<string, InferencePipelineData>> => {
const [trainedModels, trainedModelsStats] = await Promise.all([
client.ml.getTrainedModels({ model_id: trainedModelNames.join() }),
client.ml.getTrainedModelsStats({ model_id: trainedModelNames.join() }),
]);

const modelConfigs: Record<string, InferencePipeline> = {};
const modelConfigs: Record<string, InferencePipelineData> = {};

trainedModels.trained_model_configs.forEach((trainedModelData) => {
const trainedModelName = trainedModelData.model_id;
Expand Down Expand Up @@ -115,8 +119,8 @@ export const getMlModelConfigsForModelIds = async (

export const fetchAndAddTrainedModelData = async (
client: ElasticsearchClient,
pipelineProcessorData: InferencePipeline[]
): Promise<InferencePipeline[]> => {
pipelineProcessorData: InferencePipelineData[]
): Promise<InferencePipelineData[]> => {
const trainedModelNames = Array.from(
new Set(pipelineProcessorData.map((pipeline) => pipeline.trainedModelName))
);
Expand Down Expand Up @@ -160,5 +164,9 @@ export const fetchMlInferencePipelineProcessors = async (
// inference processors, return early to avoid fetching all of the possible trained model data.
if (pipelineProcessorInferenceData.length === 0) return [] as InferencePipeline[];

return await fetchAndAddTrainedModelData(client, pipelineProcessorInferenceData);
const pipelines = await fetchAndAddTrainedModelData(client, pipelineProcessorInferenceData);

// Due to restrictions with Kibana spaces we do not want to return the trained model name
// to the UI. So we remove it from the data structure here.
return pipelines.map(({ trainedModelName, ...pipeline }) => pipeline);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('createIndexPipelineDefinitions util function', () => {
});

describe('formatMlPipelineBody util function', () => {
const pipelineName = 'ml-inference-my-ml-proc';
const modelId = 'my-model-id';
let modelInputField = 'my-model-input-field';
const modelType = 'pytorch';
Expand Down Expand Up @@ -82,8 +83,8 @@ describe('formatMlPipelineBody util function', () => {
field: '_source._ingest.processors',
value: [
{
model_id: modelId,
model_version: modelVersion,
pipeline: pipelineName,
processed_timestamp: '{{{ _ingest.timestamp }}}',
types: modelTypes,
},
Expand All @@ -110,6 +111,7 @@ describe('formatMlPipelineBody util function', () => {
};
mockClient.ml.getTrainedModels.mockImplementation(() => Promise.resolve(mockResponse));
const actualResult = await formatMlPipelineBody(
pipelineName,
modelId,
sourceField,
destField,
Expand All @@ -123,6 +125,7 @@ describe('formatMlPipelineBody util function', () => {
const mockError = new Error('No known trained model with model_id [my-model-id]');
mockClient.ml.getTrainedModels.mockImplementation(() => Promise.reject(mockError));
const asyncCall = formatMlPipelineBody(
pipelineName,
modelId,
sourceField,
destField,
Expand Down Expand Up @@ -157,8 +160,8 @@ describe('formatMlPipelineBody util function', () => {
field: '_source._ingest.processors',
value: [
{
model_id: modelId,
model_version: modelVersion,
pipeline: pipelineName,
processed_timestamp: '{{{ _ingest.timestamp }}}',
types: modelTypes,
},
Expand All @@ -184,6 +187,7 @@ describe('formatMlPipelineBody util function', () => {
};
mockClient.ml.getTrainedModels.mockImplementation(() => Promise.resolve(mockResponse));
const actualResult = await formatMlPipelineBody(
pipelineName,
modelId,
sourceField,
destField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export const createIndexPipelineDefinitions = (
* @param esClient the Elasticsearch Client to use when retrieving model details.
*/
export const formatMlPipelineBody = async (
pipelineName: string,
modelId: string,
sourceField: string,
destinationField: string,
Expand Down Expand Up @@ -264,8 +265,8 @@ export const formatMlPipelineBody = async (
field: '_source._ingest.processors',
value: [
{
model_id: modelId,
model_version: modelVersion,
pipeline: pipelineName,
processed_timestamp: '{{{ _ingest.timestamp }}}',
types: modelTypes,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const createMlInferencePipeline = async (

// Generate pipeline with default processors
const mlInferencePipeline = await formatMlPipelineBody(
inferencePipelineGeneratedName,
modelId,
sourceField,
destinationField,
Expand Down

0 comments on commit e92f098

Please sign in to comment.