Repository navigation
fix(rag): isolate embedding caches by workspace - #45226
Open
Zhi-Xiang-Guo wants to merge 1 commit into
Open
Zhi-Xiang-Guo wants to merge 1 commit into
Zhi-Xiang-Guo wants to merge 1 commit into
Conversation
Open
6 tasks done
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.
Fixes #45223
Summary
Two workspaces can configure the same embedding provider/model name with different endpoints. Previously, both the persistent document cache and Redis query cache could return the other workspace's vectors. With real CLIP (512 dimensions) in workspace A and BGE (384 dimensions) in B, this caused retrieval to fail with
expected dim: 512, got 384or the inverse error.Scope cache identities by workspace for text and image embedding paths. The same API reproduction now returns HTTP 200 for both previously failing requests, with nonempty retrieval records; the fresh-query control also remains successful.
Changes Made
api/core/rag/embedding/cached_embedding.py:api/core/rag/datasource/vdb/vector_factory.py:api/core/rag/rerank/weight_rerank.py:Compatibility and recovery: no database schema migration is required. Upgrade the API and indexing workers together. The new document hashes and Redis namespace do not read legacy unscoped entries, so recovery does not depend on their expiry. Existing document-cache entries remain for the normal cleanup job; Redis TTL is sliding and refreshes on hits, so 600 seconds is an idle interval, not a guaranteed lifetime since creation.
This prevents new cross-workspace contamination but does not automatically repair vectors already stored in knowledge-base collections. On the old code, waiting for Redis expiry or merely re-running indexing can reuse the incompatible persistent cache. After upgrading all relevant processes, affected indexes/collections must be rebuilt from source with the intended model. A collection created with the wrong dimensionality may need recreation, rather than only replacing document points. The deployed validation below uses newly created datasets and does not claim an end-to-end repair of existing contaminated collections. Changing an embedding endpoint/configuration within one workspace and model load balancing remain outside this patch's scope.
Unit Tests
test_workspace_cache.py, covering text/image document and query isolation, same-dimensional different vectors, different dimensions, same-workspace reuse, and rejection of legacy unscoped cache entries. All 12 fail on the original production code and pass with the fix. Persistent-cache tests use real SQLite; model invocations and Redis are mocked in these unit tests.git diff --checkpassed.main@5336037aa91f07188baaf03957effd57a364f7df; tested local commit:674687a46bf29db11ffb147551f6d997b83debb4. Remote head5e3990a7728d025b425ecd77dabcf60b3aa78298has the exact same Git tree (0a877b1e748d68ce491bd43eac480132ed7a1ab3); commit metadata differs because the branch was uploaded through the GitHub connector.Checklist
make lint && make type-check/ full test suite completed. Only the focused checks listed above were run; no frontend changes.action_required; no remote test-pass result is claimed.