mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-30 03:10:45 +02:00
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:
@@ -1,21 +1,8 @@
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::fmt;
|
||||
|
||||
use crate::scoring::FusionWeights;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RetrievalStrategy {
|
||||
/// Primary hybrid chunk retrieval for search/chat (formerly Revised)
|
||||
#[default]
|
||||
Default,
|
||||
/// Entity retrieval for suggesting relationships when creating manual entities
|
||||
RelationshipSuggestion,
|
||||
/// Entity retrieval for context during content ingestion
|
||||
Ingestion,
|
||||
/// Unified search returning both chunks and entities
|
||||
Search,
|
||||
}
|
||||
pub use common::utils::config::RetrievalStrategy;
|
||||
|
||||
/// Configures which result types to include in Search strategy
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
@@ -30,41 +17,6 @@ pub enum SearchTarget {
|
||||
Both,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for RetrievalStrategy {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
match value.to_ascii_lowercase().as_str() {
|
||||
"default" => Ok(Self::Default),
|
||||
// Backward compatibility: treat "initial" and "revised" as "default"
|
||||
"initial" | "revised" => {
|
||||
tracing::warn!(
|
||||
"Retrieval strategy '{}' is deprecated. Use 'default' instead. \
|
||||
The 'initial' strategy has been removed in favor of the simpler hybrid chunk retrieval.",
|
||||
value
|
||||
);
|
||||
Ok(Self::Default)
|
||||
}
|
||||
"relationship_suggestion" => Ok(Self::RelationshipSuggestion),
|
||||
"ingestion" => Ok(Self::Ingestion),
|
||||
"search" => Ok(Self::Search),
|
||||
other => Err(format!("unknown retrieval strategy '{other}'")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for RetrievalStrategy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let label = match self {
|
||||
RetrievalStrategy::Default => "default",
|
||||
RetrievalStrategy::RelationshipSuggestion => "relationship_suggestion",
|
||||
RetrievalStrategy::Ingestion => "ingestion",
|
||||
RetrievalStrategy::Search => "search",
|
||||
};
|
||||
f.write_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
/// Two-variant flag that serializes as a bool for backward compatibility.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum BoolFlag {
|
||||
|
||||
@@ -256,11 +256,7 @@ pub async fn embed(ctx: &mut PipelineContext<'_>) -> Result<(), AppError> {
|
||||
} else {
|
||||
debug!("Generating query embedding for hybrid retrieval");
|
||||
let embedding = if let Some(provider) = ctx.embedding_provider {
|
||||
provider.embed(&ctx.input_text).await.map_err(|e| {
|
||||
AppError::InternalError(format!(
|
||||
"Failed to generate embedding with provider: {e}",
|
||||
))
|
||||
})?
|
||||
provider.embed(&ctx.input_text).await?
|
||||
} else {
|
||||
generate_embedding(ctx.openai_client, &ctx.input_text, ctx.db_client).await?
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user