EmbeddingModelCache class final
The local copy of a pinned embedding model, in one cache directory.
locate never touches the network. provision is the only call that downloads, so a host makes it only after the user agrees to fetch the target. A download goes to a temporary file in directory, and only a file whose size and SHA-256 match the pin is renamed into place. Several processes may provision one directory at once: each writes its own temporary file, and every rename installs the same bytes.
Failures are WayfinderExceptions with these codes:
model-download-failedfor a network error, a response other than 200, or a download that receives nothing for stallTimeout;model-invalidwhen the downloaded size or SHA-256 differs from the pin, or the response announces a size other than the pinned one;model-cache-unavailablewhen the cache directory cannot be created or written, something other than the model is in the way of the target, or remove cannot delete the model;cancelledwhen theWayfinderCancellationpassed to provision stops it;data-directory-unavailablefrom the default constructor, when nodataDirectoryis given and the Wayfinder data directory cannot be located.
Constructors
- EmbeddingModelCache({Directory? dataDirectory, EmbeddingModelSpec spec = localEmbeddingModel, Client? client, Duration stallTimeout = const Duration(minutes: 1)})
-
A cache of
specinmodels/<id>ofdataDirectory, by default the Wayfinder data directory (WayfinderDataDirectory.resolve), beside its indexes and Profiles. - EmbeddingModelCache.inDirectory(Directory directory, {EmbeddingModelSpec spec = localEmbeddingModel, Client? client, Duration stallTimeout = const Duration(minutes: 1)})
-
A cache of
specindirectoryitself.
Properties
- directory → Directory
-
Holds the model and, during a download, its temporary file.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- spec → EmbeddingModelSpec
-
final
- stallTimeout → Duration
-
How long a download may wait for a response, or for its next bytes,
before it fails.
final
- target → EmbeddingModelTarget
-
The pinned model and its place in directory.
no setter
Methods
-
locate(
{Iterable< File> alsoCheck = const []}) → Future<File?> -
The first verified copy of the model: the cache's own, then each of
alsoCheckin order, such as the model an installed Wayfinder bundle ships. Returns null when none matches the pinned size and SHA-256. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
provision(
{WayfinderCancellation? cancel}) → Stream< ModelProvisionProgress> - Installs the verified model in directory unless it is already there.
-
remove(
) → Future< List< String> > - Deletes the model at the target and the temporary files of this cache's downloads, and returns the paths it deleted. It reads and deletes files only, never touches the network, and deletes a file at the target whether or not it verifies. The cache directory stays.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
removeAbandonedDownloads(
Directory dataDirectory) → Future< List< String> > -
Deletes the temporary files of downloads into the default cache
directories,
models/<id>/underdataDirectory, that stopped at least a day ago without removing them, such as one whose process was killed, whatever model they were for, and returns their paths. provision does the same for its own model; this serves a host that cleans its data directory without provisioning again. A download in progress writes far more often, so its file is kept.