CacheBackedEmbeddings.fromByteStore constructor
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.
underlyingEmbeddings
is the embedder to use for computing embeddings.documentEmbeddingsStore
is the store to use for caching embeddings.namespace
is the namespace to use for the cache. This namespace is used to avoid collisions of the same text embedded using different embeddings models. For example, you can set it to the name of the embedding model used.
Example:
final cacheBackedEmbeddings = CacheBackedEmbeddings.fromByteStore(
underlyingEmbeddings: OpenAIEmbeddings(apiKey: openaiApiKey),
documentEmbeddingsStore: InMemoryStore(),
namespace: 'text-embedding-3-small',
);
Implementation
factory CacheBackedEmbeddings.fromByteStore({
required final Embeddings underlyingEmbeddings,
required final BaseStore<String, Uint8List> documentEmbeddingsStore,
final String namespace = '',
}) {
return CacheBackedEmbeddings(
underlyingEmbeddings: underlyingEmbeddings,
documentEmbeddingsStore: EncoderBackedStore(
store: documentEmbeddingsStore,
encoder: EmbeddingsByteStoreEncoder(namespace: namespace),
),
);
}