Skip to content

Commit d5b8f13

Browse files
committed
fix(embedding): add LM Studio support to with_auto_from_env() and expose feature flag
This fixes the false alarm error where embeddings were working correctly but the system still logged "Falling back to random hash-based embeddings". Root cause: with_auto_from_env() only initialized Jina and Ollama providers, missing LM Studio entirely. This caused the error to appear when EmbeddingGenerator::with_auto_from_env() was called (e.g., in indexer.rs:1678 for symbol resolution), even though the main indexing used with_config() which properly initialized LM Studio. Changes: 1. Added LM Studio initialization to with_auto_from_env() (embedding.rs:275-301) - Checks CODEGRAPH_EMBEDDING_PROVIDER=lmstudio environment variable - Performs availability check before enabling - Matches with_config() implementation 2. Added lmstudio to feature flag checks (embedding.rs:120, 129) - Ensures mut base is available when lmstudio feature is enabled 3. Exposed embeddings-lmstudio feature in MCP crate (Cargo.toml:91) - Feature flag: embeddings-lmstudio = ["embeddings", "codegraph-vector/lmstudio"] 4. Updated Makefile build targets (Makefile:16, 21) - Added embeddings-lmstudio to build-mcp-autoagents - Added embeddings-lmstudio to build-mcp-http The false alarm no longer appears and LM Studio embeddings work in all code paths.
1 parent 9db3f6c commit d5b8f13

6 files changed

Lines changed: 36 additions & 7 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ build-release:
1313

1414
# Build MCP server with AutoAgents experimental feature
1515
build-mcp-autoagents:
16-
LIBRARY_PATH=/opt/homebrew/lib:$$LIBRARY_PATH cargo build --release -p codegraph-mcp --bin codegraph --features "ai-enhanced,autoagents-experimental,embeddings-ollama,codegraph-ai/anthropic,codegraph-ai/openai-llm,codegraph-ai/openai-compatible"
16+
LIBRARY_PATH=/opt/homebrew/lib:$$LIBRARY_PATH cargo build --release -p codegraph-mcp --bin codegraph --features "ai-enhanced,autoagents-experimental,embeddings-ollama,embeddings-lmstudio,codegraph-ai/anthropic,codegraph-ai/openai-llm,codegraph-ai/openai-compatible"
1717

1818
# Build MCP HTTP server with experimental HTTP transport
1919
.PHONY: build-mcp-http
2020
build-mcp-http:
21-
cargo build --release -p codegraph-mcp --bin codegraph --features "ai-enhanced,autoagents-experimental,embeddings-ollama,server-http"
21+
cargo build --release -p codegraph-mcp --bin codegraph --features "ai-enhanced,autoagents-experimental,embeddings-ollama,embeddings-lmstudio,server-http"
2222

2323
# Run HTTP server (depends on build)
2424
.PHONY: run-http-server

crates/codegraph-mcp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ embeddings-local = ["embeddings", "codegraph-vector/local-embeddings"]
8888
embeddings-openai = ["embeddings", "codegraph-vector/openai"]
8989
embeddings-ollama = ["embeddings", "codegraph-vector/ollama"]
9090
embeddings-jina = ["embeddings", "codegraph-vector/jina"]
91+
embeddings-lmstudio = ["embeddings", "codegraph-vector/lmstudio"]
9192
cloud = ["embeddings-jina", "codegraph-graph/surrealdb"]
9293
server-http = ["dep:axum", "dep:hyper", "dep:tower", "dep:http-body-util"]
9394
qwen-integration = []

crates/codegraph-vector/src/embedding.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,17 @@ impl EmbeddingGenerator {
116116
feature = "openai",
117117
feature = "onnx",
118118
feature = "ollama",
119-
feature = "jina"
119+
feature = "jina",
120+
feature = "lmstudio"
120121
))]
121122
let mut base = Self::new(ModelConfig::default());
122123
#[cfg(not(any(
123124
feature = "local-embeddings",
124125
feature = "openai",
125126
feature = "onnx",
126127
feature = "ollama",
127-
feature = "jina"
128+
feature = "jina",
129+
feature = "lmstudio"
128130
)))]
129131
let base = Self::new(ModelConfig::default());
130132
let provider = std::env::var("CODEGRAPH_EMBEDDING_PROVIDER")
@@ -270,6 +272,32 @@ impl EmbeddingGenerator {
270272
}
271273
}
272274
}
275+
} else if provider == "lmstudio" {
276+
#[cfg(feature = "lmstudio")]
277+
{
278+
let lmstudio_config = crate::lmstudio_embedding_provider::LmStudioEmbeddingConfig::default();
279+
match crate::lmstudio_embedding_provider::LmStudioEmbeddingProvider::new(lmstudio_config) {
280+
Ok(provider) => {
281+
tracing::info!("🔍 Checking LM Studio availability...");
282+
if provider.check_availability().await {
283+
use crate::providers::EmbeddingProvider;
284+
tracing::info!("✅ LM Studio embeddings initialized (from env)");
285+
base.model_config.dimension = provider.embedding_dimension();
286+
base.lmstudio_provider = Some(provider);
287+
} else {
288+
tracing::error!("❌ LM Studio not available at default URL");
289+
tracing::error!(" Make sure LM Studio is running with an embedding model loaded");
290+
}
291+
}
292+
Err(e) => {
293+
tracing::error!("❌ Failed to initialize LM Studio embeddings: {}", e);
294+
}
295+
}
296+
}
297+
#[cfg(not(feature = "lmstudio"))]
298+
{
299+
tracing::error!("❌ 'lmstudio' feature is NOT ENABLED - cannot use LM Studio provider!");
300+
}
273301
}
274302
base
275303
}

install-codegraph-cloud.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
set -euo pipefail
66

7-
FEATURES="daemon,ai-enhanced,codegraph-vector/jina,embeddings-ollama,codegraph-graph/surrealdb,codegraph-ai/all-cloud-providers,server-http,autoagents-experimental"
7+
FEATURES="daemon,ai-enhanced,codegraph-vector/jina,embeddings-ollama,embeddings-lmstudio,codegraph-graph/surrealdb,codegraph-ai/all-cloud-providers,server-http,autoagents-experimental"
88
SURR_URL="${CODEGRAPH_SURREALDB_URL:-ws://localhost:3004}"
99
SURR_NAMESPACE="${CODEGRAPH_SURREALDB_NAMESPACE:-ouroboros}"
1010
SURR_DATABASE="${CODEGRAPH_SURREALDB_DATABASE:-codegraph}"

install-codegraph-local-speed-osx.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
set -euo pipefail
66

7-
FEATURES="daemon,ai-enhanced,autoagents-experimental,qwen-integration,embeddings-ollama,server-http,codegraph-graph/surrealdb"
7+
FEATURES="daemon,ai-enhanced,autoagents-experimental,qwen-integration,embeddings-ollama,embeddings-lmstudio,server-http,codegraph-graph/surrealdb"
88
INSTALL_DIR="${CODEGRAPH_INSTALL_DIR:-$HOME/.local/bin}"
99
TARGET_BIN="target/release/codegraph"
1010

install-codegraph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
set -euo pipefail
66

7-
FEATURES="daemon,ai-enhanced,embeddings,embeddings-local,embeddings-openai,embeddings-ollama,embeddings-jina,cloud,server-http,qwen-integration,codegraph-graph/surrealdb"
7+
FEATURES="daemon,ai-enhanced,embeddings,embeddings-local,embeddings-openai,embeddings-lmstudio,embeddings-ollama,embeddings-jina,cloud,server-http,qwen-integration,codegraph-graph/surrealdb,autoagents-experimental"
88
SURR_URL="ws://localhost:3004"
99
SURR_NAMESPACE="ouroboros"
1010
SURR_DATABASE="codegraph"

0 commit comments

Comments
 (0)