Repository navigation
FIX: Match get_scores score_category against each stored category - #3622
Open
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Open
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Conversation
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.
Description
memory.get_scores_async(score_category="refusal")(and the deprecatedget_scores) never returns a score.Score.score_categoryis a list, andScoreEntrystores it in a JSON column, but_execute_get_scorescompared the whole column with the argument (ScoreEntry.score_category == score_category). A stored["refusal"]is never equal to"refusal", so every category query by name comes back empty (reproduced on SQLite; Azure SQL builds the same whole-column comparison). Only an argument equal to the whole stored value matched, such as the complete list in its stored order.This PR builds the condition with
_add_list_conditions(..., exact=True), the helper behind the seed list filters (harm_categories,authors,groups), in its whole-element mode. A query now returns the scores whose category list contains the requested name as a whole element, compared case-insensitively as that mode does:"hate"matches["hate"]and["violence", "hate"], but not["hate_speech"]. A list argument keeps working and returns the scores that list every given category, in any order. The parameter type is nowstr | Sequence[str] | None, and the docstrings say how it matches.Real run: two
SubStringScorers score two stored assistant replies inIN_MEMORYmemory, then the scores are read back:Tests and Documentation
Added
test_get_scores_by_score_categorytotests/unit/memory/memory_interface/test_interface_scores.py. It stores scores with["hate"],["violence", "hate"],["hate_speech"],["HaTe"],Noneand[]and checks whole-element matching, case folding,"speech"matching nothing, stored empty andNonecategories not matching the queried category names, a list argument, and the intersection withscore_type. It fails on main (the first query returns[]).pytest tests/unit/memory: 1923 passed, 1 skipped.ruff check,ruff format --check(0.17.1) andty checkon the changed files pass.