Skip to content

FEAT: Index ScoreEntries by scored message piece - #4120

Merged
Richard Lundeen (richlundeen) merged 5 commits into
microsoft:mainfrom
richlundeen:richlundeen-score-piece-index
Nov 11, 2026
Merged

Richard Lundeen (richlundeen) merged 5 commits into
microsoft:mainfrom
richlundeen:richlundeen-score-piece-index

Conversation

@richlundeen

Copy link
Copy Markdown
Contributor

Description

Score reads keyed by message piece (conversation messages, attack summaries, get_prompt_scores_async) filter ScoreEntries.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.

  • Adds index=True on ScoreEntry.prompt_request_response_id (ix_ScoreEntries_prompt_request_response_id).
  • Adds migration c4d1e8b72a90, which revises the current head d6de1045cca4.
  • The migration test upgrades to head, checks the index, then downgrades one step and checks that it's gone.

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

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>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 20:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@richlundeen
Richard Lundeen (richlundeen) marked this pull request as ready for review November 10, 2026 05:27
@richlundeen
Richard Lundeen (richlundeen) added this pull request to the merge queue Nov 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 10, 2026
@richlundeen
Richard Lundeen (richlundeen) added this pull request to the merge queue Nov 10, 2026
@github-merge-queue
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>
@richlundeen
Richard Lundeen (richlundeen) added this pull request to the merge queue Nov 11, 2026
@github-merge-queue
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>
@richlundeen
Richard Lundeen (richlundeen) added this pull request to the merge queue Nov 11, 2026
Merged via the queue into microsoft:main with commit 65b2b38 Nov 11, 2026
61 checks passed
@richlundeen
Richard Lundeen (richlundeen) deleted the richlundeen-score-piece-index branch November 11, 2026 04:55
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.

3 participants