CacheBackedEmbeddings class
Wrapper around an embedder that caches embeddings in a key-value store to avoid recomputing embeddings for the same text.
When embedding a new document, the method first checks the cache for the embeddings. If the embeddings are not found, the method uses the underlying embedder to embed the documents and stores the results in the cache.
The factory constructor CacheBackedEmbeddings.fromByteStore can be used to create a cache backed embeddings that uses a EncoderBackedStore which generates the keys for the cache by hashing the text.
You can use a InMemoryStore (mainly for testing or prototyping), a LocalFileStore or your custom implementation of BaseStore.
The CacheBackedEmbeddings.embedQuery method does not support caching at the moment.
- Implemented types
Constructors
-
CacheBackedEmbeddings.new({required Embeddings underlyingEmbeddings, required BaseStore<
String, List< documentEmbeddingsStore})double> > -
Wrapper around an embedder that caches embeddings in a key-value store to
avoid recomputing embeddings for the same text.
const
-
CacheBackedEmbeddings.fromByteStore({required Embeddings underlyingEmbeddings, required BaseStore<
String, Uint8List> documentEmbeddingsStore, String namespace = ''}) -
Create a cache backed embeddings that uses a EncoderBackedStore which
generates the keys for the cache by hashing the text.
factory
Properties
-
documentEmbeddingsStore
→ BaseStore<
String, List< double> > -
The store to use for caching embeddings.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- underlyingEmbeddings → Embeddings
-
The embedder to use for computing embeddings.
final
Methods
-
embedDocuments(
List< Document> documents) → Future<List< List< >double> > -
Embed search docs.
override
-
embedQuery(
String query) → Future< List< double> > -
Embed query text.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited