AsyncEmbeddingModel instances, keyed by embedding model name.
When multiple components request an embedding model for the same model name,
this cache ensures only one AsyncEmbeddingModel instance—and therefore only one
background download/load task—is ever created for that model name.
Without this cache, each caller that independently reacts to preference changes would
instantiate its own AsyncEmbeddingModel, spawning a duplicate
org. for every listener.
Implements AutoCloseable; call close() (e.g. in AiService.close())
to release all cached model resources.
| Modifier and Type | Field and Description |
|---|---|
| private final AiPreferences | |
| private final Map | |
| private final EmbeddingModelMetadataService | |
| private final NotificationService | |
| private final TaskExecutor |
| Access | Constructor and Description |
|---|---|
| public | EmbeddingModelCache(AiPreferences aiPreferences, NotificationService notificationService, TaskExecutor taskExecutor, EmbeddingModelMetadataService metadataService)
|
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | close()
Implements java. Closes all cached |
| public synchronized AsyncEmbeddingModel | getOrCreate(String
the requested embedding model name modelName)Returns the cached |
| aiPreferences | back to summary |
|---|---|
| private final AiPreferences aiPreferences | |
| cache | back to summary |
|---|---|
| private final Map<String, AsyncEmbeddingModel> cache | |
| metadataService | back to summary |
|---|---|
| private final EmbeddingModelMetadataService metadataService | |
| notificationService | back to summary |
|---|---|
| private final NotificationService notificationService | |
| taskExecutor | back to summary |
|---|---|
| private final TaskExecutor taskExecutor | |
| EmbeddingModelCache | back to summary |
|---|---|
| public EmbeddingModelCache(AiPreferences aiPreferences, NotificationService notificationService, TaskExecutor taskExecutor, EmbeddingModelMetadataService metadataService) | |
| close | back to summary |
|---|---|
| public synchronized void close() Implements java. Closes all cached Should be called once the AI subsystem is shut down (i.e. from
| |
| getOrCreate | back to summary |
|---|---|
| public synchronized AsyncEmbeddingModel getOrCreate(String modelName) Returns the cached Consecutive calls with the same
| |