axiomsync 1.0.0

Core data-processing engine for AxiomSync local retrieval runtime.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
use serde::{Deserialize, Serialize};

use super::EvalQueryCase;
use super::defaults::default_true;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(
    clippy::struct_excessive_bools,
    reason = "benchmark suite toggles are explicit configuration flags and preserved for JSON contract compatibility"
)]
pub struct BenchmarkRunOptions {
    pub query_limit: usize,
    pub search_limit: usize,
    pub include_golden: bool,
    pub include_trace: bool,
    #[serde(default = "default_true")]
    pub include_stress: bool,
    #[serde(default)]
    pub trace_expectations: bool,
    pub fixture_name: Option<String>,
}

impl Default for BenchmarkRunOptions {
    fn default() -> Self {
        Self {
            query_limit: 100,
            search_limit: 10,
            include_golden: true,
            include_trace: true,
            include_stress: true,
            trace_expectations: false,
            fixture_name: None,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAmortizedRunSummary {
    pub iteration: usize,
    pub run_id: String,
    pub created_at: String,
    pub executed_cases: usize,
    pub top1_accuracy: f32,
    pub ndcg_at_10: f32,
    pub recall_at_10: f32,
    pub p95_latency_ms: u128,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub p95_latency_us: Option<u128>,
    pub report_uri: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(
    clippy::struct_excessive_bools,
    reason = "report shape mirrors run options for stable serialization and downstream tooling"
)]
pub struct BenchmarkAmortizedSelection {
    pub query_limit: usize,
    pub search_limit: usize,
    pub include_golden: bool,
    pub include_trace: bool,
    pub include_stress: bool,
    pub trace_expectations: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fixture_name: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAmortizedTiming {
    pub wall_total_ms: u128,
    pub wall_avg_ms: f32,
    pub p95_latency_ms_median: u128,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub p95_latency_us_median: Option<u128>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAmortizedQualitySummary {
    pub executed_cases_total: usize,
    pub top1_accuracy_avg: f32,
    pub ndcg_at_10_avg: f32,
    pub recall_at_10_avg: f32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAmortizedReport {
    pub mode: String,
    pub iterations: usize,
    pub selection: BenchmarkAmortizedSelection,
    pub timing: BenchmarkAmortizedTiming,
    pub quality: BenchmarkAmortizedQualitySummary,
    pub runs: Vec<BenchmarkAmortizedRunSummary>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateOptions {
    pub gate_profile: String,
    pub threshold_p95_ms: u128,
    pub min_top1_accuracy: f32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub min_stress_top1_accuracy: Option<f32>,
    pub max_p95_regression_pct: Option<f32>,
    pub max_top1_regression_pct: Option<f32>,
    pub window_size: usize,
    pub required_passes: usize,
    pub record: bool,
    pub write_release_check: bool,
}

impl Default for BenchmarkGateOptions {
    fn default() -> Self {
        Self {
            gate_profile: "custom".to_string(),
            threshold_p95_ms: 600,
            min_top1_accuracy: 0.75,
            min_stress_top1_accuracy: None,
            max_p95_regression_pct: None,
            max_top1_regression_pct: None,
            window_size: 1,
            required_passes: 1,
            record: false,
            write_release_check: false,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ReleaseSecurityAuditMode {
    Offline,
    #[default]
    Strict,
}

impl ReleaseSecurityAuditMode {
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Offline => "offline",
            Self::Strict => "strict",
        }
    }
}

impl std::fmt::Display for ReleaseSecurityAuditMode {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str((*self).as_str())
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGateReplayPlan {
    pub replay_limit: usize,
    pub replay_max_cycles: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGateOperabilityPlan {
    pub trace_limit: usize,
    pub request_limit: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGateEvalPlan {
    pub eval_trace_limit: usize,
    pub eval_query_limit: usize,
    pub eval_search_limit: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGateBenchmarkRunPlan {
    pub benchmark_query_limit: usize,
    pub benchmark_search_limit: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGateBenchmarkGatePlan {
    pub benchmark_threshold_p95_ms: u128,
    pub benchmark_min_top1_accuracy: f32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub benchmark_min_stress_top1_accuracy: Option<f32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub benchmark_max_p95_regression_pct: Option<f32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub benchmark_max_top1_regression_pct: Option<f32>,
    pub benchmark_window_size: usize,
    pub benchmark_required_passes: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGatePackOptions {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub workspace_dir: Option<String>,
    pub replay: ReleaseGateReplayPlan,
    pub operability: ReleaseGateOperabilityPlan,
    pub eval: ReleaseGateEvalPlan,
    pub benchmark_run: ReleaseGateBenchmarkRunPlan,
    pub benchmark_gate: ReleaseGateBenchmarkGatePlan,
    #[serde(default)]
    pub security_audit_mode: ReleaseSecurityAuditMode,
}

impl Default for ReleaseGatePackOptions {
    fn default() -> Self {
        Self {
            workspace_dir: None,
            replay: ReleaseGateReplayPlan {
                replay_limit: 100,
                replay_max_cycles: 8,
            },
            operability: ReleaseGateOperabilityPlan {
                trace_limit: 200,
                request_limit: 200,
            },
            eval: ReleaseGateEvalPlan {
                eval_trace_limit: 200,
                eval_query_limit: 50,
                eval_search_limit: 10,
            },
            benchmark_run: ReleaseGateBenchmarkRunPlan {
                benchmark_query_limit: 60,
                benchmark_search_limit: 10,
            },
            benchmark_gate: ReleaseGateBenchmarkGatePlan {
                benchmark_threshold_p95_ms: 600,
                benchmark_min_top1_accuracy: 0.75,
                benchmark_min_stress_top1_accuracy: None,
                benchmark_max_p95_regression_pct: None,
                benchmark_max_top1_regression_pct: None,
                benchmark_window_size: 1,
                benchmark_required_passes: 1,
            },
            security_audit_mode: ReleaseSecurityAuditMode::default(),
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkCaseResult {
    pub query: String,
    pub target_uri: Option<String>,
    pub expected_top_uri: Option<String>,
    pub actual_top_uri: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expected_rank: Option<usize>,
    pub latency_ms: u128,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub latency_us: Option<u128>,
    pub passed: bool,
    pub source: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkEnvironmentMetadata {
    pub machine_profile: String,
    pub cpu_model: String,
    pub ram_bytes: u64,
    pub os_version: String,
    pub rustc_version: String,
    pub retrieval_backend: String,
    pub reranker_profile: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding_provider: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding_vector_version: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding_strict_error: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkCorpusMetadata {
    pub profile: String,
    pub snapshot_id: String,
    pub root_uri: String,
    pub file_count: usize,
    pub total_bytes: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkQuerySetMetadata {
    pub version: String,
    pub source: String,
    pub total_queries: usize,
    pub semantic_queries: usize,
    pub lexical_queries: usize,
    pub mixed_queries: usize,
    pub warmup_queries: usize,
    pub measured_queries: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAcceptanceThresholds {
    pub find_p95_latency_ms_max: u128,
    pub search_p95_latency_ms_max: u128,
    pub commit_p95_latency_ms_max: u128,
    pub min_ndcg_at_10: f32,
    pub min_recall_at_10: f32,
    pub min_total_queries: usize,
    pub min_semantic_queries: usize,
    pub min_lexical_queries: usize,
    pub min_mixed_queries: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAcceptanceMeasured {
    pub find_p95_latency_ms: u128,
    pub search_p95_latency_ms: u128,
    pub commit_p95_latency_ms: u128,
    pub ndcg_at_10: f32,
    pub recall_at_10: f32,
    pub total_queries: usize,
    pub semantic_queries: usize,
    pub lexical_queries: usize,
    pub mixed_queries: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAcceptanceCheck {
    pub name: String,
    pub passed: bool,
    pub expected: String,
    pub actual: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkAcceptanceResult {
    pub protocol_id: String,
    pub passed: bool,
    pub thresholds: BenchmarkAcceptanceThresholds,
    pub measured: BenchmarkAcceptanceMeasured,
    pub checks: Vec<BenchmarkAcceptanceCheck>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkRunSelection {
    pub query_limit: usize,
    pub search_limit: usize,
    pub include_golden: bool,
    pub include_trace: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkQualityMetrics {
    pub executed_cases: usize,
    pub passed: usize,
    pub failed: usize,
    pub top1_accuracy: f32,
    pub ndcg_at_10: f32,
    pub recall_at_10: f32,
    pub error_rate: f32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkLatencySummary {
    pub p50_ms: u128,
    pub p95_ms: u128,
    pub p99_ms: u128,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub p50_us: Option<u128>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub p95_us: Option<u128>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub p99_us: Option<u128>,
    pub avg_ms: f32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkLatencyProfile {
    pub find: BenchmarkLatencySummary,
    pub search: BenchmarkLatencySummary,
    pub commit: BenchmarkLatencySummary,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkArtifacts {
    pub report_uri: String,
    pub markdown_report_uri: String,
    pub case_set_uri: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkReport {
    pub run_id: String,
    pub created_at: String,
    pub selection: BenchmarkRunSelection,
    pub quality: BenchmarkQualityMetrics,
    pub latency: BenchmarkLatencyProfile,
    pub environment: BenchmarkEnvironmentMetadata,
    pub corpus: BenchmarkCorpusMetadata,
    pub query_set: BenchmarkQuerySetMetadata,
    pub acceptance: BenchmarkAcceptanceResult,
    pub artifacts: BenchmarkArtifacts,
    pub results: Vec<BenchmarkCaseResult>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkSummary {
    pub run_id: String,
    pub created_at: String,
    pub executed_cases: usize,
    pub top1_accuracy: f32,
    pub p95_latency_ms: u128,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub p95_latency_us: Option<u128>,
    pub report_uri: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkFixtureDocument {
    pub version: u32,
    pub created_at: String,
    pub name: String,
    pub cases: Vec<EvalQueryCase>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkFixtureSummary {
    pub name: String,
    pub uri: String,
    pub case_count: usize,
    pub created_at: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkTrendReport {
    pub latest: Option<BenchmarkSummary>,
    pub previous: Option<BenchmarkSummary>,
    pub delta_p95_latency_ms: Option<i128>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub delta_p95_latency_us: Option<i128>,
    pub delta_top1_accuracy: Option<f32>,
    pub status: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateRunResult {
    pub run_id: String,
    pub passed: bool,
    pub p95_latency_ms: u128,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub p95_latency_us: Option<u128>,
    pub top1_accuracy: f32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub stress_top1_accuracy: Option<f32>,
    pub regression_pct: Option<f32>,
    pub top1_regression_pct: Option<f32>,
    pub reasons: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateThresholds {
    pub threshold_p95_ms: u128,
    pub min_top1_accuracy: f32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub min_stress_top1_accuracy: Option<f32>,
    pub max_p95_regression_pct: Option<f32>,
    pub max_top1_regression_pct: Option<f32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateQuorum {
    pub window_size: usize,
    pub required_passes: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateSnapshot {
    pub latest: Option<BenchmarkSummary>,
    pub previous: Option<BenchmarkSummary>,
    pub regression_pct: Option<f32>,
    pub top1_regression_pct: Option<f32>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub stress_top1_accuracy: Option<f32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateExecution {
    pub evaluated_runs: usize,
    pub passing_runs: usize,
    pub run_results: Vec<BenchmarkGateRunResult>,
    pub reasons: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateArtifacts {
    pub gate_record_uri: Option<String>,
    pub release_check_uri: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding_provider: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding_strict_error: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateResult {
    pub passed: bool,
    pub gate_profile: String,
    pub thresholds: BenchmarkGateThresholds,
    pub quorum: BenchmarkGateQuorum,
    pub snapshot: BenchmarkGateSnapshot,
    pub execution: BenchmarkGateExecution,
    pub artifacts: BenchmarkGateArtifacts,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn release_security_audit_mode_serde_contract_is_stable() {
        let expected = [
            (ReleaseSecurityAuditMode::Offline, "offline"),
            (ReleaseSecurityAuditMode::Strict, "strict"),
        ];

        for (mode, raw) in expected {
            let serialized = serde_json::to_string(&mode).expect("serialize mode");
            assert_eq!(serialized, format!("\"{raw}\""));
            let deserialized: ReleaseSecurityAuditMode =
                serde_json::from_str(&serialized).expect("deserialize mode");
            assert_eq!(deserialized, mode);
        }
    }
}