feat: Phase 2.6 edges migration to Qdrant (TKG-only architecture)
Phase 2.6.1: co_occurrence_edges migration - build_co_occurrence_edges_from_qdrant() - Qdrant embeddings → frame grouping → YOLO objects - Result: 6679 edges (vs 6701 PostgreSQL) Phase 2.6.2: face_face_edges migration - build_face_face_edges_from_qdrant() - Qdrant embeddings → frame grouping → face pairs - mutual_gaze detection preserved - Result: 6 edges (exact match) Phase 2.6.3: speaker_face_edges migration - build_speaker_face_edges_from_qdrant() - Qdrant embeddings → trace_id frame ranges - SPEAKS_AS edge creation Architecture: - All edges use Qdrant payload (no face_detections queries) - PostgreSQL fallback for empty Qdrant - Estimated 3.6x performance improvement Testing: - Playground (3003): ✓ All Phase 2.6 logs verified - Edge counts: ✓ Close match with PostgreSQL - Fallback: ✓ Working Docs: - docs_v1.0/DESIGN/TKG_PHASE2_6_EDGES_MIGRATION.md - docs_v1.0/M4_workspace/2026-06-21_phase2_6_test.md
This commit is contained in:
@@ -0,0 +1,355 @@
|
||||
use crate::core::db::ProcessorType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Required field definition for JSON schema validation
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RequiredField {
|
||||
pub path: &'static str,
|
||||
pub field_type: FieldType,
|
||||
pub allow_empty: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum FieldType {
|
||||
Number,
|
||||
PositiveNumber,
|
||||
Array,
|
||||
NonEmptyArray,
|
||||
Object,
|
||||
String,
|
||||
OptionalNumber,
|
||||
}
|
||||
|
||||
/// Processor JSON schema: defines required fields and their types
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProcessorJsonSchema {
|
||||
pub processor: ProcessorType,
|
||||
pub required_fields: &'static [RequiredField],
|
||||
pub min_data_threshold: usize,
|
||||
}
|
||||
|
||||
/// All processor schemas
|
||||
pub const PROCESSOR_SCHEMAS: &[ProcessorJsonSchema] = &[
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Cut,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "frame_count",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "scenes",
|
||||
field_type: FieldType::NonEmptyArray,
|
||||
allow_empty: false,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 1,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Yolo,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "metadata.fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "metadata.total_frames",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "frames",
|
||||
field_type: FieldType::Object,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Ocr,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "frame_count",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "frames",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Face,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "frame_count",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "frames",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Pose,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "frame_count",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "frames",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Appearance,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "frame_count",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "frames",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Asr,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "language",
|
||||
field_type: FieldType::OptionalNumber,
|
||||
allow_empty: true,
|
||||
},
|
||||
RequiredField {
|
||||
path: "segments",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Asrx,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "language",
|
||||
field_type: FieldType::OptionalNumber,
|
||||
allow_empty: true,
|
||||
},
|
||||
RequiredField {
|
||||
path: "segments",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Scene,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "frame_count",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "scenes",
|
||||
field_type: FieldType::NonEmptyArray,
|
||||
allow_empty: false,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 1,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::Story,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "child_chunks",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
RequiredField {
|
||||
path: "parent_chunks",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
RequiredField {
|
||||
path: "stats",
|
||||
field_type: FieldType::Object,
|
||||
allow_empty: false,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
ProcessorJsonSchema {
|
||||
processor: ProcessorType::MediaPipe,
|
||||
required_fields: &[
|
||||
RequiredField {
|
||||
path: "frame_count",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "fps",
|
||||
field_type: FieldType::PositiveNumber,
|
||||
allow_empty: false,
|
||||
},
|
||||
RequiredField {
|
||||
path: "frames",
|
||||
field_type: FieldType::Array,
|
||||
allow_empty: true,
|
||||
},
|
||||
],
|
||||
min_data_threshold: 0,
|
||||
},
|
||||
];
|
||||
|
||||
/// Get schema for a processor
|
||||
pub fn get_schema(processor: &ProcessorType) -> Option<&'static ProcessorJsonSchema> {
|
||||
PROCESSOR_SCHEMAS.iter().find(|s| s.processor == *processor)
|
||||
}
|
||||
|
||||
/// Verification result for a single processor
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProcessorVerification {
|
||||
pub processor: String,
|
||||
pub file_exists: bool,
|
||||
pub valid_json: bool,
|
||||
pub completeness: bool,
|
||||
pub dependency_ok: bool,
|
||||
pub reasonableness: bool,
|
||||
pub trust_level: String,
|
||||
pub issues: Vec<String>,
|
||||
pub data_summary: serde_json::Value,
|
||||
}
|
||||
|
||||
impl ProcessorVerification {
|
||||
pub fn new(processor: &str) -> Self {
|
||||
Self {
|
||||
processor: processor.to_string(),
|
||||
file_exists: false,
|
||||
valid_json: false,
|
||||
completeness: false,
|
||||
dependency_ok: true,
|
||||
reasonableness: true,
|
||||
trust_level: "untrusted".to_string(),
|
||||
issues: Vec::new(),
|
||||
data_summary: serde_json::json!({}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_trust_level(&mut self) {
|
||||
if self.file_exists
|
||||
&& self.valid_json
|
||||
&& self.completeness
|
||||
&& self.dependency_ok
|
||||
&& self.reasonableness
|
||||
{
|
||||
self.trust_level = "trusted".to_string();
|
||||
} else if self.file_exists && self.valid_json && self.completeness && !self.dependency_ok {
|
||||
self.trust_level = "degraded".to_string();
|
||||
} else if self.file_exists
|
||||
&& self.valid_json
|
||||
&& self.completeness
|
||||
&& self.dependency_ok
|
||||
&& !self.reasonableness
|
||||
{
|
||||
self.trust_level = "suspicious".to_string();
|
||||
} else {
|
||||
self.trust_level = "untrusted".to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Overall file verification report
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FileVerificationReport {
|
||||
pub file_uuid: String,
|
||||
pub trust_level: String,
|
||||
pub processors: Vec<ProcessorVerification>,
|
||||
pub summary: serde_json::Value,
|
||||
}
|
||||
|
||||
impl FileVerificationReport {
|
||||
pub fn update_overall_trust(&mut self) {
|
||||
let levels: Vec<&str> = self
|
||||
.processors
|
||||
.iter()
|
||||
.map(|p| p.trust_level.as_str())
|
||||
.collect();
|
||||
|
||||
self.trust_level = if levels.is_empty() {
|
||||
"untrusted".to_string()
|
||||
} else if levels.iter().all(|&l| l == "trusted") {
|
||||
"trusted".to_string()
|
||||
} else if levels.iter().all(|&l| l == "trusted" || l == "degraded") {
|
||||
"degraded".to_string()
|
||||
} else if levels.iter().any(|&l| l == "suspicious") {
|
||||
"suspicious".to_string()
|
||||
} else {
|
||||
"untrusted".to_string()
|
||||
};
|
||||
|
||||
let trusted = levels.iter().filter(|&&l| l == "trusted").count();
|
||||
let degraded = levels.iter().filter(|&&l| l == "degraded").count();
|
||||
let suspicious = levels.iter().filter(|&&l| l == "suspicious").count();
|
||||
let untrusted = levels.iter().filter(|&&l| l == "untrusted").count();
|
||||
|
||||
self.summary = serde_json::json!({
|
||||
"total": levels.len(),
|
||||
"trusted": trusted,
|
||||
"degraded": degraded,
|
||||
"suspicious": suspicious,
|
||||
"untrusted": untrusted
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user