Add Model cache to cache model templates in memory#46
Add Model cache to cache model templates in memory#46jmazanec15 merged 12 commits intoopensearch-project:feature/faiss-supportfrom
Conversation
Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
| (s) -> Long.toString(KNN_DEFAULT_MODEL_CACHE_SIZE_IN_BYTES), | ||
| (s) -> { | ||
| long value = Long.parseLong(s); | ||
| if (value < KNN_MIN_MODEL_CACHE_SIZE_IN_BYTES) { |
There was a problem hiding this comment.
nit: why not combine both into single check and error message as "value must be > 100 KB and <= 80 MB, so that user knows required setting at first failure attempt?
|
|
||
| private static Logger logger = LogManager.getLogger(ModelCache.class); | ||
|
|
||
| private static ModelCache INSTANCE; |
There was a problem hiding this comment.
Why Upper case? i believe only constants are in Upper case
There was a problem hiding this comment.
Good catch, will update
Signed-off-by: John Mazanec <jmazane@amazon.com>
VijayanB
left a comment
There was a problem hiding this comment.
Thanks for answers. it looks good. Will keep it as it is.
| @Override | ||
| public void delete(String modelId, ActionListener<DeleteResponse> listener) { | ||
| if (!isCreated()) { | ||
| throw new IllegalStateException("Cannot delete model \"" + modelId + "\". Model index does not exist."); |
There was a problem hiding this comment.
If the Model index is deleted which means model is deleted right? Why should this be an exception? May be mark as logger.info for debugging purpose?
There was a problem hiding this comment.
My thinking for throwing an exception is that a user should not try to delete something that isnt there. I can switch to a log statement and return.
Btw, this function is subject to change. For instance, what happens when someone tries to delete a model that is in use by an index? This could cause problems. I will need to think it through a little more once I start implementing Model Index management APIs.
Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
| @Override | ||
| public void put(String modelId, KNNEngine knnEngine, byte[] modelBlob, ActionListener<IndexResponse> listener) { | ||
| if (!isCreated()) { | ||
| throw new IllegalStateException("Cannot put model in index before index has been initialized"); |
There was a problem hiding this comment.
Question: Is it possible Model index not created and we end up with this put? If its the case, why not we create Model index on the first put and proceed?
There was a problem hiding this comment.
It is possible. I think that makes sense. Will update.
Signed-off-by: John Mazanec <jmazane@amazon.com>
…t#46) Signed-off-by: Jack Mazanec <jmazane@amazon.com>
Signed-off-by: Jack Mazanec <jmazane@amazon.com>
…t#46) Signed-off-by: Jack Mazanec <jmazane@amazon.com>
…t#46) Signed-off-by: Jack Mazanec <jmazane@amazon.com> Signed-off-by: Martin Gaievski <gaievski@amazon.com>
…t#46) Signed-off-by: Jack Mazanec <jmazane@amazon.com>
…t#46) Signed-off-by: Jack Mazanec <jmazane@amazon.com>
Description
For OpenSearch indices that require training, a trained model template index will need to be created and stored in the Model system index before ingestion can begin. In order for the plugin to create a segment for indices that require training, a template will need to be loaded from the Model system index and passed to the jni. If the KNNDocValuesConsumer were to make a get request to this index for each segment creation operation, indexing will be slow. The purpose of this cache is to speed up this operation by storing the model template index in memory on a given node.
Cache size is determined by a new cluster setting that is updateable. On update, the cache will be rebuilt.
Additionally, this PR refactors ModelIndex into ModelDao interface. This helps for testing. However, no core functionality of the model index has been changed.
Unit tests for the cache have been added to validate.
This PR does not introduce APIs or functionality to warmup or remove entries from the cache. In the future, we can investigate adding these APIs and functionality.
Issues Resolved
#27
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.