fix: isolate embedding cache by model and prefix - #213
Open
Daniel Peng (original4422) wants to merge 1 commit into
Open
fix: isolate embedding cache by model and prefix#213Daniel Peng (original4422) wants to merge 1 commit into
Daniel Peng (original4422) wants to merge 1 commit into
Conversation
Copilot started reviewing on behalf of
Daniel Peng (original4422)
August 19, 2026 19:08
View session
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness issue in the Python EmbeddingSimilarity scorer where its class-level embedding cache could be inadvertently shared across different configurations, leading to cross-model / cross-prefix cache poisoning. It aligns with the library’s goal of providing reliable, deterministic evaluators by ensuring cached embedding results are only reused when the embedding request configuration matches.
Changes:
- Introduces a shared cache-key function for
EmbeddingSimilarityand keys the cache by(model, prefix, normalized_input). - Applies the same cache-keying behavior to both sync and async embedding paths.
- Adds regression tests to confirm cache isolation across models/prefixes and cache hits within the same configuration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| py/autoevals/string.py | Fixes EmbeddingSimilarity cache keying to prevent cross-configuration reuse and shares key logic between sync/async paths. |
| py/autoevals/test_embeddings.py | Adds deterministic regression tests (sync + async) and a per-test cache reset fixture to validate isolation and same-config cache hits. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
Root cause
EmbeddingSimilarityused only the normalized input as its class-level cache key even though the embedding request also depends onmodelandprefix. Instances with different configurations could therefore reuse vectors produced by another model or prefixed input.Validation
pytest py/autoevals/test_embeddings.py -k 'cache_isolated' -q(2 passed)pytest py/autoevals/test_values.py py/autoevals/test_json.py -q(8 passed)pre-commit run --all-filespython -m buildpython -m twine check dist/*The full local suite completed with 72 passed and 17 integration failures because OpenAI/Braintrust API credentials are unavailable locally; those failures stop at client initialization and do not exercise this cache change.
Fixes #211