feat: Rule 3 moment chunks — 10s windows with 1-2 key frames

- Add ChunkType::Moment to types.rs
- Add moment_interval to FileProfile (configurable, default 10s)
- Create rule3_moment.rs: reads trace_profile.json, groups by time window,
  selects 1-2 diverse key frames using Jaccard similarity on VLM text
- Embed moment chunks into Qdrant using trace VLM embeddings
- Wire into worker: triggers after VLM completes, blocks job completion
- Add moment_chunks progress stage (weight: 0.01)
This commit is contained in:
Accusys
2026-08-26 02:37:47 +08:00
parent 8732c3e0a4
commit 20f5974b52
7 changed files with 440 additions and 6 deletions
+57 -5
View File
@@ -21,6 +21,7 @@ static FACE_TRACE_INFLIGHT: LazyLock<tokio::sync::Mutex<std::collections::HashSe
LazyLock::new(|| tokio::sync::Mutex::new(std::collections::HashSet::new()));
use crate::core::chunk::rule1_ingest;
use crate::core::pipeline;
use crate::core::config::{FACE_MIN_CONFIDENCE_DEFAULT, FACE_MIN_SIZE_DEFAULT, OUTPUT_DIR};
use crate::core::db::qdrant_db::QdrantDb;
use crate::core::db::{
@@ -1885,16 +1886,26 @@ impl JobWorker {
);
}
let all_ok = asr_done && trace_done && tkg_done && face_cluster_done && qdrant_face_done && vlm_done_bool;
// Moment chunks: check if moment chunks exist (requires VLM to be done first)
let chunk_t = schema::table_name("chunk");
let moment_done: bool = sqlx::query_scalar(&format!(
"SELECT EXISTS(SELECT 1 FROM {chunk_t} WHERE file_uuid = $1 AND chunk_type = 'moment')"
))
.bind(uuid)
.fetch_one(pool)
.await
.unwrap_or(false);
let all_ok = asr_done && trace_done && tkg_done && face_cluster_done && qdrant_face_done && vlm_done_bool && moment_done;
tracing::info!(
"[Ingestion] all_ok={} (asr={}, trace={}, tkg={}, face_cluster={}, rule3={}, scene_meta={}, qdrant_face={}, vlm={}) for uuid={}",
all_ok, asr_done, trace_done, tkg_done, face_cluster_done, rule3_done, scene_meta_done, qdrant_face_done, vlm_done_bool, uuid
"[Ingestion] all_ok={} (asr={}, trace={}, tkg={}, face_cluster={}, rule3={}, scene_meta={}, qdrant_face={}, vlm={}, moment={}) for uuid={}",
all_ok, asr_done, trace_done, tkg_done, face_cluster_done, rule3_done, scene_meta_done, qdrant_face_done, vlm_done_bool, moment_done, uuid
);
if !all_ok {
tracing::info!(
"[Ingestion] waiting (uuid={}): asr={} trace={} tkg={} face_cluster={} rule3={} scene_meta={} qdrant_face={} vlm={}",
uuid, asr_done, trace_done, tkg_done, face_cluster_done, rule3_done, scene_meta_done, qdrant_face_done, vlm_done_bool
"[Ingestion] waiting (uuid={}): asr={} trace={} tkg={} face_cluster={} rule3={} scene_meta={} qdrant_face={} vlm={} moment={}",
uuid, asr_done, trace_done, tkg_done, face_cluster_done, rule3_done, scene_meta_done, qdrant_face_done, vlm_done_bool, moment_done
);
}
all_ok
@@ -2069,6 +2080,47 @@ impl JobWorker {
}
}
// Check moment chunks progress — trigger if VLM done but moments not created
let chunk_t = schema::table_name("chunk");
let moment_exists: bool = sqlx::query_scalar(&format!(
"SELECT EXISTS(SELECT 1 FROM {chunk_t} WHERE file_uuid = $1 AND chunk_type = 'moment')"
))
.bind(uuid)
.fetch_one(self.db.pool())
.await
.unwrap_or(false);
if !moment_exists && vlm_done > 0 {
// VLM is done but no moment chunks yet — trigger Rule 3
info!("[Moment-poll] VLM done ({}), no moments yet — triggering Rule 3", vlm_done);
let db_clone = self.db.clone();
let uuid_clone = uuid.to_string();
let redis_clone2 = self.redis.clone();
tokio::spawn(async move {
match crate::core::pipeline::execute_rule3_moment(&db_clone, &uuid_clone).await {
Ok(count) => {
info!("[Rule3-Moment] Completed: {} moments for {}", count, uuid_clone);
if let Ok(mut conn) = redis_clone2.get_conn().await {
let prefix = crate::core::config::REDIS_KEY_PREFIX.as_str();
let redis_key = format!("{}progress:{}:pipeline", prefix, uuid_clone);
let _: Result<(), _> =
redis::AsyncCommands::set(&mut conn, &redis_key,
serde_json::json!({
"stage": "moment_chunks",
"progress": 1.0,
"status": "completed",
"detail": format!("{} moments created", count)
}).to_string()
).await;
}
}
Err(e) => {
tracing::error!("[Rule3-Moment] Failed for {}: {}", uuid_clone, e);
}
}
});
}
let mut created_deferred = false;
// Find processors in job_processors that are not in results yet