Repository navigation
perf(genai): cache PDF embeddings with bounded content reuse - #250
Open
divyanshAgarwal123 wants to merge 1 commit into
Open
divyanshAgarwal123 wants to merge 1 commit into
divyanshAgarwal123 wants to merge 1 commit into
Conversation
Signed-off-by: Divyansh agarwal <85987665+divyanshAgarwal123@users.noreply.github.com>
Contributor
Author
|
@TheCodeHeist-Coder, #244 is implemented with 43 passing Python tests and the requested real-CPU before/after timing in the PR. The repeated PDF-to-store phase measured 519.792 ms uncached versus 3.756 ms on a warm cache, with no second document-embedding call; model startup and LLM time are excluded. Could you carry the existing |
TheCodeHeist-Coder
approved these changes
Nov 25, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Repeated
/ask-pdfuploads of identical bytes now reuse document embeddings even when their temporary filenames differ. A SHA-256/model/chunk-configuration key identifies each PDF snapshot. The in-process LRU retains at most four PDFs / 2,000 total chunks; oversized stores serve the current flight without retention. Concurrent misses share a build, failures release all waiters for a later retry, and model initialization is serialized.The cache strips source paths and returns independent record/vector/metadata copies with the current request's path. Hashing and parsing use the same bytes. Temporary uploads are still removed. Cached PDF text/vectors remain in RAM until eviction or restart; each process starts cold. There is no disk/shared cache or TTL. Query embedding and LLM answering still run per question; quiz generation's separate context-window issue is unchanged.
Related issue
Closes #244.
Type of change
Which services does this touch?
apps/genAIHow did you test this?
Python3.11.15, canonical
requirements-dev.txt: 43 pytest tests pass (31 parent + 12 new). Ruff passes forappand both new test/benchmark modules; compileall and staged secret scan pass. Regressions cover renamed/changed PDFs, immutable snapshots, model/chunk key changes, mutable-record/source isolation, both LRU limits, oversized bypass, concurrent miss plus eviction, failure fan-out/retry, concurrent model initialization and two actual multipart/ask-pdftest-client uploads with cleanup. The regular suite uses fake providers and the real vector-store implementation.Real CPU fastembed
BAAI/bge-small-en-v1.5, arm64, one synthetic20,144-byte PDF / 30 chunks, same initialized/warmed model:Reproduce with
.venv/bin/python -m tests.benchmark_pdf_cache. This opt-in script downloads the model if absent. Model load/warmup, query embedding and LLM generation are excluded from timing; these numbers are not whole-request latency or a production guarantee. Immutable source/parent/environment and four-artifact verification manifest.Hosted CI run45509929479 passed all10 reported jobs on
aa3af64ff4788fb1a756ad2e8e00a7cbee93f1ad, including allfive container builds. Every executed step reported success; no failure was hidden by a continued step. Local monorepo/Compose checkboxes below remain accurately unticked. Maintainer review and carrying over the issue grading labels are still pending.Checklist
pnpm run lintpnpm run check-typespnpm run builddocker-compose up.env, API keys or secrets committedThe monorepo/Docker boxes are left unchecked: this scoped Python change was validated with the full GenAI tests, Ruff and compileall rather than claiming unrun frontend/Node/Compose checks. No dependencies, schemas, workflows or thresholds changed.