Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.ai.embedding

public Class EmbeddingModelCache

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
java.util.HashMap, .Map, org.jabref.logic.ai.preferences.AiPreferences, org.jabref.logic.util.NotificationService, .TaskExecutor

Session-scoped cache for 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.jabref.logic.ai.ingestion.tasks.UpdateEmbeddingModelTask for every listener.

Implements AutoCloseable; call close() (e.g. in AiService.close()) to release all cached model resources.

Field Summary

Modifier and TypeField and Description
private final AiPreferences
private final Map<String, AsyncEmbeddingModel>
private final EmbeddingModelMetadataService
private final NotificationService
private final TaskExecutor

Constructor Summary

AccessConstructor and Description
public
EmbeddingModelCache(AiPreferences aiPreferences, NotificationService notificationService, TaskExecutor taskExecutor, EmbeddingModelMetadataService metadataService)

Method Summary

Modifier and TypeMethod and Description
public synchronized void
close()

Implements java.lang.AutoCloseable.close.

Closes all cached AsyncEmbeddingModel instances and clears the cache.

public synchronized AsyncEmbeddingModel

Returns:

a (possibly still-loading) AsyncEmbeddingModel for modelName
getOrCreate
(String
the requested embedding model name
modelName
)

Returns the cached AsyncEmbeddingModel for modelName, creating it on first access.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aiPreferencesback to summary
private final AiPreferences aiPreferences
cacheback to summary
private final Map<String, AsyncEmbeddingModel> cache
metadataServiceback to summary
private final EmbeddingModelMetadataService metadataService
notificationServiceback to summary
private final NotificationService notificationService
taskExecutorback to summary
private final TaskExecutor taskExecutor

Constructor Detail

EmbeddingModelCacheback to summary
public EmbeddingModelCache(AiPreferences aiPreferences, NotificationService notificationService, TaskExecutor taskExecutor, EmbeddingModelMetadataService metadataService)

Method Detail

closeback to summary
public synchronized void close()

Implements java.lang.AutoCloseable.close.

Closes all cached AsyncEmbeddingModel instances and clears the cache.

Should be called once the AI subsystem is shut down (i.e. from AiService.close()).

Annotations
@Override
getOrCreateback to summary
public synchronized AsyncEmbeddingModel getOrCreate(String modelName)

Returns the cached AsyncEmbeddingModel for modelName, creating it on first access.

Consecutive calls with the same modelName return the same instance; no additional background tasks are launched. Requesting another model name closes and evicts that instance, so a later request for modelName creates a new one.

Parameters
modelName:String

the requested embedding model name

Returns:AsyncEmbeddingModel

a (possibly still-loading) AsyncEmbeddingModel for modelName