Embed a list of texts.
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.
Parameters
texts – A list of texts to embed.
Returns
A list of embeddings for the given texts.
embed_query(text: str) → List[float][source]¶
Embed query text.
This method does not support caching at the moment.
Support for caching queries is easily to implement, but might make
sense to hold off to see the most common patterns.
If the cache has an eviction policy, we may need to be a bit more careful
about sharing the cache between documents and queries. Generally,
one is OK evicting query caches, but document caches should be kept.
Parameters
text – The text to embed.
Returns
The embedding for the given text.
classmethod from_bytes_store(underlying_embeddings: Embeddings, document_embedding_cache: BaseStore[str, bytes], *, namespace: str = '') → CacheBackedEmbeddings[source]¶
On-ramp that adds the necessary serialization and encoding to the store.
Parameters
underlying_embeddings – The embedder to use for embedding.
document_embedding_cache – The cache to use for storing document embeddings.
* – 
:param :
:param namespace: The namespace to use for document cache.
This namespace is used to avoid collisions with other caches.
For example, set it to the name of the embedding model used.
Examples using CacheBackedEmbeddings¶
Caching