langchain.embeddings.cache.CacheBackedEmbeddings¶
class langchain.embeddings.cache.CacheBackedEmbeddings(underlying_embeddings: Embeddings, document_embedding_store: BaseStore[str, List[float]])[source]¶
Interface for caching results from embedding models.
The interface allows works with any store that implements
the abstract store interface accepting keys of type str and values of list of
floats.
If need be, the interface can be extended to accept other implementations
of the value serializer and deserializer, as well as the key encoder.
Examples
Initialize the embedder.
Parameters
underlying_embeddings – the embedder to use for computing embeddings.
document_embedding_store – The store to use for caching document embeddings.
Methods
__init__(underlying_embeddings, ...)
Initialize the embedder.
aembed_documents(texts)
Asynchronous Embed search docs.
aembed_query(text)
Asynchronous Embed query text.
embed_documents(texts)
Embed a list of texts.
embed_query(text)
Embed query text.
from_bytes_store(underlying_embeddings, ...)
On-ramp that adds the necessary serialization and encoding to the store.
__init__(underlying_embeddings: Embeddings, document_embedding_store: BaseStore[str, List[float]]) → None[source]¶
Initialize the embedder.
Parameters
underlying_embeddings – the embedder to use for computing embeddings.
document_embedding_store – The store to use for caching document embeddings.
async aembed_documents(texts: List[str]) → List[List[float]]¶
Asynchronous Embed search docs.
async aembed_query(text: str) → List[float]¶
Asynchronous Embed query text.
embed_documents(texts: List[str]) → List[List[float]][source]¶
Embed a list of texts.
The method first checks the cache for the embeddings.