-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Search] Consolidate ML model fetch calls #176257
Conversation
if (!selectedMLModel || configuration.existingPipeline) return null; | ||
const modelType = getMLType(getMlModelTypesForModelConfig(selectedMLModel)); | ||
if (!selectedModel || configuration.existingPipeline) return null; | ||
const modelType = getMLType([selectedModel.type]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be simplified by using selectedModel.type
directly. I'll check if there are any side effects and modify the code in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at getMLType()
I think this is still needed to show the correct type for the lang_ident
model. I think without that check this might have show built-in
instead. But you should confirm that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - it does change the type from lang_ident
to classification
. I think that's OK - the built-in language identification model's type is classification, and I don't see any logic that depends on the value of modelType
. But for the sake of less moving parts I restored the original value parsing in this line and in another.
!API_REQUEST_COMPLETE_STATUSES.includes(mlModelsStatus) || | ||
!API_REQUEST_COMPLETE_STATUSES.includes(mappingStatus), | ||
() => [selectors.mappingStatus], | ||
(mappingStatus: Status) => !API_REQUEST_COMPLETE_STATUSES.includes(mappingStatus), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isLoading
flag for the pipeline configuration panel no longer depends on the status of model fetching. The "models loading" state is now displayed in the model selector. Other steps of the workflow (e.g. generating pipeline configuration) depend on the models data, but it's very unlikely the user will get to that stage before the models finish loading (and even if they do, they just need to wait a little).
If we keep this dependency, the pipeline configuration panel's rendering will be blocked by the fetching of the models.
() => [selectors.selectableModelsFromMLInferenceLogic], | ||
(selectableModels) => selectableModels, // Pass-through |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need these pass-through selectors, or we should just expose the imported selectors directly like startPollingModels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with @TattdCodeMonkey that we don't need plain pass-through selectors. I'll remove these in a follow-up PR.
/ci |
events: {}, | ||
events: ({ actions }) => ({ | ||
afterMount: () => { | ||
actions.startPollingModels(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason the GET /ml/models
API is called twice upon opening the pipeline config flyout, and populates the models, so this hook is technically not needed. But I can't find what triggers the other call, so I'm leaving it here while I investigate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2nd call is caused by useEffect() -> setIndexName
in add_inference_pipeline_flyout.tsx
. I removed the listener, moved the fetch operations there, and removed the afterMount
hook.
@elasticmachine merge upstream |
…ithub.com/elastic/kibana into demjened/remove-ml-model-fetch-redundancy
…ithub.com/elastic/kibana into demjened/remove-ml-model-fetch-redundancy
05403ad
to
92019fd
Compare
// Trigger fetching of initial data: existing ML pipelines, available models, index mapping | ||
makeMlInferencePipelinesRequest(undefined); | ||
startPollingModels(); | ||
makeMappingRequest({ indexName }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved initial fetch operations here from setIndexName
listener.
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall :)
@@ -103,9 +107,6 @@ export const AddInferencePipelineContent = ({ onClose }: AddInferencePipelineFly | |||
</EuiFlyoutBody> | |||
); | |||
} | |||
if (supportedMLModels.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good to see this removed since we allow the lang ident model now there should never be 0 ML Models
if (!selectedMLModel || configuration.existingPipeline) return null; | ||
const modelType = getMLType(getMlModelTypesForModelConfig(selectedMLModel)); | ||
if (!selectedModel || configuration.existingPipeline) return null; | ||
const modelType = getMLType([selectedModel.type]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at getMLType()
I think this is still needed to show the correct type for the lang_ident
model. I think without that check this might have show built-in
instead. But you should confirm that.
...terprise_search_content/components/search_index/pipelines/ml_inference/ml_inference_logic.ts
Outdated
Show resolved
Hide resolved
@@ -359,7 +349,7 @@ export const MLInferenceLogic = kea< | |||
}, | |||
startTextExpansionModelSuccess: () => { | |||
// Refresh ML models list when the text expansion model is started | |||
actions.makeMLModelsRequest(undefined); | |||
actions.startPollingModels(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have a refreshModels
action on CachedFetchModlesApiLogic
instead of re-using startPollingModels
to force an update.
I'm fine with this for now, but its an improvement we could consider, it may not be worth the overhead though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TattdCodeMonkey For my understanding - is the issue that this action happens outside the pipeline configuration screen (ELSER callout), and so it unnecessarily starts polling the models rather than refreshing them once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more a semantic quibble, that really isn't important.
If I under the code correctly we are calling startPollingModels()
here to force a refresh the model list after an update instead of waiting for the next poll, correct? If thats the case it would be a little nicer to have an action that is descriptive of that intent vs re-using startPollingModels()
.
BUT calling startPollingModels()
works, so is it worth the complexity of introducing another action that may require other special handing to not interfere with the existing polling? maybe not, I could make the argument both ways. So feel free to ignore me this time if you want :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha - yeah, it might not be worth the effort. But let's revisit this once these components and logics have been refactored.
…ithub.com/elastic/kibana into demjened/remove-ml-model-fetch-redundancy
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Unknown metric groupsmiscellaneous assets size
History
To update your PR or re-run it, just comment with: |
## Summary With the introduction of [fetch_ml_models.ts](https://github.com/elastic/kibana/blob/main/x-pack/plugins/enterprise_search/server/lib/ml/fetch_ml_models.ts), the fetching and enriching of ML models for Search purposes has been consolidated in that API. This allows us to remove the dependency on the older method that works with ML plugin-specific `TrainedModel` entities. This PR makes the following changes: - Switch over code that depend on ML models to use the new function from `fetch_ml_models.ts` (that already does sorting/filtering). - Move the fetch process to `ml_inference_logic.ts`, and begin periodically polling after mounting the logic. This enables passing down values to lower components, e.g. `model_select_logic.ts`, instead of repeating the fetch there. - Use `MlModel` instead of `TrainedModel/MlTrainedModelConfig`. This requires adding some missing properties to `MlModel`: `types`, `inputFieldNames`, `version`. - Remove the old fetch methods (`x-pack/plugins/enterprise_search/server/lib/ml/ml_*_logic.ts`). - Remove the "no models available" component and condition, since as of 8.12 at least the ELSER/E5 placeholders are always present. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
## Summary With the introduction of [fetch_ml_models.ts](https://github.com/elastic/kibana/blob/main/x-pack/plugins/enterprise_search/server/lib/ml/fetch_ml_models.ts), the fetching and enriching of ML models for Search purposes has been consolidated in that API. This allows us to remove the dependency on the older method that works with ML plugin-specific `TrainedModel` entities. This PR makes the following changes: - Switch over code that depend on ML models to use the new function from `fetch_ml_models.ts` (that already does sorting/filtering). - Move the fetch process to `ml_inference_logic.ts`, and begin periodically polling after mounting the logic. This enables passing down values to lower components, e.g. `model_select_logic.ts`, instead of repeating the fetch there. - Use `MlModel` instead of `TrainedModel/MlTrainedModelConfig`. This requires adding some missing properties to `MlModel`: `types`, `inputFieldNames`, `version`. - Remove the old fetch methods (`x-pack/plugins/enterprise_search/server/lib/ml/ml_*_logic.ts`). - Remove the "no models available" component and condition, since as of 8.12 at least the ELSER/E5 placeholders are always present. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
## Summary With the introduction of [fetch_ml_models.ts](https://github.com/elastic/kibana/blob/main/x-pack/plugins/enterprise_search/server/lib/ml/fetch_ml_models.ts), the fetching and enriching of ML models for Search purposes has been consolidated in that API. This allows us to remove the dependency on the older method that works with ML plugin-specific `TrainedModel` entities. This PR makes the following changes: - Switch over code that depend on ML models to use the new function from `fetch_ml_models.ts` (that already does sorting/filtering). - Move the fetch process to `ml_inference_logic.ts`, and begin periodically polling after mounting the logic. This enables passing down values to lower components, e.g. `model_select_logic.ts`, instead of repeating the fetch there. - Use `MlModel` instead of `TrainedModel/MlTrainedModelConfig`. This requires adding some missing properties to `MlModel`: `types`, `inputFieldNames`, `version`. - Remove the old fetch methods (`x-pack/plugins/enterprise_search/server/lib/ml/ml_*_logic.ts`). - Remove the "no models available" component and condition, since as of 8.12 at least the ELSER/E5 placeholders are always present. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
With the introduction of fetch_ml_models.ts, the fetching and enriching of ML models for Search purposes has been consolidated in that API. This allows us to remove the dependency on the older method that works with ML plugin-specific
TrainedModel
entities.This PR makes the following changes:
fetch_ml_models.ts
(that already does sorting/filtering).ml_inference_logic.ts
, and begin periodically polling after mounting the logic. This enables passing down values to lower components, e.g.model_select_logic.ts
, instead of repeating the fetch there.MlModel
instead ofTrainedModel/MlTrainedModelConfig
. This requires adding some missing properties toMlModel
:types
,inputFieldNames
,version
.x-pack/plugins/enterprise_search/server/lib/ml/ml_*_logic.ts
).Checklist