-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Motivation
In collaborative office suites such as Twake Workplace, documents are updated every hour, such as email threads, notes and chat conversations.
When documents are updated, the embeddings are recomputed by vLLM every time, which can be computationally expensive. This is especially wasteful if the documents are long enough to be split in many chunks.
For more context, see these (LLM-generated) answers on Milvus AI Quick Reference:
- How can caching mechanisms be used in RAG to reduce latency, and what types of data might we cache (embeddings, retrieved results for frequent queries, etc.)?
- How can caching of computed embeddings help improve application performance when using Sentence Transformers repeatedly on the same sentences? (a bit more general)
Solution
The easiest way is to have a chunk -> embedding cache. LangChain provides a simple wrapper around OpenAIEmbeddings: https://python.langchain.com/docs/how_to/caching_embeddings/
The store could be a Redis cache with an eviction strategy such as LRU: https://redis.io/docs/latest/develop/reference/eviction/
The cache has to be cleared on application startup, which is necessary if the embedding API changed in the configuration.
Alternatives
The embedding API could be configured to cache the embeddings. I haven't found how to do this in vLLM and it is not always configurable if using an external API.
Related optimizations
- Prompt caching
- Document retrieval caching