use crate::server::MemoryMCPServer;
use anyhow::Result;
use serde_json::json;
use std::sync::Arc;
use tracing::debug;
impl MemoryMCPServer {
pub async fn execute_search_by_embedding(
&self,
input: crate::mcp::tools::embeddings::SearchByEmbeddingInput,
) -> Result<serde_json::Value> {
self.track_tool_usage("search_by_embedding").await;
let request_id = format!(
"search_by_embedding_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_nanos()
);
self.monitoring
.start_request(request_id.clone(), "search_by_embedding".to_string())
.await;
debug!(
"Searching by embedding (dimension: {}, limit: {}, threshold: {})",
input.embedding.len(),
input.limit,
input.similarity_threshold
);
let tool = crate::mcp::tools::embeddings::EmbeddingTools::new(Arc::clone(&self.memory));
let result = tool.execute_search_by_embedding(input).await;
self.monitoring
.end_request(&request_id, result.is_ok(), None)
.await;
let output = result?;
Ok(json!(output))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[allow(clippy::manual_async_fn)]
fn test_search_by_embedding_signature_compile() {
use crate::mcp::tools::embeddings::SearchByEmbeddingInput;
fn method_signature(
_server: &MemoryMCPServer,
_input: SearchByEmbeddingInput,
) -> impl std::future::Future<Output = Result<serde_json::Value>> {
async { Ok(json!({})) }
}
let _ = method_signature; }
}