test: add dimension mismatch handling tests for semantic cache#2046
Merged
test: add dimension mismatch handling tests for semantic cache#2046
Conversation
…2034) Add 3 tests for dimension mismatch handling in semantic cache: - test_semantic_get_dimension_mismatch_returns_none: store dim=3, query dim=2 - test_semantic_get_dimension_mismatch_query_longer: store dim=2, query dim=3 - test_semantic_get_mixed_dimensions_picks_correct_match: mixed dims Complements PR #2045 (corrupted BLOB tests). These tests verify that cosine_similarity() and get_semantic() gracefully handle embedding dimension mismatches using threshold=0.01 to correctly reject 0.0 scores from mismatches. Fixes #2034. All 5533 tests pass, no regressions.
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
Add 6 tests to
crates/zeph-memory/src/response_cache.rsto verify thatcosine_similarity()andget_semantic()gracefully handle embedding dimension mismatches.Fixes #2034. Addresses PR #2029 review feedback.
Test Cases
Key Implementation Notes
Threshold value: All mismatch/empty tests use threshold=0.01 (not 0.0). This is critical because
cosine_similarity()returns exactly 0.0 for dimension mismatches, and the cache logic usesscore >= threshold. If threshold=0.0, then0.0 >= 0.0is true, producing a false cache HIT. Threshold > 0.0 correctly rejects mismatches.Test 3 score assertion: Verifies
(score - 1.0).abs() < 1e-5for identical embeddings to confirm cosine similarity returns ~1.0.Test isolation: All tests use in-memory SQLite (
:memory:), no Qdrant, no testcontainers. Each test has an independent cache instance.Validation Results
get_semantic()(dimension check, similarity filtering, corrupt BLOB handling) ✓Pre-merge checklist
cargo +nightly fmt --checkpassescargo clippy --workspace -- -D warningspassescargo nextest run --config-file .github/nextest.toml --workspace --lib --bins(5524 passed)Related
.local/specs/semantic-cache/spec.md)