-
Notifications
You must be signed in to change notification settings - Fork 825
FEAT: Add remove_seeds_from_memory_async to memory #2243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blahdeblahde
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
blahdeblahde:blahdeblahde-remove-seeds-from-memory-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,3 +113,39 @@ def print_group(seed_group): | |
| seed_groups = memory.get_seed_groups(data_types=["image_path"], dataset_name="pyrit_example_dataset") | ||
| print("----------") | ||
| print_group(seed_groups[0]) | ||
|
|
||
| # %% [markdown] | ||
| # ## Removing Seeds from the Database | ||
| # | ||
| # Just as you can add and query seeds, you can remove them using `remove_seeds_from_memory`. It accepts the same filtering parameters as `get_seeds` (plus an `exact` flag), so the recommended workflow is to preview the matching seeds with `get_seeds(...)` first, then remove them with the same filters. The method returns the number of seeds removed. | ||
| # | ||
| # As a safety measure, at least one filter must be provided. Calling it with no filters raises a `ValueError` to prevent accidentally deleting the entire seed database. | ||
|
|
||
| # %% | ||
| # Preview the seeds that will be removed using the same filters | ||
| seeds_to_remove = memory.get_seeds(dataset_name="pyrit_example_dataset") | ||
| print(f"Seeds matching the filter: {len(seeds_to_remove)}") | ||
|
|
||
| # Remove them and get back the number of seeds deleted | ||
| removed_count = memory.remove_seeds_from_memory(dataset_name="pyrit_example_dataset") | ||
| print(f"Removed {removed_count} seeds") | ||
|
|
||
| # Confirm they are gone | ||
| seeds = memory.get_seeds(dataset_name="pyrit_example_dataset") | ||
| print(f"Seeds remaining in dataset: {len(seeds)}") | ||
|
|
||
| # %% [markdown] | ||
| # ### Removing entire groups | ||
| # | ||
| # `remove_seeds_from_memory` deletes only the individual seeds that match your filters. Because a seed group (for example a multimodal prompt made of text plus an image, or a multi-turn conversation) is stored as several seeds sharing a `prompt_group_id`, filtering by a single modality or attribute can leave a **partial group** behind. Some consequences to be aware of: | ||
| # | ||
| # - Deleting the sole objective while leaving its prompts produces an invalid `AttackSeedGroup`, and scenario initialization will raise a `ValueError`. | ||
| # - Deleting one modality (e.g. the image) leaves a group that is still valid but now sends only text. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove since it's not an actual error |
||
| # - Deleting one turn of a multi-turn conversation leaves the group with an incomplete context. | ||
| # - Deleting the only role-bearing prompt in a sequence can cause a surviving multi-sequence group to fail role validation. | ||
| # | ||
| # For the most part these are user errors, but when you want to remove whole groups rather than individual seeds, use `remove_seed_groups_from_memory`. It applies the same filters, but removes every seed that shares a `prompt_group_id` with any match, so groups are never left partial. Note that it only affects seeds that belong to a group: a matching seed added individually (with no `prompt_group_id`) is skipped, so use `remove_seeds_from_memory` for those. | ||
| # | ||
| # > **Note on deleting by `value`.** For the remove methods, the `value` filter defaults to full-string equality (`exact=True`), so `remove_seeds_from_memory(value="the")` deletes only seeds whose value is exactly `"the"` — not everything containing it. This differs from `get_seeds`, which always matches `value` by substring. Pass `exact=False` to opt into substring deletion when you really want it. As a general rule, preview with the same filters via `get_seeds(...)` first and prefer a specific filter (such as `dataset_name` or `value_sha256`) for deletion. | ||
| # | ||
| # > **Note on file-backed seeds.** For `image_path`, `audio_path`, and `video_path` seeds, removal deletes only the database record; the serialized file on disk is left in place. Delete those files separately if they are no longer needed. | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe add something about exact, even like see documentation or something like that, mostly bc youre mentioning it in (plus an
exactflag)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see below! i might just not mention the parameters here but this is a super nit so i'll leave it to you