perf(mcp): Batch semantic code search embeddings to resolve CPU bottleneck and fix linting warnings

This commit is contained in:
Riz Ashraf committed 2026-09-30 09:07:14 +01:00
1 parent 185c3c999e
commit ec0472155f
4 files changed
+25 -9

No files matched your search

+11
View File
@@ -40,3 +40,14 @@ pub fn cosine_similarity(a: &[f32], b: &[f32]) -> f32 {
dot_product / (norm_a * norm_b)
}
}
pub async fn generate_embeddings_async(texts: Vec<String>) -> Result<Vec<Vec<f32>>, String> {
if texts.is_empty() {
return Ok(Vec::new());
}
tokio::task::spawn_blocking(move || {
let model_mutex = get_embedding_model()?;
let mut model = model_mutex.lock().map_err(|e| e.to_string())?;
let embeddings = model.embed(texts, None).map_err(|e| e.to_string())?;
Ok(embeddings)
}).await.map_err(|e| e.to_string())?
}