YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: build
Louis Beaumont26927a396a0e
diff --git a/screenpipe-server/src/add.rs b/screenpipe-server/src/add.rsindex 3a9747f8e..a655c2b2d 100644--- a/screenpipe-server/src/add.rs+++ b/screenpipe-server/src/add.rs@@ -24,9 +24,9 @@ use walkdir::WalkDir;use crate::{cli::CliOcrEngine,+ text_embeds::generate_embedding,video_utils::{extract_frames_from_video, get_video_metadata, VideoMetadataOverrides},DatabaseManager,- text_embeds::generate_embedding,};pub async fn handle_index_command(@@ -148,14 +148,8 @@ pub async fn handle_index_command(for (idx, frame) in frames.iter().enumerate() {// Compare with previous frame to skip similar oneslet current_average = if let Some(prev) = &previous_image {- compare_with_previous_image(- Some(prev),- &frame,- &mut None,- frame_counter as u64,- &mut 0.0,- )- .await?+ compare_with_previous_image(Some(prev), &frame, &mut None, idx as u64, &mut 0.0)+ .await?} else {1.0};@@ -202,33 +196,30 @@ pub async fn handle_index_command(}};- if let Ok(()) = tx.send((frame_num, text, confidence.unwrap_or(0.0))).await {- debug!("processed frame {}", frame_num);- } else {- error!("error sending ocr result for frame {}", frame_num);- }- });-// Handle OCR results- while let Ok((frame_num, text, confidence)) = rx.try_recv() {- total_frames += 1;- total_text += text.len();-- // Only generate embeddings if flag is enabled- if use_embedding && !text.is_empty() {- match generate_embedding(&text, frame_num).await {- Ok(emb) => {- debug!("generated embedding for frame {}", frame_num);- embed_batch.push((- frame_num as i64,- serde_json::to_string(&emb)?,- ));- }- Err(e) => {- error!("failed to generate embedding for frame {}: {}", frame_num, e);+ total_frames += 1;+ total_text += text.len();++ // Only generate embeddings if flag is enabled+ if use_embedding && !text.is_empty() {+ match generate_embedding(&text, frame_ids[idx]).await {+ Ok(emb) => {+ debug!("generated embedding for frame {}", frame_ids[idx]);+ if let Err(e) = db+ .insert_embeddings(frame_ids[idx], serde_json::to_string(&emb)?)+ .await+ {+ error!("error batch inserting embeddings: {}", e);}}+ Err(e) => {+ error!(+ "failed to generate embedding for frame {}: {}",+ frame_ids[idx], e+ );+ }}+ }// Process OCR directly instead of batchingif let Err(e) = db@@ -240,33 +231,12 @@ pub async fn handle_index_command("", // no window nameengine_arc.clone(),true, // focused- ));-- // Process OCR batch when it reaches size 100- if ocr_batch.len() >= 100 {- if let Err(e) = db.batch_insert_ocr(ocr_batch).await {- error!("error batch inserting ocr text: {}", e);- }- ocr_batch = Vec::new();- }-- // Process embeddings batch when it reaches size 100- if embed_batch.len() >= 100 {- // TODO: We'll implement db.batch_insert_embeddings next- if let Err(e) = db.batch_insert_embeddings(embed_batch).await {- error!("error batch inserting embeddings: {}", e);- }- embed_batch = Vec::new();- }-- match output_format {- crate::cli::OutputFormat::Json => {- println!().await{error!("error inserting ocr text: {}", e);}+info!("inserted ocr text for frame {}", frame_ids[idx]);// Handle output formatting@@ -299,19 +269,6 @@ pub async fn handle_index_command(frame_counter += 1;}-- // Process remaining batches- if !ocr_batch.is_empty() {- if let Err(e) = db.batch_insert_ocr(ocr_batch).await {- error!("error batch inserting remaining ocr text: {}", e);- }- }-- if !embed_batch.is_empty() {- if let Err(e) = db.batch_insert_embeddings(embed_batch).await {- error!("error batch inserting remaining embeddings: {}", e);- }- }}// wait few seconds for remaining OCR tasksdiff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rsindex 60127e6fb..7cb4d5bee 100644--- a/screenpipe-server/src/db.rs+++ b/screenpipe-server/src/db.rs@@ -1848,16 +1848,17 @@ impl DatabaseManager {);// Use metadata.device_name or default to "imported_files"- let device_name = metadata.device_name.unwrap_or_else(|| "imported_files".to_string());-- let video_chunk_id = sqlx::query(- "INSERT INTO video_chunks (device_name, file_path) VALUES (?1, ?2)"- )- .bind(device_name)- .bind(file_path)- .execute(&mut *tx)- .await?- .last_insert_rowid();+ let device_name = metadata+ .device_name+ .unwrap_or_else(|| "imported_files".to_string());++ let video_chunk_id =+ sqlx::query("INSERT INTO video_chunks (device_name, file_path) VALUES (?1, ?2)")+ .bind(device_name)+ .bind(file_path)+ .execute(&mut *tx)+ .await?+ .last_insert_rowid();// 2. Create frames with correct timestamps and default namelet mut frame_ids = Vec::with_capacity(frames.len());@@ -1892,25 +1893,16 @@ impl DatabaseManager {Ok(frame_ids)}- pub async fn batch_insert_embeddings(+ pub async fn insert_embeddings(&self,- embeddings: Vec<(i64, String)>, // (frame_id, embedding_json)+ frame_id: i64,+ embedding: String,) -> Result<(), sqlx::Error> {- let mut tx = self.pool.begin().await?;-- // Using query builder for batch insert- let mut query_builder = QueryBuilder::new(- "INSERT INTO ocr_text_embeddings (frame_id, embedding) "- );-- query_builder.push_values(embeddings, |mut b, (frame_id, embedding)| {- b.push_bind(frame_id)- .push_bind(embedding);- });-- query_builder.build().execute(&mut *tx).await?;-- tx.commit().await?;+ sqlx::query("INSERT INTO ocr_text_embeddings (frame_id, embedding) VALUES (?1, ?2)")+ .bind(frame_id)+ .bind(embedding)+ .execute(&self.pool)+ .await?;Ok(())}@@ -1954,7 +1946,7 @@ impl DatabaseManager {"#;let bytes = embedding.as_bytes();-+let raw_results: Vec<OCRResultRaw> = sqlx::query_as(sql).bind(bytes).bind(threshold)@@ -1974,6 +1966,7 @@ impl DatabaseManager {app_name: raw.app_name,ocr_engine: raw.ocr_engine,window_name: raw.window_name,+ frame_name: raw.frame_name,tags: raw.tags.map(|t| t.split(',').map(String::from).collect())