Ship floating launcher, automatic discovery and bounded media search improvements
This commit is contained in:
1 parent
01279a6b25
commit
521966a2ac
43 files changed
+3165
-267
No files matched your search
@@ -0,0 +1,122 @@
|
||||
//! Actual query retrieval against the owned, verified README fixture index.
|
||||
use anyhow::{Context, Result};
|
||||
use searchi_service::{HybridSearch, SearchOptions};
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn required(name: &str) -> Result<PathBuf> {
|
||||
std::env::var_os(name)
|
||||
.map(PathBuf::from)
|
||||
.with_context(|| format!("Set {name}"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "Requires verified owned README fixture database and actual Google CPU model/runtime"]
|
||||
fn real_google_hybrid_shortlist_removes_unrelated_media_without_changing_raw_search() -> Result<()>
|
||||
{
|
||||
assert_eq!(std::env::var("SEARCHI_FORCE_CPU")?, "1");
|
||||
let db = required("SEARCHI_TEST_RELEVANCE_DATABASE")?;
|
||||
let model = required("SEARCHI_GEMMA_MODEL_DIR")?;
|
||||
let worker = required("SEARCHI_GEMMA_WORKER")?;
|
||||
let mut search = HybridSearch::open_query(db, model, worker, 1)?;
|
||||
let options = SearchOptions::default();
|
||||
let contract = "cancel the supplier partnership";
|
||||
let raw = search.search_semantic(contract, 50, &options)?;
|
||||
assert_eq!(raw[0].filename, "Supplier Agreement.pdf");
|
||||
assert!(raw
|
||||
.iter()
|
||||
.any(|result| result.filename == "Mountain Lake.jpg"));
|
||||
let measured = search.search_measured(contract, 50, &options, true)?;
|
||||
assert_eq!(measured.results[0].filename, "Supplier Agreement.pdf");
|
||||
assert!(measured.results.iter().all(
|
||||
|result| result.filename != "Mountain Lake.jpg" && result.filename != "Night Pier.jpg"
|
||||
));
|
||||
assert!(measured
|
||||
.metrics
|
||||
.trace
|
||||
.as_ref()
|
||||
.context("debug trace")?
|
||||
.iter()
|
||||
.any(|span| span.name == "hybrid.semantic_shortlist"
|
||||
&& span
|
||||
.counters
|
||||
.get("tail_candidates_pruned")
|
||||
.is_some_and(|count| *count > 0)));
|
||||
let raw_after = search.search_semantic(contract, 50, &options)?;
|
||||
assert_eq!(raw_after.len(), raw.len());
|
||||
assert_eq!(raw_after[0].score, raw[0].score);
|
||||
let image = search.search("mountains reflected in calm water", 50, &options)?;
|
||||
assert_eq!(image[0].filename, "Mountain Lake.jpg");
|
||||
assert!(image
|
||||
.iter()
|
||||
.all(|result| result.match_kind == "semantic_image"));
|
||||
assert_eq!(
|
||||
search.search("Mountain Lake.jpg", 1, &options)?[0].match_kind,
|
||||
"exact_filename"
|
||||
);
|
||||
let pdf = SearchOptions {
|
||||
extension: Some("pdf".into()),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(search
|
||||
.search(contract, 50, &pdf)?
|
||||
.iter()
|
||||
.all(|result| result.filename == "Supplier Agreement.pdf"));
|
||||
assert_eq!(
|
||||
search.search(contract, 1, &options)?[0].filename,
|
||||
"Supplier Agreement.pdf"
|
||||
);
|
||||
let excluded = SearchOptions {
|
||||
max_size: Some(1),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(search.search(contract, 50, &excluded)?.is_empty());
|
||||
eprintln!(
|
||||
"actual raw contract candidates={}, hybrid={}, image={}",
|
||||
raw.len(),
|
||||
measured.results.len(),
|
||||
image.len()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "Requires the owned verified README fixture database and real Google CPU runtime"]
|
||||
fn real_google_query_warms_during_an_owned_wal_writer() -> Result<()> {
|
||||
assert_eq!(std::env::var("SEARCHI_FORCE_CPU")?, "1");
|
||||
let db = required("SEARCHI_TEST_RELEVANCE_DATABASE")?;
|
||||
let model = required("SEARCHI_GEMMA_MODEL_DIR")?;
|
||||
let worker = required("SEARCHI_GEMMA_WORKER")?;
|
||||
let mut writer = rusqlite::Connection::open(&db)?;
|
||||
let old_dirty: i64 = writer.query_row(
|
||||
"SELECT dirty FROM name_statistics_state WHERE singleton=1",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)?;
|
||||
writer.execute(
|
||||
"UPDATE name_statistics_state SET dirty=1 WHERE singleton=1",
|
||||
[],
|
||||
)?;
|
||||
let transaction = writer.transaction_with_behavior(rusqlite::TransactionBehavior::Immediate)?;
|
||||
let outcome = (|| -> Result<()> {
|
||||
let mut search = HybridSearch::open_query(&db, model, worker, 1)?;
|
||||
search.warmup()?;
|
||||
let hits = search.search_semantic(
|
||||
"cancel the supplier partnership",
|
||||
1,
|
||||
&SearchOptions::default(),
|
||||
)?;
|
||||
assert_eq!(hits[0].filename, "Supplier Agreement.pdf");
|
||||
assert_eq!(
|
||||
search.worker_info().context("real worker info")?.device,
|
||||
"cpu"
|
||||
);
|
||||
eprintln!("Actual Google CPU query initialization, warmup and prepared retrieval succeeded with the WAL writer held");
|
||||
Ok(())
|
||||
})();
|
||||
transaction.rollback()?;
|
||||
writer.execute(
|
||||
"UPDATE name_statistics_state SET dirty=?1 WHERE singleton=1",
|
||||
[old_dirty],
|
||||
)?;
|
||||
outcome
|
||||
}
|
||||
Reference in new issue
Block a user