Skip to content

FEAT: Add remove_seeds_from_memory_async to memory#1

Open
blahdeblahde wants to merge 1 commit into
mainfrom
blahdeblahde-remove-seeds-from-memory-api
Open

FEAT: Add remove_seeds_from_memory_async to memory#1
blahdeblahde wants to merge 1 commit into
mainfrom
blahdeblahde-remove-seeds-from-memory-api

Conversation

@blahdeblahde

Copy link
Copy Markdown
Owner

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 as get_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 call remove_seeds_from_memory_async(...) with the same filters.

Implementation

  • Refactored the filter-building logic out of get_seeds into a shared _build_seed_filter_conditions helper, so both methods stay in sync and cannot drift.
  • remove_seeds_from_memory_async builds 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

  • At least one filter must be provided. A no-filter call raises ValueError to prevent accidentally deleting the entire seed database.

Resolves AB#5688

Tests and Documentation

Tests — added tests/unit/memory/memory_interface/test_interface_remove_seeds.py covering:

  • exact dataset_name match
  • dataset_name_pattern (SQL LIKE)
  • multi-filter narrowing (dataset_name + added_by)
  • no-filter call raises ValueError
  • zero-match returns 0 and deletes nothing
  • harm_categories (list field) and source filters

Documentation — added a "Removing Seeds from the Database" section to the seed database notebook (doc/code/memory/8_seed_database.py and .ipynb) demonstrating the preview-then-remove workflow. The .py/.ipynb pair 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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant