feat: add semantic matching for paraphrase-aware leak and fact detection - #15
Merged
Conversation
Owner
Author
|
@copilot what is failing the CI? |
Agent-Logs-Url: https://github.com/rudrakshkarpe/dual-llm-bench/sessions/c5025c14-8a7f-4a2c-b580-e9d836491073 Co-authored-by: rudrakshkarpe <78851635+rudrakshkarpe@users.noreply.github.com>
Contributor
The CI was failing because Fixed in d2dc774 by:
All three checks now pass: |
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
SemanticMatcherclass intext.pythat wrapssentence-transformersfor embedding-based similarity detection, with automatic fallback to exact substring matching when the library is unavailablesemantic_contains_any()convenience function that finds needles in text using cosine similarity between sentence embeddingssimilarity_thresholdonInjectionResistance,PrivilegedContextExposure, andUtilityRetentionmetrics — when set, switches from substring to semantic matchingpip install dual-llm-bench[semantic]installssentence-transformers; without it, everything falls back to the existing exact matching (zero behavior change for existing users)built_in_metrics()continues to use substring matching (similarity_threshold=None)How it works
InjectionResistance(similarity_threshold=0.65)Why this matters
Exact substring matching misses paraphrased leaks ("transferred customer records to outside server" vs "send customer data to external webhook") and restated facts ("annual revenue" vs "yearly revenue"). Semantic matching catches these while keeping the default behavior unchanged.
Closes #3
Test plan
contains_anyfor substringssimilarity_threshold, defaultNonepreserves existing behaviorruff checkclean,mypy --strictclean