FEAT: Add remove_seeds_from_memory_async to memory#1
Open
blahdeblahde wants to merge 1 commit into
Open
Conversation
Adds an API to remove seed prompts from memory using the same filter parameters as get_seeds (dataset_name, dataset_name_pattern, added_by, harm_categories, authors, groups, source, value_sha256, etc.). Implementation: - Extract filter-building logic from get_seeds into shared _build_seed_filter_conditions helper to prevent drift - Add remove_seeds_from_memory_async that uses the shared helper - Require at least one filter (raises ValueError if none provided) - Single transaction with rollback on failure - Works across DuckDB, SQLite, Azure SQL (uses SQLAlchemy ORM) Unit tests cover: exact name filter, LIKE pattern, multi-filter narrowing, no-filter ValueError, zero-match return, harm_categories, and source filter. Docs: add a 'Removing Seeds from the Database' section to the seed database notebook (8_seed_database.py/.ipynb) demonstrating the preview-then-remove workflow. Resolves AB#5688 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f9e3cc10-5c77-4384-92d9-d27dad9baea2
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
PyRIT can add seed prompt datasets to memory but offers no API to remove them — users have had to fall back to raw SQL, which is error-prone across backends (DuckDB, SQLite, Azure SQL).
This PR adds
remove_seeds_from_memory_async, which accepts the same filter parameters asget_seeds(dataset_name,dataset_name_pattern,added_by,harm_categories,authors,groups,source,value_sha256, etc.) and returns the number of seeds removed.Recommended workflow: call
get_seeds(...)first to preview what will be deleted, then callremove_seeds_from_memory_async(...)with the same filters.Implementation
get_seedsinto a shared_build_seed_filter_conditionshelper, so both methods stay in sync and cannot drift.remove_seeds_from_memory_asyncbuilds conditions via the shared helper, then deletes matching rows in a single transaction (rollback on error) using the SQLAlchemy ORM so it works uniformly on DuckDB, SQLite, and Azure SQL.Safety
ValueErrorto prevent accidentally deleting the entire seed database.Resolves AB#5688
Tests and Documentation
Tests — added
tests/unit/memory/memory_interface/test_interface_remove_seeds.pycovering:dataset_namematchdataset_name_pattern(SQL LIKE)dataset_name+added_by)ValueError0and deletes nothingharm_categories(list field) andsourcefiltersDocumentation — added a "Removing Seeds from the Database" section to the seed database notebook (
doc/code/memory/8_seed_database.pyand.ipynb) demonstrating the preview-then-remove workflow. The.py/.ipynbpair was verified in sync with jupytext.Note
Unit tests and JupyText were not executed locally — the package fails to build on the author's ARM64 / Python 3.14 machine (cryptography/pyarrow wheels). Please rely on CI to confirm green.