mirror of
https://gitea.ingwaz.work/Ingwaz/openbrain-mcp.git
synced 2026-06-16 06:17:08 +00:00
Add hybrid text plus vector memory search
This commit is contained in:
@@ -11,6 +11,7 @@ pub struct Config {
|
||||
pub server: ServerConfig,
|
||||
pub database: DatabaseConfig,
|
||||
pub embedding: EmbeddingConfig,
|
||||
pub query: QueryConfig,
|
||||
pub auth: AuthConfig,
|
||||
}
|
||||
|
||||
@@ -45,6 +46,15 @@ pub struct EmbeddingConfig {
|
||||
pub dimension: usize,
|
||||
}
|
||||
|
||||
/// Query scoring configuration
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct QueryConfig {
|
||||
#[serde(default = "default_vector_weight")]
|
||||
pub vector_weight: f32,
|
||||
#[serde(default = "default_text_weight")]
|
||||
pub text_weight: f32,
|
||||
}
|
||||
|
||||
/// Authentication configuration
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct AuthConfig {
|
||||
@@ -86,6 +96,8 @@ fn default_db_port() -> u16 { 5432 }
|
||||
fn default_pool_size() -> usize { 10 }
|
||||
fn default_model_path() -> String { "models/all-MiniLM-L6-v2".to_string() }
|
||||
fn default_embedding_dim() -> usize { 384 }
|
||||
fn default_vector_weight() -> f32 { 0.6 }
|
||||
fn default_text_weight() -> f32 { 0.4 }
|
||||
fn default_auth_enabled() -> bool { false }
|
||||
|
||||
impl Config {
|
||||
@@ -104,6 +116,9 @@ impl Config {
|
||||
// Embedding settings
|
||||
.set_default("embedding.model_path", default_model_path())?
|
||||
.set_default("embedding.dimension", default_embedding_dim() as i64)?
|
||||
// Query settings
|
||||
.set_default("query.vector_weight", default_vector_weight() as f64)?
|
||||
.set_default("query.text_weight", default_text_weight() as f64)?
|
||||
// Auth settings
|
||||
.set_default("auth.enabled", default_auth_enabled())?
|
||||
// Load from environment with OPENBRAIN_ prefix
|
||||
@@ -114,7 +129,21 @@ impl Config {
|
||||
)
|
||||
.build()?;
|
||||
|
||||
Ok(config.try_deserialize()?)
|
||||
let mut config: Self = config.try_deserialize()?;
|
||||
|
||||
// Keep compatibility with plain env names proposed in issue #17.
|
||||
if let Ok(vector_weight) = std::env::var("VECTOR_WEIGHT") {
|
||||
if let Ok(parsed) = vector_weight.parse::<f32>() {
|
||||
config.query.vector_weight = parsed;
|
||||
}
|
||||
}
|
||||
if let Ok(text_weight) = std::env::var("TEXT_WEIGHT") {
|
||||
if let Ok(parsed) = text_weight.parse::<f32>() {
|
||||
config.query.text_weight = parsed;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +166,10 @@ impl Default for Config {
|
||||
model_path: default_model_path(),
|
||||
dimension: default_embedding_dim(),
|
||||
},
|
||||
query: QueryConfig {
|
||||
vector_weight: default_vector_weight(),
|
||||
text_weight: default_text_weight(),
|
||||
},
|
||||
auth: AuthConfig {
|
||||
enabled: default_auth_enabled(),
|
||||
api_keys: Vec::new(),
|
||||
|
||||
Reference in New Issue
Block a user