chore: centralize embedding errors, retrieval strategy, and test DB helpers.

Replace anyhow in embedding production code with EmbeddingError, move
RetrievalStrategy into common config, and deduplicate Surreal test setup
via common::test_utils.
This commit is contained in:
Per Stark
2026-05-29 14:35:07 +02:00
parent e3bb2935d0
commit d3443d4153
17 changed files with 366 additions and 304 deletions
+3 -27
View File
@@ -20,6 +20,7 @@ use crate::{
auth_middleware::RequireUser,
response_middleware::{HtmlError, TemplateResponse},
},
utils::truncate::{first_non_empty_line, truncate_with_ellipsis},
};
/// Serde deserialization decorator to map empty Strings to None,
@@ -41,31 +42,6 @@ fn source_id_suffix(source_id: &str) -> String {
source_id[start..].to_string()
}
fn truncate_label(value: &str, max_chars: usize) -> String {
let mut end = None;
for (count, (idx, _)) in value.char_indices().enumerate() {
if count == max_chars {
end = Some(idx);
break;
}
}
match end {
Some(idx) => format!("{}...", &value[..idx]),
None => value.to_string(),
}
}
fn first_non_empty_line(text: &str, max_chars: usize) -> Option<String> {
for line in text.lines() {
let trimmed = line.trim();
if !trimmed.is_empty() {
return Some(truncate_label(trimmed, max_chars));
}
}
None
}
#[derive(Deserialize)]
struct UrlInfoLabel {
#[serde(default)]
@@ -121,7 +97,7 @@ fn build_source_label(row: &SourceLabelRow) -> String {
if let Some(context) = row.context.as_ref() {
let trimmed = context.trim();
if !trimmed.is_empty() {
return truncate_label(trimmed, MAX_LABEL_CHARS);
return truncate_with_ellipsis(trimmed, MAX_LABEL_CHARS);
}
}
@@ -131,7 +107,7 @@ fn build_source_label(row: &SourceLabelRow) -> String {
let category = row.category.trim();
if !category.is_empty() {
return truncate_label(category, MAX_LABEL_CHARS);
return truncate_with_ellipsis(category, MAX_LABEL_CHARS);
}
format!("Text snippet: {}", source_id_suffix(&row.id))