Skip to content

Commit b7bb2b1

Browse files
authored
Merge pull request #2 from iohub/fix-hybridsearch
fix: resolve empty MCP semantic search results
2 parents 55716c7 + 1a7b193 commit b7bb2b1

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

rust-core/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-core/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,6 @@ impl Config {
236236
pub fn compute_project_hash(project_root: &PathBuf) -> String {
237237
format!("{:x}", md5::compute(project_root.to_string_lossy().as_bytes()))
238238
}
239+
240+
239241
}

rust-core/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
121121
pb.set_phase("Building vector embeddings...");
122122
pb.set_stats(stats.total_files, stats.total_functions);
123123

124-
let db_path = index_dir.to_string_lossy().to_string();
124+
let db_path = Config::lancedb_dir(&project_hash).to_string_lossy().to_string();
125125
let collection = format!("codeseek_{}", &project_hash[..8]);
126126

127+
// 创建BM25索引用于稀疏检索通道
128+
let bm25_dir = Config::bm25_dir(&project_hash);
129+
let bm25_index = TantivyBm25Index::open_or_create(&bm25_dir)
130+
.ok()
131+
.map(|idx| Arc::new(idx) as Arc<dyn codeseek::storage::traits_bm25::TextSearchProvider>);
132+
127133
embedding_done = true; // mark attempted; actual success tracked below
128-
match EmbeddingService::new(&db_path, collection, Some(cfg), None).await {
134+
match EmbeddingService::new(&db_path, collection, Some(cfg), bm25_index).await {
129135
Ok(es) => {
130136
if let Err(e) = es.ensure_collection().await {
131137
warn!("Embedding table setup failed: {}", e);

rust-core/src/mcp/server.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn run_cli(args: &[&str]) -> Result<String, String> {
143143
let output = std::process::Command::new(&bin)
144144
.args(args)
145145
.stdout(std::process::Stdio::piped())
146-
.stderr(std::process::Stdio::null())
146+
.stderr(std::process::Stdio::piped())
147147
.output()
148148
.map_err(|e| format!("Failed to run codeseek: {}", e))?;
149149

@@ -152,6 +152,13 @@ fn run_cli(args: &[&str]) -> Result<String, String> {
152152
.map_err(|e| format!("Invalid UTF-8 output: {}", e))
153153
} else {
154154
let stderr = String::from_utf8_lossy(&output.stderr);
155-
Err(format!("codeseek exited with {}: {}", output.status, stderr.trim()))
155+
let stdout = String::from_utf8_lossy(&output.stdout);
156+
if stderr.is_empty() && stdout.is_empty() {
157+
Err(format!("codeseek exited with {}", output.status))
158+
} else if stderr.is_empty() {
159+
Err(format!("codeseek exited with {}: {}", output.status, stdout.trim()))
160+
} else {
161+
Err(format!("codeseek exited with {}: {}", output.status, stderr.trim()))
162+
}
156163
}
157164
}

0 commit comments

Comments
 (0)