Skip to content

BUG remove_seeds_from_memory(harm_categories=...) deletes seeds whose categories only contain the value as a substring #2808

Description

remove_seeds_from_memory(harm_categories=["hate"]) also deletes seeds tagged hate_speech, and even whatever. The list filters (harm_categories, authors, groups, parameters) go through field.contains(value), which is an unescaped LIKE '%value%' on the JSON text.

For get_seeds the substring match looks intentional (there are tests for it). But the remove methods already default value to an exact match so a short value can't wipe out more than you meant, and the list filters never got the same treatment.

seeds = [SeedPrompt(value="a", harm_categories=["hate"]),
         SeedPrompt(value="b", harm_categories=["hate_speech"]),
         SeedPrompt(value="c", harm_categories=["whatever"])]
await memory.add_seeds_to_memory_async(seeds=seeds, added_by="t")
memory.remove_seeds_from_memory(harm_categories=["hate"])  # removes all 3

Suggested fix: when exact=True (the default for removes), match whole list elements using the existing _get_condition_json_array_match helper, and leave get_seeds as is.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions