Skip to content

Commit 9318f30

Browse files
author
SentienceDEV
committed
add ml_rerank metadata to snapshot response
1 parent b634ee9 commit 9318f30

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

sentience/models.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,34 @@ class GridInfo(BaseModel):
151151
viewport_coverage: float = 0.0 # Ratio of grid area to viewport area (0.0-1.0)
152152

153153

154+
class MlRerankTags(BaseModel):
155+
"""ML rerank tag configuration used for candidate text"""
156+
157+
repeated: bool
158+
sponsored_ish: bool
159+
non_sponsored: bool
160+
pos: bool
161+
occ: bool
162+
vocc: bool
163+
short: bool
164+
action_ish: bool
165+
nav_ish: bool
166+
167+
168+
class MlRerankInfo(BaseModel):
169+
"""ML rerank metadata for a snapshot response"""
170+
171+
enabled: bool
172+
applied: bool
173+
reason: str | None = None
174+
candidate_count: int | None = None
175+
top_probability: float | None = None
176+
min_confidence: float | None = None
177+
is_high_confidence: bool | None = None
178+
tags: MlRerankTags | None = None
179+
error: str | None = None
180+
181+
154182
class Snapshot(BaseModel):
155183
"""Snapshot response from extension"""
156184

@@ -170,6 +198,8 @@ class Snapshot(BaseModel):
170198
# Modal detection fields (from gateway)
171199
modal_detected: bool | None = None # True if a modal/overlay grid was detected
172200
modal_grids: list[GridInfo] | None = None # Array of GridInfo for detected modal grids
201+
# ML rerank metadata (optional)
202+
ml_rerank: MlRerankInfo | None = None
173203

174204
def save(self, filepath: str) -> None:
175205
"""Save snapshot as JSON file"""

tests/test_snapshot.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,39 @@ def test_element_ml_fields_optional():
196196
assert element_partial.heuristic_index is None
197197
assert element_partial.ml_probability == 0.87
198198
assert element_partial.ml_score is None
199+
200+
201+
def test_snapshot_ml_rerank_metadata_optional():
202+
"""Test snapshot ML rerank metadata model"""
203+
from sentience.models import MlRerankInfo, MlRerankTags, Snapshot
204+
205+
snap = Snapshot(
206+
status="success",
207+
url="https://example.com",
208+
elements=[],
209+
ml_rerank=MlRerankInfo(
210+
enabled=True,
211+
applied=False,
212+
reason="low_confidence",
213+
candidate_count=25,
214+
top_probability=0.42,
215+
min_confidence=0.6,
216+
is_high_confidence=False,
217+
tags=MlRerankTags(
218+
repeated=True,
219+
sponsored_ish=True,
220+
non_sponsored=False,
221+
pos=True,
222+
occ=True,
223+
vocc=False,
224+
short=True,
225+
action_ish=False,
226+
nav_ish=False,
227+
),
228+
),
229+
)
230+
231+
assert snap.ml_rerank is not None
232+
assert snap.ml_rerank.enabled is True
233+
assert snap.ml_rerank.is_high_confidence is False
234+

0 commit comments

Comments
 (0)