Repository navigation
FEAT: Index ScoreEntries by scored message piece - #4120
Merged
Richard Lundeen (richlundeen) merged 5 commits intoNov 11, 2026
Merged
Richard Lundeen (richlundeen) merged 5 commits into
Richard Lundeen (richlundeen) merged 5 commits into
Conversation
Every score read keyed by message piece (conversation messages, attack summaries, `get_prompt_scores_async`) filters `ScoreEntries.prompt_request_response_id`, which had no index. SQL Server does not index foreign keys automatically, so these reads scanned the whole table and grew with it. Adds `ix_ScoreEntries_prompt_request_response_id` to the model and a migration (`c4d1e8b72a90`, revises `d6de1045cca4`). On a small (4k score) database the scored conversation read went from 6.0 s to 5.3 s on Basic; the benefit grows with the table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the score-lookup index change.
No open issues 🎉
What changed in this PR
Adds an index on ScoreEntries.prompt_request_response_id to improve PyRIT’s message-piece score lookups without full-table scans.
Changes:
- Declares the index in the ORM model.
- Adds a reversible migration from
d6de1045cca4. - Adds a SQLite migration test checking index creation and removal.
| File | Description |
|---|---|
tests/unit/memory/test_migration.py |
Tests index creation on upgrade and removal on downgrade. |
pyrit/memory/memory_models.py |
Declares the score lookup index in the ORM model. |
pyrit/memory/alembic/versions/c4d1e8b72a90_index_scores_by_message_piece.py |
Creates and drops the index for existing databases. |
Review effort: Balanced
Justin Song (jsong468)
approved these changes
Nov 10, 2026
Richard Lundeen (richlundeen)
marked this pull request as ready for review
November 10, 2026 05:27
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 10, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 10, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve both existing revisions and cover upgrades from the common parent and either branch. Keep index downgrade coverage independent of the global migration head. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 11, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve both published migration branches and verify upgrades from each head retain the score index, decomposition columns, and dataset lifecycle schema. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Richard Lundeen (richlundeen)
deleted the
richlundeen-score-piece-index
branch
November 11, 2026 04:55
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
Score reads keyed by message piece (conversation messages, attack summaries,
get_prompt_scores_async) filterScoreEntries.prompt_request_response_id, which has no index. SQL Server does not index foreign keys automatically, so these reads scan the whole table, and the cost grows with it.index=TrueonScoreEntry.prompt_request_response_id(ix_ScoreEntries_prompt_request_response_id).c4d1e8b72a90, which revises the current headd6de1045cca4.On a small database (4k scores, Basic tier) the scored conversation read went from 6.0 s to 5.3 s. The gain grows with table size.
Deployments apply the migration through the app-stage migration job, so verify on the test stack first.
🤖 Generated with Claude Code