feat: ASRX hybrid pipeline, identity history, worker fixes, checkpoint system
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
use anyhow::{Context, Result};
|
||||
use momentry_core::{
|
||||
Database, Embedder, PostgresDb, QdrantDb, VectorPayload,
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
dotenv::from_filename("/Users/accusys/momentry_core_0.1/.env.development").ok();
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let pg = PostgresDb::init().await.context("Failed to init PostgreSQL")?;
|
||||
let qdrant = QdrantDb::new();
|
||||
let embedder = Embedder::new("embeddinggemma-300m".to_string());
|
||||
|
||||
let uuid = "63acd3bb02b5b9dfbb9d6db499fcc864";
|
||||
let chunk_table = momentry_core::core::db::schema::table_name("chunk");
|
||||
|
||||
let rows = sqlx::query_as::<_, (String, String, i64, i64, f64, f64, String)>(
|
||||
&format!(
|
||||
"SELECT chunk_id, text_content, start_frame, end_frame, \
|
||||
start_time, end_time, content::text \
|
||||
FROM {} \
|
||||
WHERE file_uuid = $1 \
|
||||
AND chunk_type = 'sentence' \
|
||||
AND embedding IS NULL \
|
||||
AND (text_content IS NOT NULL AND text_content != '') \
|
||||
ORDER BY id",
|
||||
chunk_table
|
||||
),
|
||||
)
|
||||
.bind(uuid)
|
||||
.fetch_all(pg.pool())
|
||||
.await?;
|
||||
|
||||
let total = rows.len();
|
||||
println!("Found {} sentence chunks without embedding for {}", total, uuid);
|
||||
|
||||
if total == 0 {
|
||||
println!("Nothing to vectorize. Exiting.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let mut stored = 0usize;
|
||||
let mut errors = 0usize;
|
||||
|
||||
for (chunk_id, text, start_frame, end_frame, start_time, end_time, _content_str) in &rows {
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
match embedder.embed_document(text).await {
|
||||
Ok(vector) => {
|
||||
if let Err(e) = pg.store_vector(chunk_id, &vector, uuid).await {
|
||||
eprintln!("[ERROR] PG store failed for {}: {}", chunk_id, e);
|
||||
errors += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let payload = VectorPayload {
|
||||
file_uuid: uuid.to_string(),
|
||||
chunk_id: chunk_id.clone(),
|
||||
chunk_type: "sentence".to_string(),
|
||||
start_frame: *start_frame,
|
||||
end_frame: *end_frame,
|
||||
start_time: *start_time,
|
||||
end_time: *end_time,
|
||||
text: Some(text.clone()),
|
||||
};
|
||||
|
||||
if let Err(e) = qdrant.upsert_vector(chunk_id, &vector, payload).await {
|
||||
eprintln!("[ERROR] Qdrant upsert failed for {}: {}", chunk_id, e);
|
||||
errors += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
stored += 1;
|
||||
if stored % 500 == 0 || stored == total {
|
||||
let elapsed = start.elapsed();
|
||||
let rate = stored as f64 / elapsed.as_secs_f64();
|
||||
let eta = if stored < total {
|
||||
let remaining = Duration::from_secs_f64((total - stored) as f64 / rate);
|
||||
format!(" (ETA: {}s)", remaining.as_secs())
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
println!(
|
||||
" [{}/{}] {:.1}% done | {:.0} vec/s | {} errors{}",
|
||||
stored,
|
||||
total,
|
||||
100.0 * stored as f64 / total as f64,
|
||||
rate,
|
||||
errors,
|
||||
eta,
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("[ERROR] Embedding failed for {}: {}", chunk_id, e);
|
||||
errors += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
println!(
|
||||
"\nDone! {}/{} vectors stored ({} errors) in {:.1}s ({:.0} vec/s avg)",
|
||||
stored,
|
||||
total,
|
||||
errors,
|
||||
elapsed.as_secs_f64(),
|
||||
stored as f64 / elapsed.as_secs_f64(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user