Skip to content

Commit 00fe186

Browse files
authored
Merge pull request #166 from SentienceAPI/new_fields
new fields with ml_rerank metadata
2 parents 35d3523 + 3f5cda9 commit 00fe186

5 files changed

Lines changed: 69 additions & 10 deletions

File tree

src/tracing/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface TraceElement {
3939
in_viewport?: boolean;
4040
is_occluded?: boolean;
4141
z_index?: number;
42-
rerank_index?: number;
42+
fused_rank_index?: number;
4343
heuristic_index?: number;
4444
ml_probability?: number;
4545
ml_score?: number;

src/types.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface Element {
3333
z_index: number;
3434

3535
// ML reranking metadata (optional - can be absent or null)
36-
rerank_index?: number; // 0-based, The rank after ML reranking
36+
fused_rank_index?: number; // 0-based, The rank after ML reranking
3737
heuristic_index?: number; // 0-based, Where it would have been without ML
3838
ml_probability?: number; // Confidence score from ONNX model (0.0 - 1.0)
3939
ml_score?: number; // Raw logit score (optional, for debugging)
@@ -143,6 +143,30 @@ export interface GridInfo {
143143
viewport_coverage?: number;
144144
}
145145

146+
export interface MlRerankTags {
147+
repeated: boolean;
148+
sponsored_ish: boolean;
149+
non_sponsored: boolean;
150+
pos: boolean;
151+
occ: boolean;
152+
vocc: boolean;
153+
short: boolean;
154+
action_ish: boolean;
155+
nav_ish: boolean;
156+
}
157+
158+
export interface MlRerankInfo {
159+
enabled: boolean;
160+
applied: boolean;
161+
reason?: string | null;
162+
candidate_count?: number | null;
163+
top_probability?: number | null;
164+
min_confidence?: number | null;
165+
is_high_confidence?: boolean | null;
166+
tags?: MlRerankTags | null;
167+
error?: string | null;
168+
}
169+
146170
export interface Snapshot {
147171
status: 'success' | 'error';
148172
timestamp?: string;
@@ -162,6 +186,8 @@ export interface Snapshot {
162186
modal_detected?: boolean;
163187
/** Array of GridInfo for detected modal grids */
164188
modal_grids?: GridInfo[];
189+
/** ML rerank metadata (optional) */
190+
ml_rerank?: MlRerankInfo;
165191
}
166192

167193
export interface StepHookContext {

src/utils/snapshot-event-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class SnapshotEventBuilder {
4747
in_viewport: el.in_viewport,
4848
is_occluded: el.is_occluded,
4949
z_index: el.z_index,
50-
rerank_index: el.rerank_index,
50+
fused_rank_index: el.fused_rank_index,
5151
heuristic_index: el.heuristic_index,
5252
ml_probability: el.ml_probability,
5353
ml_score: el.ml_score,

src/utils/trace-event-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class TraceEventBuilder {
219219
in_viewport: el.in_viewport,
220220
is_occluded: el.is_occluded,
221221
z_index: el.z_index,
222-
rerank_index: el.rerank_index,
222+
fused_rank_index: el.fused_rank_index,
223223
heuristic_index: el.heuristic_index,
224224
ml_probability: el.ml_probability,
225225
ml_score: el.ml_score,
@@ -429,7 +429,7 @@ export class TraceEventBuilder {
429429
in_viewport: el.in_viewport,
430430
is_occluded: el.is_occluded,
431431
z_index: el.z_index,
432-
rerank_index: el.rerank_index,
432+
fused_rank_index: el.fused_rank_index,
433433
heuristic_index: el.heuristic_index,
434434
ml_probability: el.ml_probability,
435435
ml_score: el.ml_score,

tests/snapshot.test.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Element ML Fields', () => {
9595
};
9696

9797
expect(element.id).toBe(1);
98-
expect(element).not.toHaveProperty('rerank_index');
98+
expect(element).not.toHaveProperty('fused_rank_index');
9999
expect(element).not.toHaveProperty('heuristic_index');
100100
expect(element).not.toHaveProperty('ml_probability');
101101
expect(element).not.toHaveProperty('ml_score');
@@ -112,13 +112,13 @@ describe('Element ML Fields', () => {
112112
in_viewport: true,
113113
is_occluded: false,
114114
z_index: 1,
115-
rerank_index: 0,
115+
fused_rank_index: 0,
116116
heuristic_index: 5,
117117
ml_probability: 0.95,
118118
ml_score: 2.34,
119119
};
120120

121-
expect(element.rerank_index).toBe(0);
121+
expect(element.fused_rank_index).toBe(0);
122122
expect(element.heuristic_index).toBe(5);
123123
expect(element.ml_probability).toBe(0.95);
124124
expect(element.ml_score).toBe(2.34);
@@ -135,13 +135,46 @@ describe('Element ML Fields', () => {
135135
in_viewport: true,
136136
is_occluded: false,
137137
z_index: 0,
138-
rerank_index: 1,
138+
fused_rank_index: 1,
139139
ml_probability: 0.87,
140140
};
141141

142-
expect(element.rerank_index).toBe(1);
142+
expect(element.fused_rank_index).toBe(1);
143143
expect(element).not.toHaveProperty('heuristic_index');
144144
expect(element.ml_probability).toBe(0.87);
145145
expect(element).not.toHaveProperty('ml_score');
146146
});
147147
});
148+
149+
describe('Snapshot ML Rerank Metadata', () => {
150+
it('should accept snapshot with ml_rerank metadata', () => {
151+
const snap = {
152+
status: 'success' as const,
153+
url: 'https://example.com',
154+
elements: [],
155+
ml_rerank: {
156+
enabled: true,
157+
applied: false,
158+
reason: 'low_confidence',
159+
candidate_count: 25,
160+
top_probability: 0.42,
161+
min_confidence: 0.6,
162+
is_high_confidence: false,
163+
tags: {
164+
repeated: true,
165+
sponsored_ish: true,
166+
non_sponsored: false,
167+
pos: true,
168+
occ: true,
169+
vocc: false,
170+
short: true,
171+
action_ish: false,
172+
nav_ish: false,
173+
},
174+
},
175+
};
176+
177+
expect(snap.ml_rerank.enabled).toBe(true);
178+
expect(snap.ml_rerank.is_high_confidence).toBe(false);
179+
});
180+
});

0 commit comments

Comments
 (0)