feat: Phase 1 handover - schema migration, correction mechanism, API fixes
Schema changes: dev.chunks->dev.chunk, remove old_chunk_id/chunk_index Correction: asr-1.json format, generate/apply scripts API: 37/37 endpoints fixed and tested Docs: HANDOVER_V2.0.md for M4
This commit is contained in:
@@ -13,6 +13,8 @@ use crate::core::embedding::Embedder;
|
||||
pub struct SmartSearchRequest {
|
||||
pub uuid: String,
|
||||
pub query: String,
|
||||
pub page: Option<usize>,
|
||||
pub page_size: Option<usize>,
|
||||
pub limit: Option<usize>,
|
||||
}
|
||||
|
||||
@@ -41,6 +43,8 @@ pub struct SearchResult {
|
||||
pub struct SmartSearchResponse {
|
||||
pub query: String,
|
||||
pub results: Vec<SearchResult>,
|
||||
pub page: usize,
|
||||
pub page_size: usize,
|
||||
pub strategy: String,
|
||||
}
|
||||
|
||||
@@ -51,7 +55,18 @@ pub async fn smart_search(
|
||||
Json(req): Json<SmartSearchRequest>,
|
||||
) -> Result<Json<SmartSearchResponse>, (StatusCode, Json<serde_json::Value>)> {
|
||||
let db = &state.db;
|
||||
let limit = req.limit.unwrap_or(5);
|
||||
let page = req.page.unwrap_or(1).max(1);
|
||||
// Backward compat: if old `limit` sent without `page_size`, use limit as page_size
|
||||
let page_size = if req.page_size.is_some() {
|
||||
req.page_size.unwrap()
|
||||
} else if req.limit.is_some() && req.page.is_none() {
|
||||
req.limit.unwrap()
|
||||
} else {
|
||||
5
|
||||
}
|
||||
.max(1);
|
||||
let hard_limit = req.limit.unwrap_or(usize::MAX);
|
||||
let limit = hard_limit.min(page_size);
|
||||
|
||||
// 1. Generate Embedding using EmbeddingGemma via MOMENTRY_EMBED_URL
|
||||
let embedder = Embedder::new("embeddinggemma-300m".to_string());
|
||||
@@ -83,6 +98,8 @@ pub async fn smart_search(
|
||||
return Ok(Json(SmartSearchResponse {
|
||||
query: req.query,
|
||||
results: vec![],
|
||||
page,
|
||||
page_size,
|
||||
strategy: "semantic_vector_search".to_string(),
|
||||
}));
|
||||
}
|
||||
@@ -145,13 +162,15 @@ pub async fn smart_search(
|
||||
});
|
||||
|
||||
// 7. Limit the final results (optional, but good for API consistency)
|
||||
let limit = req.limit.unwrap_or(5) * 5; // Allow more children per parent context
|
||||
results.truncate(limit);
|
||||
let truncate_limit = hard_limit.min(page_size * 5); // Allow more children per parent context
|
||||
results.truncate(truncate_limit);
|
||||
|
||||
// 8. Format Response
|
||||
let response = SmartSearchResponse {
|
||||
query: req.query,
|
||||
results,
|
||||
page,
|
||||
page_size,
|
||||
strategy: "drill_down_semantic_search".to_string(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user