Skip to content

Feature request: cache document embeddings #34

@slivering

Description

@slivering

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions