embeddings in a key-value store. The text is hashed and the hash is used as the key in the cache.The main supported way to initialized a CacheBackedEmbeddings is from_bytes_store. This takes in the following parameters:underlying_embedder: The embedder to use for embedding.document_embedding_cache: The cache to use for storing document embeddings.namespace: (optional, defaults to "") 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.Attention: Be sure to set the namespace parameter to avoid collisions of the same text embedded using different embeddings models.from langchain.storage import InMemoryStore, LocalFileStore, RedisStore, UpstashRedisStorefrom langchain.embeddings import OpenAIEmbeddings, CacheBackedEmbeddingsUsing with a vector store‚ÄãFirst, let's see an example that uses the local file system for storing embeddings and uses FAISS vector store for retrieval.from langchain.document_loaders import TextLoaderfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.text_splitter import CharacterTextSplitterfrom langchain.vectorstores import FAISSunderlying_embeddings = OpenAIEmbeddings()fs = LocalFileStore("./cache/")cached_embedder = CacheBackedEmbeddings.from_bytes_store(    underlying_embeddings, fs, namespace=underlying_embeddings.model)The cache is empty prior to embedding:list(fs.yield_keys())    []Load the document, split it into chunks, embed each chunk and load it into the vector store.raw_documents = TextLoader("../state_of_the_union.txt").load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)documents = text_splitter.split_documents(raw_documents)Create the vector store:db = FAISS.from_documents(documents, cached_embedder)    CPU times: user 608 ms, sys: 58.9 ms, total: 667 ms    Wall time: 1.3 sIf we try to create the vector store again, it'll be much faster since it does not need to re-compute any
Embeddings can be stored or temporarily cached to avoid needing to recompute them.
Embeddings can be stored or temporarily cached to avoid needing to recompute them. ->: embeddings in a key-value store. The text is hashed and the hash is used as the key in the cache.The main supported way to initialized a CacheBackedEmbeddings is from_bytes_store. This takes in the following parameters:underlying_embedder: The embedder to use for embedding.document_embedding_cache: The cache to use for storing document embeddings.namespace: (optional, defaults to "") 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.Attention: Be sure to set the namespace parameter to avoid collisions of the same text embedded using different embeddings models.from langchain.storage import InMemoryStore, LocalFileStore, RedisStore, UpstashRedisStorefrom langchain.embeddings import OpenAIEmbeddings, CacheBackedEmbeddingsUsing with a vector store‚ÄãFirst, let's see an example that uses the local file system for storing embeddings and uses FAISS vector store for retrieval.from langchain.document_loaders import TextLoaderfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.text_splitter import CharacterTextSplitterfrom langchain.vectorstores import FAISSunderlying_embeddings = OpenAIEmbeddings()fs = LocalFileStore("./cache/")cached_embedder = CacheBackedEmbeddings.from_bytes_store(    underlying_embeddings, fs, namespace=underlying_embeddings.model)The cache is empty prior to embedding:list(fs.yield_keys())    []Load the document, split it into chunks, embed each chunk and load it into the vector store.raw_documents = TextLoader("../state_of_the_union.txt").load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)documents = text_splitter.split_documents(raw_documents)Create the vector store:db = FAISS.from_documents(documents, cached_embedder)    CPU times: user 608 ms, sys: 58.9 ms, total: 667 ms    Wall time: 1.3 sIf we try to create the vector store again, it'll be much faster since it does not need to re-compute any