Skip to content

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

fix: disable chunking

Louis Beaumontfd875a63c461
diff --git a/Cargo.toml b/Cargo.toml
index 1f76de937..2ae787673 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,7 @@ resolver = "2"
[workspace.package]
-version = "0.1.62"
+version = "0.1.65"
authors = ["louis030195 <[email protected]>"]
description = ""
repository = "https://github.com/mediar-ai/screenpipe"
diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/examples/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index 8f5b890d4..225289f66 100644
--- a/examples/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/examples/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.1.58"
+version = "0.1.59"
description = ""
authors = ["you"]
license = ""
diff --git a/screenpipe-server/Cargo.toml b/screenpipe-server/Cargo.toml
index 49d84d923..0281ba5ef 100644
--- a/screenpipe-server/Cargo.toml
+++ b/screenpipe-server/Cargo.toml
@@ -114,6 +114,10 @@ url = "2.4.0"
name = "db_benchmarks"
harness = false
+[[bench]]
+name = "new_db_benchmark"
+harness = false
+
[features]
default = []
static-ffmpeg = ["ffmpeg-next/static"]
diff --git a/screenpipe-server/benches/new_db_benchmark.rs b/screenpipe-server/benches/new_db_benchmark.rs
new file mode 100644
index 000000000..a4f85d73c
--- /dev/null
+++ b/screenpipe-server/benches/new_db_benchmark.rs
@@ -0,0 +1,63 @@
+use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
+use screenpipe_server::DatabaseManager;
+use screenpipe_vision::OcrEngine;
+use std::time::Duration;
+use tokio::runtime::Runtime;
+
+fn create_test_db() -> DatabaseManager {
+ let rt = Runtime::new().unwrap();
+ rt.block_on(async {
+ DatabaseManager::new("sqlite::memory:")
+ .await
+ .expect("Failed to create in-memory database")
+ })
+}
+
+fn bench_insert_ocr_text(c: &mut Criterion) {
+ let db = create_test_db();
+ let rt = Runtime::new().unwrap();
+
+ let mut group = c.benchmark_group("Database Insert OCR Text");
+ group.sample_size(100);
+ group.measurement_time(Duration::from_secs(10));
+
+ let test_cases = vec![
+ ("Short", "This is a short piece of text."),
+ ("Medium", "This is a medium-length piece of text that contains multiple sentences. It should be long enough to test the performance of inserting larger chunks of text into the database."),
+ ("Long", "This is a long piece of text that simulates a more realistic OCR result. It contains multiple paragraphs and various types of content.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
+ ("Code", "fn main() {\n println!(\"Hello, world!\");\n let x = 5;\n let y = 10;\n println!(\"x + y = {}\", x + y);\n}"),
+ ("Mixed", "This text contains a mix of content types:\n\n1. Plain text\n2. Code snippet: `let result = 2 + 2;`\n3. URL: https://www.example.com\n4. Special characters: !@#$%^&*()\n5. Numbers: 12345 67890"),
+ ];
+
+ for (case_name, text) in test_cases {
+ group.bench_with_input(BenchmarkId::new("Insert", case_name), text, |b, i| {
+ b.to_async(&rt).iter(|| async {
+ let frame_id = black_box(1);
+ let text = black_box(i);
+ let text_json =
+ black_box(format!("{{\"text\": \"{}\"}}", text.replace("\"", "\\\"")));
+ let app_name = black_box("BenchmarkApp");
+ let window_name = black_box("BenchmarkWindow");
+ let ocr_engine = black_box(OcrEngine::AppleNative);
+ let focused = black_box(true);
+
+ db.insert_ocr_text(
+ frame_id,
+ text,
+ &text_json,
+ app_name,
+ window_name,
+ std::sync::Arc::new(ocr_engine),
+ focused,
+ )
+ .await
+ .unwrap();
+ })
+ });
+ }
+
+ group.finish();
+}
+
+criterion_group!(benches, bench_insert_ocr_text);
+criterion_main!(benches);
diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rs
index 8d9c8d1dc..ff25b1b67 100644
--- a/screenpipe-server/src/db.rs
+++ b/screenpipe-server/src/db.rs
@@ -363,62 +363,62 @@ impl DatabaseManager {
{
Ok(Ok(())) => {
// Chunk the text before inserting into chunked text index
- const CHUNKING_ENGINE: &str = "local_simple";
-
- let chunks = match CHUNKING_ENGINE {
- "local_simple" => text_chunking_simple(text),
- "candle_jina_bert" => text_chunking_by_similarity(text).await,
- "unstructured" => unstructured_chunking(text)
- .map_err(|e| anyhow::anyhow!(e))
- .and_then(|chunks| Ok(chunks)),
- _ => text_chunking_simple(text), // Default to simple chunking for unknown engines
- };
-
- match chunks {
- Ok(chunks) => {
- debug!("Successfully chunked text into {} chunks", chunks.len());
- for chunk in chunks.iter() {
- if let Err(e) = self
- .insert_chunked_text(
- frame_id,
- chunk,
- Utc::now(),
- &format!("{:?}", *ocr_engine),
- CHUNKING_ENGINE,
- ContentSource::Screen,
- )
- .await
- {
- error!("Failed to insert chunk into chunked text index: {}", e);
- }
- }
- }
- Err(e) => {
- error!("Failed to chunk text: {}", e);
- // Fallback to inserting the whole text if chunking fails
- debug!("Inserting whole text as a single chunk");
- if let Err(e) = self
- .insert_chunked_text(
- frame_id,
- text,
- Utc::now(),
- &format!("{:?}", *ocr_engine),
- "No_Chunking",
- ContentSource::Screen,
- )
- .await
- {
- error!(
- "Failed to insert whole text into chunked text index: {}",
- e
- );
- }
- }
- }
- debug!(
- "Successfully completed OCR text insertion for frame_id: {} on attempt {}",
- frame_id, attempt
- );
+ // const CHUNKING_ENGINE: &str = "local_simple";
+
+ // let chunks = match CHUNKING_ENGINE {
+ // "local_simple" => text_chunking_simple(text),
+ // "candle_jina_bert" => text_chunking_by_similarity(text).await,
+ // "unstructured" => unstructured_chunking(text)
+ // .map_err(|e| anyhow::anyhow!(e))
+ // .and_then(|chunks| Ok(chunks)),
+ // _ => text_chunking_simple(text), // Default to simple chunking for unknown engines
+ // };
+
+ // match chunks {
+ // Ok(chunks) => {
+ // debug!("Successfully chunked text into {} chunks", chunks.len());
+ // for chunk in chunks.iter() {
+ // if let Err(e) = self
+ // .insert_chunked_text(
+ // frame_id,
+ // chunk,
+ // Utc::now(),
+ // &format!("{:?}", *ocr_engine),
+ // CHUNKING_ENGINE,
+ // ContentSource::Screen,
+ // )
+ // .await
+ // {
+ // error!("Failed to insert chunk into chunked text index: {}", e);
+ // }
+ // }
+ // }
+ // Err(e) => {
+ // error!("Failed to chunk text: {}", e);
+ // // Fallback to inserting the whole text if chunking fails
+ // debug!("Inserting whole text as a single chunk");
+ // if let Err(e) = self
+ // .insert_chunked_text(
+ // frame_id,
+ // text,
+ // Utc::now(),
+ // &format!("{:?}", *ocr_engine),
+ // "No_Chunking",
+ // ContentSource::Screen,
+ // )
+ // .await
+ // {
+ // error!(
+ // "Failed to insert whole text into chunked text index: {}",
+ // e
+ // );
+ // }
+ // }
+ // }
+ // debug!(
+ // "Successfully completed OCR text insertion for frame_id: {} on attempt {}",
+ // frame_id, attempt
+ // );
return Ok(());
}
Ok(Err(e)) => {