EmbeddingCache class

Persistent embedding cache with content-based invalidation.

Features:

  • Disk persistence via JSON serialization
  • Content hash-based cache invalidation
  • LRU eviction when cache exceeds size limit
  • Fast similarity search across all cached embeddings

Constructors

EmbeddingCache({required String cachePath, int maxEntries = 10000})

Properties

hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether the cache is empty.
no setter
keys Iterable<String>
All cached function IDs.
no setter
maxEntries int
Maximum number of entries before eviction.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
Number of cached entries.
no setter

Methods

clear() → void
Clears all cached entries.
contains(String functionId, String contentHash) bool
Checks if a function is cached with the given content hash.
findSimilar(List<double> queryEmbedding, {double threshold = 0.85, int limit = 10, String? excludeId}) List<SimilarityResult>
Finds all functions with similarity above threshold.
get(String functionId, String contentHash) List<double>?
Gets embedding for a function, or null if not cached or invalidated.
getStats() CacheStats
Gets cache statistics.
load() Future<void>
Loads cache from disk if it exists.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String functionId, String contentHash, List<double> embedding) → void
Stores embedding for a function.
remove(String functionId) → void
Removes a function from the cache.
save() Future<void>
Saves cache to disk.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

computeHash(String code) String
Computes content hash for cache invalidation.