feat: add data-consistency API + deprecate old face docs
- Added GET /api/v1/file/:uuid/data-consistency endpoint Checks consistency across tkg_nodes, trace_profiles, FS trace dirs, and Qdrant - Marked 6 old face documents as deprecated with link to Face_Operations_Complete.md
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
> ⚠️ **DEPRECATED** - This document has been superseded by [Face Operations Complete](../REFERENCE/Face_Operations_Complete.md). See the new document for the complete and updated reference.
|
||||
>
|
||||
# FaceFilterSettings 文件存储架构
|
||||
|
||||
**日期**: 2026-10-09
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
> ⚠️ **DEPRECATED** - This document has been superseded by [Face Operations Complete](../REFERENCE/Face_Operations_Complete.md). See the new document for the complete and updated reference.
|
||||
>
|
||||
# Face Pipeline: Detection → Clustering → Trace
|
||||
|
||||
**Date**: 2026-05-16
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
> ⚠️ **DEPRECATED** - This document has been superseded by [Face Operations Complete](../REFERENCE/Face_Operations_Complete.md). See the new document for the complete and updated reference.
|
||||
>
|
||||
---
|
||||
title: Rust Store Traced Faces 設計文檔
|
||||
version: 1.0
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
> ⚠️ **DEPRECATED** - This document has been superseded by [Face Operations Complete](../REFERENCE/Face_Operations_Complete.md). See the new document for the complete and updated reference.
|
||||
>
|
||||
---
|
||||
title: Swift Face Trace Design
|
||||
version: 1.0
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
> ⚠️ **DEPRECATED** - This document has been superseded by [Face Operations Complete](../REFERENCE/Face_Operations_Complete.md). See the new document for the complete and updated reference.
|
||||
>
|
||||
# Trace ID Inheritance & Expansion Rules
|
||||
|
||||
**Date**: 2026-07-19
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
> ⚠️ **DEPRECATED** - This document has been superseded by [Face Operations Complete](../REFERENCE/Face_Operations_Complete.md). See the new document for the complete and updated reference.
|
||||
>
|
||||
# Face Pipeline: Detection → Clustering → Trace
|
||||
|
||||
**Date**: 2026-05-16
|
||||
|
||||
@@ -74,6 +74,10 @@ pub fn trace_agent_routes() -> Router<crate::api::types::AppState> {
|
||||
"/api/v1/trace-profile-file",
|
||||
get(get_trace_profile_file),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/file/:file_uuid/data-consistency",
|
||||
get(check_data_consistency),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -2811,3 +2815,104 @@ async fn get_trace_profile_file(
|
||||
None => (StatusCode::NOT_FOUND, Json(serde_json::json!({"error": "Trace profile file not found", "file_uuid": file_uuid, "trace_id": trace_id}))),
|
||||
}
|
||||
}
|
||||
|
||||
/// GET /api/v1/file/:file_uuid/data-consistency
|
||||
/// Checks consistency across tkg_nodes, trace_profiles, FS trace dirs, and Qdrant points.
|
||||
async fn check_data_consistency(
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(file_uuid): Path<String>,
|
||||
) -> Json<serde_json::Value> {
|
||||
let tkg_table = crate::core::db::schema::table_name("tkg_nodes");
|
||||
let tp_table = crate::core::db::schema::table_name("trace_profiles");
|
||||
|
||||
// 1. Count tkg_nodes face_track
|
||||
let tkg_count: i64 = sqlx::query_scalar(&format!(
|
||||
"SELECT COUNT(*) FROM {} WHERE file_uuid = $1 AND node_type = 'face_track'",
|
||||
tkg_table
|
||||
))
|
||||
.bind(&file_uuid)
|
||||
.fetch_one(state.db.pool())
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
|
||||
// 2. Count trace_profiles
|
||||
let tp_count: i64 = sqlx::query_scalar(&format!(
|
||||
"SELECT COUNT(*) FROM {} WHERE file_uuid = $1",
|
||||
tp_table
|
||||
))
|
||||
.bind(&file_uuid)
|
||||
.fetch_one(state.db.pool())
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
|
||||
// 3. Count FS trace directories
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let trace_base_dir = std::path::Path::new(output_dir).join(&file_uuid);
|
||||
let fs_count = if let Ok(entries) = std::fs::read_dir(&trace_base_dir) {
|
||||
entries
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|e| e.file_name().to_string_lossy().starts_with("trace_"))
|
||||
.count() as i64
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
// 4. Count Qdrant points for this file
|
||||
let qdrant = crate::core::db::qdrant_db::QdrantDb::new();
|
||||
let qdrant_filter = serde_json::json!({
|
||||
"must": [{"key": "file_uuid", "match": {"value": &file_uuid}}]
|
||||
});
|
||||
let qdrant_count = qdrant
|
||||
.count_points("_faces", qdrant_filter)
|
||||
.await
|
||||
.unwrap_or(0) as i64;
|
||||
|
||||
// 5. Check for mismatches
|
||||
let mut mismatches = Vec::new();
|
||||
if tkg_count != tp_count {
|
||||
mismatches.push(format!("tkg_nodes ({}) != trace_profiles ({})", tkg_count, tp_count));
|
||||
}
|
||||
if tkg_count != fs_count {
|
||||
mismatches.push(format!("tkg_nodes ({}) != trace_dirs ({})", tkg_count, fs_count));
|
||||
}
|
||||
|
||||
// 6. Check unique trace_ids in Qdrant
|
||||
let qdrant_unique_traces = qdrant
|
||||
.scroll_all_points(
|
||||
"_faces",
|
||||
serde_json::json!({
|
||||
"must": [
|
||||
{"key": "file_uuid", "match": {"value": &file_uuid}},
|
||||
{"key": "trace_id", "is_null": false}
|
||||
]
|
||||
}),
|
||||
1000,
|
||||
)
|
||||
.await
|
||||
.map(|pts| {
|
||||
use std::collections::HashSet;
|
||||
pts.iter()
|
||||
.filter_map(|p| p["payload"]["trace_id"].as_i64())
|
||||
.collect::<HashSet<_>>()
|
||||
.len() as i64
|
||||
})
|
||||
.unwrap_or(0);
|
||||
|
||||
if qdrant_unique_traces != tkg_count && tkg_count > 0 {
|
||||
mismatches.push(format!(
|
||||
"tkg_nodes ({}) != Qdrant unique traces ({})",
|
||||
tkg_count, qdrant_unique_traces
|
||||
));
|
||||
}
|
||||
|
||||
Json(serde_json::json!({
|
||||
"file_uuid": file_uuid,
|
||||
"tkg_nodes": tkg_count,
|
||||
"trace_profiles": tp_count,
|
||||
"trace_dirs": fs_count,
|
||||
"qdrant_points": qdrant_count,
|
||||
"qdrant_unique_traces": qdrant_unique_traces,
|
||||
"is_consistent": mismatches.is_empty(),
|
||||
"mismatches": mismatches
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user