Skip to content

Commit 5a21b75

Browse files
committed
feat: Simplify configuration from 8+ env vars to zero-config auto-detection
## Problem Users had to export 8+ environment variables every time: - CODEGRAPH_LOCAL_MODEL (long HuggingFace cache paths) - CODEGRAPH_EMBEDDING_PROVIDER - CODEGRAPH_OLLAMA_URL - CODEGRAPH_MODEL - CODEGRAPH_CONTEXT_WINDOW - CODEGRAPH_TEMPERATURE - RUST_LOG - PATH updates This was error-prone, tedious, and a terrible user experience. ## Solution Implemented comprehensive configuration system with: ### 1. Auto-Detection - Automatically finds ONNX models in HuggingFace cache - Detects if Ollama is running on localhost:11434 - Uses sensible defaults for all settings - Zero configuration required for most users ### 2. ConfigManager (`config_manager.rs`) - Smart configuration loader with precedence: 1. Environment variables (.env file or exports) 2. Config file (.codegraph.toml or ~/.codegraph/config.toml) 3. Auto-detection 4. Sensible defaults - Auto-detects ONNX models: `find_onnx_model_in_cache()` - Checks Ollama availability: `check_ollama_available()` - Loads .env from current dir or ~/.codegraph.env - Comprehensive validation ### 3. Configuration Files - `.env.example`: One-line setup (CODEGRAPH_EMBEDDING_PROVIDER=auto) - `.codegraph.toml.example`: Full configuration example with docs - Both files support all options with helpful comments ### 4. Documentation - `SIMPLIFIED_CONFIG.md`: Complete migration guide - Before/after comparison (8 exports → 0-1) - Quick start guides for different workflows - Troubleshooting section ## Key Features - **Zero-config mode**: Just `cargo run -- index .` - **Auto-detection**: Finds ONNX models in HF cache automatically - **Flexible**: Supports .env, TOML config, or env vars - **Backward compatible**: All existing env vars still work - **Context-only mode**: Perfect for Claude/GPT-4 agents (fastest) - **Local LLM mode**: One-line enable with CODEGRAPH_MODEL ## Usage Examples ### Before (8 exports): ```bash export CODEGRAPH_LOCAL_MODEL=/Users/you/.cache/huggingface/hub/models--Qdrant--all-MiniLM-L6-v2-onnx/snapshots/abc123 export CODEGRAPH_EMBEDDING_PROVIDER=onnx export CODEGRAPH_OLLAMA_URL=http://localhost:11434 export CODEGRAPH_MODEL="hf.co/unsloth/Qwen2.5-Coder-14B-Instruct-128K-GGUF:Q4_K_M" export CODEGRAPH_CONTEXT_WINDOW=128000 export CODEGRAPH_TEMPERATURE=0.1 export RUST_LOG=info export PATH="$HOME/.local/bin:$PATH" cargo run -- index . ``` ### After (0 exports): ```bash cargo run -- index . ``` ### After (.env file): ```bash echo "CODEGRAPH_EMBEDDING_PROVIDER=auto" > .env cargo run -- index . ``` ## Files Changed - `crates/codegraph-core/src/config_manager.rs`: New ConfigManager with auto-detection - `crates/codegraph-core/src/lib.rs`: Export config_manager module - `crates/codegraph-core/Cargo.toml`: Add dotenv and dirs dependencies - `.env.example`: Extended with simplified CodeGraph configuration - `.codegraph.toml.example`: Complete example configuration file - `SIMPLIFIED_CONFIG.md`: Comprehensive migration and usage guide ## Impact - Reduces configuration complexity by 90% - Eliminates need to know HuggingFace cache paths - Works out-of-the-box for most users - Maintains full flexibility for power users - Dramatically improves onboarding experience 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7782583 commit 5a21b75

File tree

6 files changed

+1137
-3
lines changed

6 files changed

+1137
-3
lines changed

.codegraph.toml.example

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# CodeGraph Configuration File
2+
# Copy this to .codegraph.toml or ~/.codegraph/config.toml and customize
3+
4+
# ============================================================================
5+
# Embedding Configuration
6+
# ============================================================================
7+
[embedding]
8+
# Provider: "auto", "onnx", "ollama", or "openai"
9+
# "auto" will detect available models automatically
10+
provider = "auto"
11+
12+
# Model path or identifier
13+
# For ONNX: Absolute path to model directory (auto-detected from HuggingFace cache)
14+
# For Ollama: Model name (e.g., "all-minilm:latest")
15+
# For OpenAI: Model name (e.g., "text-embedding-3-small")
16+
# Leave empty for auto-detection
17+
model = ""
18+
19+
# Ollama URL (only used if provider is "ollama")
20+
ollama_url = "http://localhost:11434"
21+
22+
# OpenAI API key (only used if provider is "openai")
23+
# Can also be set via OPENAI_API_KEY environment variable
24+
# openai_api_key = "sk-..."
25+
26+
# Batch size for embedding generation (GPU optimization)
27+
batch_size = 64
28+
29+
# ============================================================================
30+
# LLM Configuration (for insights generation)
31+
# ============================================================================
32+
[llm]
33+
# Enable LLM insights (false = context-only mode for agents like Claude/GPT-4)
34+
# Set to false for maximum speed if using an external agent
35+
enabled = false
36+
37+
# LLM model identifier
38+
# For Ollama: Model name (e.g., "qwen2.5-coder:14b", "codellama:13b")
39+
# Leave empty if disabled
40+
model = ""
41+
42+
# Ollama URL
43+
ollama_url = "http://localhost:11434"
44+
45+
# Context window size (tokens)
46+
context_window = 8000
47+
48+
# Temperature for generation (0.0 = deterministic, 1.0 = creative)
49+
temperature = 0.1
50+
51+
# Insights mode: "context-only", "balanced", or "deep"
52+
# - context-only: Return context only (fastest, for agents)
53+
# - balanced: Process top 10 files with LLM (good speed/quality)
54+
# - deep: Process all reranked files (comprehensive)
55+
insights_mode = "context-only"
56+
57+
# ============================================================================
58+
# Performance Configuration
59+
# ============================================================================
60+
[performance]
61+
# Number of worker threads (defaults to CPU count)
62+
num_threads = 0 # 0 = auto-detect
63+
64+
# Cache size in MB
65+
cache_size_mb = 512
66+
67+
# Enable GPU acceleration (requires CUDA/Metal support)
68+
enable_gpu = false
69+
70+
# Maximum concurrent requests for embedding/LLM
71+
max_concurrent_requests = 4
72+
73+
# ============================================================================
74+
# Logging Configuration
75+
# ============================================================================
76+
[logging]
77+
# Log level: "trace", "debug", "info", "warn", "error"
78+
level = "info"
79+
80+
# Log format: "pretty", "json", "compact"
81+
format = "pretty"

.env.example

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
1-
# CodeGraph Security Configuration
1+
# CodeGraph Configuration Example
22
# Copy this file to .env and update the values for your environment
33

4+
# ============================================================================
5+
# CodeGraph Core Configuration (Simplified Setup)
6+
# ============================================================================
7+
8+
# Minimal Setup - Auto-detect embedding provider (ONNX, Ollama, or OpenAI)
9+
CODEGRAPH_EMBEDDING_PROVIDER=auto
10+
11+
# That's it for basic usage! CodeGraph will auto-detect everything else.
12+
# Uncomment and customize the settings below if you need more control.
13+
14+
# Embedding Provider Configuration
15+
# ----------------------------------
16+
# Provider options: "auto", "onnx", "ollama", or "openai"
17+
# CODEGRAPH_EMBEDDING_PROVIDER=auto
18+
19+
# ONNX: Specify model path (or leave empty for auto-detection from HuggingFace cache)
20+
# CODEGRAPH_LOCAL_MODEL=/path/to/your/onnx/model
21+
22+
# Ollama: Specify embedding model name
23+
# CODEGRAPH_EMBEDDING_MODEL=all-minilm:latest
24+
# CODEGRAPH_OLLAMA_URL=http://localhost:11434
25+
26+
# OpenAI: Model name (API key configured below in Security section)
27+
# CODEGRAPH_EMBEDDING_MODEL=text-embedding-3-small
28+
29+
# LLM Configuration (for local insights generation)
30+
# --------------------------------------------------
31+
# Leave empty to use context-only mode (fastest, recommended for agents like Claude/GPT-4)
32+
# Set to enable local LLM insights generation
33+
34+
# LLM model (e.g., "qwen2.5-coder:14b", "codellama:13b")
35+
# CODEGRAPH_MODEL=qwen2.5-coder:14b
36+
37+
# LLM context window size (tokens)
38+
# CODEGRAPH_CONTEXT_WINDOW=128000
39+
40+
# LLM temperature (0.0 = deterministic, 1.0 = creative)
41+
# CODEGRAPH_TEMPERATURE=0.1
42+
43+
# Logging
44+
# -------
45+
# Log level: trace, debug, info, warn, error
46+
RUST_LOG=info
47+
48+
# ============================================================================
49+
# Security Configuration (for production deployments)
50+
# ============================================================================
51+
452
# JWT Authentication
553
JWT_SECRET=replace_with_secure_random_secret_minimum_32_characters_long
654
JWT_EXPIRY_HOURS=24
@@ -33,8 +81,8 @@ MAX_REQUEST_SIZE=10485760 # 10MB
3381
SESSION_TIMEOUT_HOURS=24
3482
PASSWORD_MIN_LENGTH=12
3583

36-
# Logging
37-
LOG_LEVEL=info
84+
# Logging (see RUST_LOG above for CodeGraph core logging)
85+
# LOG_LEVEL=info # For application-level logging
3886
SECURITY_LOG_LEVEL=warn
3987
LOG_FORMAT=json
4088

0 commit comments

Comments
 (0)