inaturalist / iNaturalistMLWork

0 stars 0 forks source link

Enable reloading synonyms in inatVisionAPI without restarting app #51

Closed pleary closed 3 months ago

pleary commented 4 months ago

We'll want to regularly regenerate the synonym mapping and updated taxonomy based on recent taxon changes. It takes several seconds to start inatVisionAPI as it has to do thing like load the models into memory. It isn't necessary to reload the models to update the synonym mappings, so we could reload them without having API downtime. Add a method that checks to see if the files at the synonym path locations have been updated since last reading them, and reload the mappings for use in API results. Run that method regularly (before or after an API call, or on a schedule if we can do that) so the synonym mappings are kept up-to-date without needing to restart the whole API

pleary commented 3 months ago

Resolved with https://github.com/inaturalist/inatVisionAPI/commit/5828a9f50eca9de4113c34f85678c771306be09b. There are methods to check if the synonyms file has changed since last processed, and to reprocess it if it has changed. For the API use case, I also added an API endpoint to refresh the synonyms file. That way we don't need to do it as a before or after step on an end-users API request, slowing down the first request after updating synonyms. We can make a POST request to /refresh_synonyms after updating the synonyms data independent of users requests.