[DRAFT] Persist identifiers in DB#2164
Conversation
|
I wonder if we can figure out how to not repeat the promoted values 3x per identifier. Here is a way that copilot brainstormed that shows promise: The promotion metadata already lives on the identifier ( 1. Expose a public accessor on the domain model
# component_identifier.py
@classmethod
def promoted_scalar_field_names(cls) -> tuple[str, ...]:
"""Names of this identifier's promoted scalar (param) fields — the DB-column projection."""
return cls._promoted_param_fields()
def promoted_scalar_values(self) -> dict[str, Any]:
"""This identifier's promoted scalar fields as ``{name: value}`` (children/targets excluded)."""
return {name: getattr(self, name) for name in self._promoted_param_fields()}For 2. Make
|
| @@ -459,6 +462,13 @@ def _insert_conversation(self, *, conversation: Conversation) -> None: | |||
| try: | |||
| existing = session.get(ConversationEntry, conversation.conversation_id) | |||
| if existing is None: | |||
There was a problem hiding this comment.
I know this is draft, but I'd also add queries to the same PR. I think it makes testability easier even at the expense of bigger PR.
Problem
This is phase 7 of this proposal: PyRIT Unified Registry — Design & Rationale
this draft uses TargetIdentifier and their relationship with Conversation as example, if we concensus on the pattern, this will be extended to all identifiers.
Target identifiers weren't persisted as first-class, queryable data. Their configuration (endpoint, model, sampling params) and their composition (multi-targets wrapping inner targets) were only available inline, with no deduplication and no way to query across them.
Solution
Persist
TargetIdentifiers as content-addressed rows keyed by their content hash, so an identical identifier reused across many conversations maps to a single immutable row.Mechanisms:
identifier_json) is the immutable source of truth; frequently-queried fields are surfaced as denormalized columns (indexes into the blob, not a second source of truth).from_domain_modelseam — a uniform, per-entry converter defining how a domain model becomes a row, enforced on concrete subclasses at class-definition time.Why draft
Raising as a draft to validate the pattern (
DomainBackedEntry+ content-addressed store + recursive child graph) on target identifiers first. If it looks good, the same approach extends cleanly to the other identifier types.