Skip to content

Commit 49979fc

Browse files
committed
Fix: Compilation errors for dual-mode search
Added cloud feature and fixed all compilation errors in search code: **Cargo.toml changes:** - Added `cloud` feature that enables codegraph-graph/surrealdb + embeddings-jina - Updated codegraph-graph dependency to support feature flags **server.rs fixes:** - Changed feature flags from "embeddings" to "cloud" for cloud_search_impl - Added faiss::Index trait import - Fixed PathBuf to &str conversion for faiss::read_index() - Updated FAISS search to handle SearchResult struct (not tuple) - Fixed node_ids type conversion from Idx to i64 - Added ServerState and stub functions for official_server.rs compatibility **jina_provider.rs fix:** - Made RerankResult and its fields (index, relevance_score) public All dual-mode search code now compiles correctly. Remaining errors are in unused legacy MCP server code that doesn't affect the search functionality. Ready for testing with: cargo build --features faiss,cloud
1 parent 82653ab commit 49979fc

File tree

3 files changed

+74
-19
lines changed

3 files changed

+74
-19
lines changed

crates/codegraph-mcp/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ num_cpus = { workspace = true }
4848
# Internal dependencies
4949
codegraph-core = { workspace = true }
5050
codegraph-parser = { workspace = true }
51-
codegraph-graph = { workspace = true }
51+
codegraph-graph = { workspace = true, features = [] }
5252
codegraph-vector = { workspace = true, optional = true, default-features = false }
5353
codegraph-ai = { workspace = true, optional = true } # Re-enabled for AI-powered symbol resolution
5454
faiss = { workspace = true, optional = true }
@@ -80,6 +80,7 @@ embeddings-local = ["embeddings", "codegraph-vector/local-embeddings"]
8080
embeddings-openai = ["embeddings", "codegraph-vector/openai"]
8181
embeddings-ollama = ["embeddings", "codegraph-vector/ollama"]
8282
embeddings-jina = ["embeddings", "codegraph-vector/jina"]
83+
cloud = ["embeddings-jina", "codegraph-graph/surrealdb"]
8384
server-http = ["dep:axum", "dep:hyper"]
8485
qwen-integration = []
8586
ai-enhanced = ["dep:codegraph-ai", "faiss", "embeddings"]

crates/codegraph-mcp/src/server.rs

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use crate::qwen::{QwenClient, QwenConfig};
1818
// and recreating embedding generator (50-500ms overhead)
1919
#[cfg(feature = "faiss")]
2020
use faiss::index::IndexImpl;
21+
#[cfg(feature = "faiss")]
22+
use faiss::Index;
2123

2224
#[cfg(feature = "faiss")]
2325
static INDEX_CACHE: Lazy<DashMap<PathBuf, Arc<parking_lot::Mutex<IndexImpl>>>> =
@@ -575,7 +577,11 @@ async fn faiss_search_impl(
575577
"📥 Loading FAISS index from disk (first-time): {}",
576578
index_path.display()
577579
);
578-
let idx = faiss::read_index(&index_path)?;
580+
let idx = faiss::read_index(
581+
index_path
582+
.to_str()
583+
.ok_or_else(|| anyhow::anyhow!("Invalid index path"))?,
584+
)?;
579585
Ok::<_, anyhow::Error>(Arc::new(parking_lot::Mutex::new(idx)))
580586
})?
581587
.clone();
@@ -585,16 +591,26 @@ async fn faiss_search_impl(
585591
// Search FAISS index
586592
let start_search = Instant::now();
587593
let search_limit = limit * 10; // Overretrieve for filtering
588-
let (distances, labels) = {
589-
let index = index_arc.lock();
590-
let query_vec = vec![query_embedding.clone()];
591-
index.search(&query_vec, search_limit)?
594+
let search_result = {
595+
let mut index = index_arc.lock();
596+
index.search(&query_embedding, search_limit)?
592597
};
593598
let search_time = start_search.elapsed().as_millis() as u64;
594599

595600
// Get node IDs from labels
596601
let start_node_load = Instant::now();
597-
let node_ids: Vec<i64> = labels[0].iter().filter(|&&id| id >= 0).copied().collect();
602+
let node_ids: Vec<i64> = search_result
603+
.labels
604+
.iter()
605+
.filter_map(|&id| {
606+
let id_i64 = id as i64;
607+
if id_i64 >= 0 {
608+
Some(id_i64)
609+
} else {
610+
None
611+
}
612+
})
613+
.collect();
598614

599615
if node_ids.is_empty() {
600616
return Ok(json!({
@@ -636,7 +652,7 @@ async fn faiss_search_impl(
636652

637653
let results: Vec<Value> = nodes
638654
.iter()
639-
.zip(distances[0].iter())
655+
.zip(search_result.distances.iter())
640656
.filter(|(node, _)| {
641657
// Filter by language if specified
642658
if let Some(ref langs) = lang_filter {
@@ -712,16 +728,16 @@ pub async fn bin_search_with_scores_shared(
712728
faiss_search_impl(query, paths, langs, limit, graph).await
713729
}
714730
SearchMode::Cloud => {
715-
#[cfg(feature = "embeddings")]
731+
#[cfg(feature = "cloud")]
716732
{
717733
tracing::info!("🌐 Search Mode: Cloud (SurrealDB HNSW + Jina reranking)");
718734
cloud_search_impl(query, paths, langs, limit, graph).await
719735
}
720-
#[cfg(not(feature = "embeddings"))]
736+
#[cfg(not(feature = "cloud"))]
721737
{
722738
Err(anyhow::anyhow!(
723-
"Cloud mode requires embeddings feature. Either:\n\
724-
1. Rebuild with --features embeddings, or\n\
739+
"Cloud mode requires cloud feature. Either:\n\
740+
1. Rebuild with --features cloud, or\n\
725741
2. Use local mode: CODEGRAPH_EMBEDDING_PROVIDER=local"
726742
))
727743
}
@@ -730,7 +746,7 @@ pub async fn bin_search_with_scores_shared(
730746
}
731747

732748
/// Cloud search implementation using SurrealDB HNSW + Jina embeddings + reranking
733-
#[cfg(feature = "embeddings")]
749+
#[cfg(feature = "cloud")]
734750
async fn cloud_search_impl(
735751
query: String,
736752
paths: Option<Vec<String>>,
@@ -774,7 +790,7 @@ async fn cloud_search_impl(
774790
let start_search = Instant::now();
775791

776792
// Build filter parameters
777-
let node_type_filter = langs.as_ref().map(|langs| {
793+
let node_type_filter = langs.as_ref().and_then(|langs| {
778794
langs
779795
.iter()
780796
.filter_map(|l| match l.to_lowercase().as_str() {
@@ -830,7 +846,7 @@ async fn cloud_search_impl(
830846
let mut rerank_time = 0u64;
831847

832848
// Try to create Jina provider for reranking
833-
#[cfg(feature = "jina")]
849+
#[cfg(feature = "embeddings-jina")]
834850
let reranked_results: Vec<(usize, f32)> = {
835851
match codegraph_vector::JinaConfig::default().api_key.is_empty() {
836852
true => {
@@ -885,7 +901,7 @@ async fn cloud_search_impl(
885901
}
886902
};
887903

888-
#[cfg(not(feature = "jina"))]
904+
#[cfg(not(feature = "embeddings-jina"))]
889905
let reranked_results: Vec<(usize, f32)> = {
890906
tracing::info!("Jina feature not enabled, using HNSW scores only");
891907
(0..nodes.len()).map(|i| (i, search_results[i].1)).collect()
@@ -1004,6 +1020,44 @@ pub async fn bin_search_with_scores(
10041020
bin_search_with_scores_shared(query, paths, langs, limit, &graph).await
10051021
}
10061022

1023+
// Stub implementations for functions called by official_server.rs but not yet implemented
1024+
pub struct ServerState {
1025+
pub graph: Arc<tokio::sync::Mutex<codegraph_graph::CodeGraph>>,
1026+
}
1027+
1028+
pub async fn enhanced_search(_state: &ServerState, _params: Value) -> anyhow::Result<Value> {
1029+
Err(anyhow::anyhow!("enhanced_search not yet implemented"))
1030+
}
1031+
1032+
pub async fn pattern_detection(_state: &ServerState, _params: Value) -> anyhow::Result<Value> {
1033+
Err(anyhow::anyhow!("pattern_detection not yet implemented"))
1034+
}
1035+
1036+
pub async fn graph_neighbors(_state: &ServerState, _params: Value) -> anyhow::Result<Value> {
1037+
Err(anyhow::anyhow!("graph_neighbors not yet implemented"))
1038+
}
1039+
1040+
pub async fn graph_traverse(_state: &ServerState, _params: Value) -> anyhow::Result<Value> {
1041+
Err(anyhow::anyhow!("graph_traverse not yet implemented"))
1042+
}
1043+
1044+
pub async fn build_comprehensive_context(
1045+
_state: &ServerState,
1046+
_params: Value,
1047+
) -> anyhow::Result<String> {
1048+
Err(anyhow::anyhow!(
1049+
"build_comprehensive_context not yet implemented"
1050+
))
1051+
}
1052+
1053+
pub async fn semantic_intelligence(_state: &ServerState, _params: Value) -> anyhow::Result<Value> {
1054+
Err(anyhow::anyhow!("semantic_intelligence not yet implemented"))
1055+
}
1056+
1057+
pub async fn impact_analysis(_state: &ServerState, _params: Value) -> anyhow::Result<Value> {
1058+
Err(anyhow::anyhow!("impact_analysis not yet implemented"))
1059+
}
1060+
10071061
#[cfg(test)]
10081062
mod tests {
10091063
use super::*;

crates/codegraph-vector/src/jina_provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ struct RerankResponse {
9393
}
9494

9595
#[derive(Debug, Deserialize)]
96-
struct RerankResult {
97-
index: usize,
98-
relevance_score: f32,
96+
pub struct RerankResult {
97+
pub index: usize,
98+
pub relevance_score: f32,
9999
}
100100

101101
/// Error response from Jina API

0 commit comments

Comments
 (0)