Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/codegraph-ai/src/llm_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub struct LLMResponse {
impl LLMResponse {
/// Check if the LLM wants to make tool calls
pub fn has_tool_calls(&self) -> bool {
self.tool_calls.as_ref().map_or(false, |tc| !tc.is_empty())
self.tool_calls.as_ref().is_some_and(|tc| !tc.is_empty())
}

/// Check if this is a final response (no more tool calls needed)
Expand Down
6 changes: 3 additions & 3 deletions crates/codegraph-ai/src/optimization/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ pub struct OptimizerMetrics {
pub gpu_utilization: Gauge,
}

impl OptimizerMetrics {
pub fn new() -> Self {
impl Default for OptimizerMetrics {
fn default() -> Self {
Self {
inference_requests_total: register_int_counter!(
"cg_ai_inference_requests_total",
Expand Down Expand Up @@ -326,7 +326,7 @@ pub struct ModelOptimizer {

impl ModelOptimizer {
pub fn new(model: Arc<dyn InferenceModel>, thresholds: MonitoringThresholds) -> Result<Self> {
let metrics = OptimizerMetrics::new();
let metrics = OptimizerMetrics::default();
let size = model.size_bytes().unwrap_or(0);
metrics.model_size_bytes.set(size as f64);
Ok(Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/codegraph-ai/src/qwen_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl QwenClient {
let response = timeout(
self.config.timeout,
self.client()?
.post(&format!("{}/api/generate", self.config.base_url))
.post(format!("{}/api/generate", self.config.base_url))
.json(&request)
.send(),
)
Expand Down Expand Up @@ -188,7 +188,7 @@ impl QwenClient {
let response = timeout(
Duration::from_secs(5),
self.client()?
.get(&format!("{}/api/tags", self.config.base_url))
.get(format!("{}/api/tags", self.config.base_url))
.send(),
)
.await
Expand Down Expand Up @@ -285,7 +285,7 @@ impl LLMProvider for QwenClient {
let response = timeout(
self.config.timeout,
self.client()?
.post(&format!("{}/api/generate", self.config.base_url))
.post(format!("{}/api/generate", self.config.base_url))
.json(&request)
.send(),
)
Expand Down
6 changes: 2 additions & 4 deletions crates/codegraph-core/benches/core_micro.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use codegraph_core::{CodeNode, Language, Location, NodeType};
use criterion::{
black_box, criterion_group, criterion_main, Bencher, BenchmarkId, Criterion, Throughput,
};
use serde_json;
use criterion::{criterion_group, criterion_main, Bencher, BenchmarkId, Criterion, Throughput};
use std::hint::black_box;

fn gen_node(i: usize) -> CodeNode {
CodeNode::new(
Expand Down
9 changes: 2 additions & 7 deletions crates/codegraph-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,13 @@ impl Default for SurrealDbConfig {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum DatabaseBackend {
#[default]
SurrealDb,
}

impl Default for DatabaseBackend {
fn default() -> Self {
Self::SurrealDb
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Default)]
pub struct DatabaseConfig {
#[serde(default)]
Expand Down
21 changes: 4 additions & 17 deletions crates/codegraph-core/src/config_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,35 +369,22 @@ pub struct PerformanceConfig {
}

/// Indexing configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct IndexingConfig {
/// Indexing tier: fast | balanced | full
#[serde(default)]
pub tier: IndexingTier,
}

impl Default for IndexingConfig {
fn default() -> Self {
Self {
tier: IndexingTier::default(),
}
}
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum IndexingTier {
#[default]
Fast,
Balanced,
Full,
}

impl Default for IndexingTier {
fn default() -> Self {
IndexingTier::Fast
}
}

impl std::str::FromStr for IndexingTier {
type Err = String;

Expand Down Expand Up @@ -1051,7 +1038,7 @@ mod tests {
fn test_default_config() {
let config = CodeGraphConfig::default();
assert_eq!(config.embedding.provider, "auto");
assert_eq!(config.llm.enabled, false);
assert!(!config.llm.enabled);
assert_eq!(config.llm.insights_mode, "context-only");
assert_eq!(config.indexing.tier, IndexingTier::Fast);
}
Expand Down
15 changes: 6 additions & 9 deletions crates/codegraph-core/src/embedding_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum EmbeddingProvider {
OpenAI,
#[default]
Local,
Cohere,
HuggingFace,
Jina,
Custom(String),
}

impl Default for EmbeddingProvider {
fn default() -> Self {
Self::Local
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct OpenAIEmbeddingConfig {
pub model: String,
Expand Down Expand Up @@ -449,8 +444,10 @@ mod tests {

#[test]
fn test_config_validation() {
let mut config = EmbeddingModelConfig::default();
config.dimension = 0;
let mut config = EmbeddingModelConfig {
dimension: 0,
..EmbeddingModelConfig::default()
};
assert!(config.validate().is_err());

config.dimension = 10000;
Expand Down
2 changes: 1 addition & 1 deletion crates/codegraph-core/src/incremental/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ mod tests {
};
let embedder = Arc::new(crate::integration::graph_vector::HasherEmbeddingService::new(64));
// Provide a graph instance for vector integrator; it won't be used for indexing path here.
let g_for_vec: Arc<dyn GraphStore> = Arc::new(InMemoryGraph {
let g_for_vec: Arc<dyn GraphStore + Send + Sync> = Arc::new(InMemoryGraph {
nodes: DashMap::new(),
});
let integrator = Arc::new(GraphVectorIntegrator::new(
Expand Down
14 changes: 7 additions & 7 deletions crates/codegraph-core/src/integration/graph_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ impl SnippetExtractor {

/// Maintains a vector index synced with the code graph and provides semantic search returning graph nodes.
pub struct GraphVectorIntegrator {
graph: Arc<dyn GraphStore>,
vector: Arc<Mutex<Box<dyn VectorStore + Send>>>,
embedder: Arc<dyn EmbeddingService>,
graph: Arc<dyn GraphStore + Send + Sync>,
vector: Arc<Mutex<Box<dyn VectorStore + Send + Sync>>>,
embedder: Arc<dyn EmbeddingService + Send + Sync>,
extractor: SnippetExtractor,
// Track node signatures for incremental updates
signatures: DashMap<NodeId, u64>,
}

impl GraphVectorIntegrator {
pub fn new(
graph: Arc<dyn GraphStore>,
vector: Box<dyn VectorStore + Send>,
embedder: Arc<dyn EmbeddingService>,
graph: Arc<dyn GraphStore + Send + Sync>,
vector: Box<dyn VectorStore + Send + Sync>,
embedder: Arc<dyn EmbeddingService + Send + Sync>,
) -> Self {
Self {
graph,
Expand Down Expand Up @@ -485,7 +485,7 @@ mod tests {
.embs
.iter()
.map(|kv| {
let s = cosine(&kv.value(), query_embedding);
let s = cosine(kv.value(), query_embedding);
(*kv.key(), s)
})
.collect();
Expand Down
9 changes: 2 additions & 7 deletions crates/codegraph-core/src/performance_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
#[serde(rename_all = "snake_case")]
pub enum PerformanceMode {
HighAccuracy,
#[default]
Balanced,
HighSpeed,
UltraFast,
Custom,
}

impl Default for PerformanceMode {
fn default() -> Self {
Self::Balanced
}
}

impl PerformanceMode {
pub fn description(&self) -> &str {
match self {
Expand Down
17 changes: 7 additions & 10 deletions crates/codegraph-core/src/rerank_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ use anyhow::Result;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Default)]
#[serde(rename_all = "snake_case")]
pub enum RerankProvider {
/// Jina AI reranking API (jina-reranker-v3)
Jina,
/// Ollama chat-based reranking (e.g., Qwen3-Reranker)
Ollama,
/// No reranking (use HNSW scores directly)
#[default]
None,
}

impl Default for RerankProvider {
fn default() -> Self {
Self::None
}
}

impl std::fmt::Display for RerankProvider {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down Expand Up @@ -262,9 +257,11 @@ mod tests {

#[test]
fn test_config_validation() {
let mut config = RerankConfig::default();
config.provider = RerankProvider::Jina;
config.jina = None;
let mut config = RerankConfig {
provider: RerankProvider::Jina,
jina: None,
..RerankConfig::default()
};
assert!(config.validate().is_err());

config.provider = RerankProvider::Ollama;
Expand Down
15 changes: 6 additions & 9 deletions crates/codegraph-core/src/watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,9 +1514,8 @@ mod tests {
let mut evs: Vec<ChangeEvent> = Vec::new();
let deadline = Instant::now() + Duration::from_millis(300);
while Instant::now() < deadline {
match rx.recv_timeout(Duration::from_millis(40)) {
Ok(ev) => evs.push(ev),
Err(_) => {}
if let Ok(ev) = rx.recv_timeout(Duration::from_millis(40)) {
evs.push(ev)
}
}
let b_triggered = evs
Expand Down Expand Up @@ -1654,9 +1653,8 @@ mod tests {
let mut evs: Vec<ChangeEvent> = Vec::new();
let deadline = Instant::now() + Duration::from_millis(350);
while Instant::now() < deadline {
match rx.recv_timeout(Duration::from_millis(40)) {
Ok(ev) => evs.push(ev),
Err(_) => {}
if let Ok(ev) = rx.recv_timeout(Duration::from_millis(40)) {
evs.push(ev)
}
}
let b_tr = evs
Expand Down Expand Up @@ -1699,9 +1697,8 @@ mod tests {
let mut evs: Vec<ChangeEvent> = Vec::new();
let deadline = Instant::now() + Duration::from_millis(300);
while Instant::now() < deadline {
match rx.recv_timeout(Duration::from_millis(40)) {
Ok(ev) => evs.push(ev),
Err(_) => {}
if let Ok(ev) = rx.recv_timeout(Duration::from_millis(40)) {
evs.push(ev)
}
}
let lib_tr = evs
Expand Down
7 changes: 4 additions & 3 deletions crates/codegraph-core/tests/config_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ fn test_auto_tuning() {

#[test]
fn test_validation_rules() {
let mut config = EmbeddingModelConfig::default();

let mut config = EmbeddingModelConfig {
dimension: 0,
..EmbeddingModelConfig::default()
};
// Test invalid dimension
config.dimension = 0;
assert!(config.validate().is_err());

config.dimension = 10000;
Expand Down
Loading