Skip to content

[Perf] #93 — Cache document embeddings in Redis to prevent redundant API/encoding calls - #132

Open
adarsh-gautam-sys wants to merge 1 commit into
devloperdevesh:mainfrom
adarsh-gautam-sys:perf/issue-93-embeddings-cache
Open

[Perf] #93 — Cache document embeddings in Redis to prevent redundant API/encoding calls#132
adarsh-gautam-sys wants to merge 1 commit into
devloperdevesh:mainfrom
adarsh-gautam-sys:perf/issue-93-embeddings-cache

Conversation

@adarsh-gautam-sys

Copy link
Copy Markdown
Contributor

Summary

The RAG pipeline generates document embeddings repeatedly for identical documents and text queries, resulting in redundant encoding work and increased API/computational costs. This PR introduces a Redis caching layer for embeddings, storing the generated vector embeddings with a 24-hour expiration (TTL).

Changes Made

  • app/rag/embeddings.py:
    • Added a synchronous Redis client with connection pooling and a 2s connection timeout.
    • Implemented md5 text-hashing to generate unique cache keys (embedding:{text_hash}).
    • Added lookup and set operations on Redis before/after encoding.
    • Handled exceptions gracefully to fallback to standard encoding in case of connection failure or timeouts.

Related Issue

Closes #93

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

@adarsh-gautam-sys is attempting to deploy a commit to the devloperdevesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] Document Embeddings Not Cached - Redundant API Calls

1 participant