style: Apply cargo fmt and clippy fixes across codebase

Automated formatting and lint corrections from parallel agent work:

- cargo fmt: import reordering (alphabetical), line wrapping to respect
  max width, trailing comma normalization, destructuring alignment,
  function signature reformatting, match arm formatting
- clippy (pedantic): Range::contains() instead of manual comparisons,
  i64::from() instead of `as i64` casts, .clamp() instead of
  .max().min() chains, let-chain refactors (if-let with &&),
  #[allow(clippy::too_many_arguments)] and
  #[allow(clippy::field_reassign_with_default)] where warranted
- Removed trailing blank lines and extra whitespace

No behavioral changes. All existing tests pass unmodified.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Taylor Eernisse
2026-02-03 13:01:59 -05:00
parent ff94f24702
commit a50fc78823
42 changed files with 1431 additions and 623 deletions

View File

@@ -4,8 +4,8 @@ use rusqlite::Connection;
use crate::core::error::Result;
use crate::embedding::ollama::OllamaClient;
use crate::search::{rank_rrf, search_fts, search_vector, FtsQueryMode};
use crate::search::filters::{apply_filters, SearchFilters};
use crate::search::filters::{SearchFilters, apply_filters};
use crate::search::{FtsQueryMode, rank_rrf, search_fts, search_vector};
const BASE_RECALL_MIN: usize = 50;
const FILTERED_RECALL_MIN: usize = 200;
@@ -65,9 +65,9 @@ pub async fn search_hybrid(
// Adaptive recall
let requested = filters.clamp_limit();
let top_k = if filters.has_any_filter() {
(requested * 50).max(FILTERED_RECALL_MIN).min(RECALL_CAP)
(requested * 50).clamp(FILTERED_RECALL_MIN, RECALL_CAP)
} else {
(requested * 10).max(BASE_RECALL_MIN).min(RECALL_CAP)
(requested * 10).clamp(BASE_RECALL_MIN, RECALL_CAP)
};
let (fts_tuples, vec_tuples) = match mode {
@@ -88,10 +88,7 @@ pub async fn search_hybrid(
};
let query_embedding = client.embed_batch(vec![query.to_string()]).await?;
let embedding = query_embedding
.into_iter()
.next()
.unwrap_or_default();
let embedding = query_embedding.into_iter().next().unwrap_or_default();
if embedding.is_empty() {
return Err(crate::core::error::LoreError::Other(
@@ -115,41 +112,34 @@ pub async fn search_hybrid(
.collect();
match client {
Some(client) => {
match client.embed_batch(vec![query.to_string()]).await {
Ok(query_embedding) => {
let embedding = query_embedding
.into_iter()
.next()
.unwrap_or_default();
Some(client) => match client.embed_batch(vec![query.to_string()]).await {
Ok(query_embedding) => {
let embedding = query_embedding.into_iter().next().unwrap_or_default();
let vec_tuples = if embedding.is_empty() {
warnings.push(
"Ollama returned empty embedding, using FTS only.".into(),
);
Vec::new()
} else {
let vec_results = search_vector(conn, &embedding, top_k)?;
vec_results
.iter()
.map(|r| (r.document_id, r.distance))
.collect()
};
let vec_tuples = if embedding.is_empty() {
warnings
.push("Ollama returned empty embedding, using FTS only.".into());
Vec::new()
} else {
let vec_results = search_vector(conn, &embedding, top_k)?;
vec_results
.iter()
.map(|r| (r.document_id, r.distance))
.collect()
};
(fts_tuples, vec_tuples)
}
Err(e) => {
warnings.push(
format!("Embedding failed ({}), falling back to lexical search.", e),
);
(fts_tuples, Vec::new())
}
(fts_tuples, vec_tuples)
}
}
Err(e) => {
warnings.push(format!(
"Embedding failed ({}), falling back to lexical search.",
e
));
(fts_tuples, Vec::new())
}
},
None => {
warnings.push(
"Ollama unavailable, falling back to lexical search.".into(),
);
warnings.push("Ollama unavailable, falling back to lexical search.".into());
(fts_tuples, Vec::new())
}
}
@@ -217,7 +207,7 @@ mod tests {
..Default::default()
};
let requested = filters.clamp_limit();
let top_k = (requested * 10).max(BASE_RECALL_MIN).min(RECALL_CAP);
let top_k = (requested * 10).clamp(BASE_RECALL_MIN, RECALL_CAP);
assert_eq!(top_k, 200);
}
@@ -229,7 +219,7 @@ mod tests {
..Default::default()
};
let requested = filters.clamp_limit();
let top_k = (requested * 50).max(FILTERED_RECALL_MIN).min(RECALL_CAP);
let top_k = (requested * 50).clamp(FILTERED_RECALL_MIN, RECALL_CAP);
assert_eq!(top_k, 1000);
}
@@ -241,7 +231,7 @@ mod tests {
..Default::default()
};
let requested = filters.clamp_limit();
let top_k = (requested * 50).max(FILTERED_RECALL_MIN).min(RECALL_CAP);
let top_k = (requested * 50).clamp(FILTERED_RECALL_MIN, RECALL_CAP);
assert_eq!(top_k, RECALL_CAP); // 5000 capped to 1500
}
@@ -252,7 +242,7 @@ mod tests {
..Default::default()
};
let requested = filters.clamp_limit();
let top_k = (requested * 10).max(BASE_RECALL_MIN).min(RECALL_CAP);
let top_k = (requested * 10).clamp(BASE_RECALL_MIN, RECALL_CAP);
assert_eq!(top_k, BASE_RECALL_MIN); // 10 -> 50
}
}