# Environment Variables for Fine-Tuning Performance and Timeouts in code-review-graph

> Optimize code-review-graph performance and prevent timeouts. Use environment variables to tune cloud embedding providers, MCP server behavior, and storage paths for faster incremental graph updates.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: performance
- Published: 2026-07-18

---

**Use environment variables to configure cloud embedding providers, MCP server behavior, and storage paths to keep incremental graph updates under 2 seconds and prevent token‑limit timeouts during blast‑radius analysis.**

`code-review-graph` persists its AST‑derived knowledge graph in a local SQLite database and exposes 30+ tools via the Model‑Context‑Protocol (MCP). While the core engine relies on Tree‑sitter parsing and incremental diffing for speed, environment variables control the optional cloud‑based embedding backends, server timeouts, and resource limits that directly impact performance on large repositories.

## Configuring Cloud Embedding Providers

When you install the optional `embeddings` extra, `code-review-graph` can enrich graph nodes with vector embeddings for semantic search. According to the repository’s README, cloud providers are **opt‑in via environment variables**, allowing you to balance local CPU usage against API latency.

- **Local inference** (default): Uses Sentence‑Transformers offline with zero external configuration.
- **Cloud endpoints**: Configure Gemini, MiniMax, or any OpenAI‑compatible API by setting the appropriate endpoint and API key variables. This offloads embedding generation to remote GPUs, significantly speeding up `semantic_search_nodes_tool` queries on large codebases.

In [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py), the schema supports both FTS5 keyword search and vector columns; the specific provider is selected at runtime based on these environment settings.

## Storage Path and SQLite Performance

By default, the graph is stored in a hidden **`.code-review-graph/`** directory at the project root. You can relocate this database to faster storage (e.g., a RAM‑mounted tmpfs or local SSD) using environment variables to reduce I/O latency during the incremental updates performed by `build_or_update_graph_tool`.

The SQLite backend—implemented in [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py)—handles node/edge insertion and querying. Tuning the SQLite `PRAGMA` settings via environment variables (as referenced in the README’s environment‑variable section) can optimize write throughput when the parser ([`code_review_graph/parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/parser.py)) ingests 30+ languages simultaneously.

## MCP Server Timeout and Concurrency

Running `code-review-graph serve` starts an MCP server that AI assistants query via `detect_changes_tool` and `get_review_context_tool`. For repositories with deep call graphs, the blast‑radius analysis can traverse thousands of nodes. Environment variables configure:

- **Request timeouts**: Prevent long‑running queries from hanging the MCP client when calculating risk scores across the dependency graph.
- **Concurrency limits**: Cap the number of simultaneous Tree‑sitter parsers or SQL connections opened by [`mcp_tools.py`](https://github.com/tirth8205/code-review-graph/blob/main/mcp_tools.py) to avoid memory exhaustion on monorepos.

These settings ensure that the median **82× token reduction** (up to 528× on large repos) is delivered without triggering MCP client timeouts.

## Daemon and Watch Mode Optimization

The optional `crg-daemon` and the `code-review-graph watch` command keep the graph fresh by monitoring file‑system events. Environment variables control:

- **Polling intervals**: Fallback polling frequency when native watchers are unavailable.
- **Debounce delays**: Coalescing rapid file saves to avoid redundant re‑parsing in [`parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/parser.py).
- **Exclusion patterns**: Glob lists that preemptively skip `node_modules` or build artifacts, reducing the watch‑mode CPU footprint.

Correct tuning keeps the incremental update latency under the benchmarked **< 2 seconds** for typical projects.

## Resource Limits for Parallel Parsing

[`code_review_graph/parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/parser.py) maps file extensions to Tree‑sitter grammars and dispatches parsing jobs. On machines with limited RAM, environment variables can restrict:

- **Worker processes**: Limit parallel parsing threads when indexing millions of lines across polyglot monorepos.
- **Per‑file timeout**: Abort parsing on individual files that exceed a threshold (e.g., minified JavaScript), ensuring `build_or_update_graph_tool` completes without stalling the entire graph construction.

## Summary

- **Cloud embeddings** (Gemini, MiniMax, OpenAI‑compatible) are activated via environment variables to accelerate `semantic_search_nodes_tool` without local GPU requirements.
- **Storage paths** can be redirected to faster disks to improve SQLite write performance during incremental updates handled by [`graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/graph.py).
- **MCP server timeouts and concurrency** limits prevent blast‑radius queries from hanging AI assistants when traversing complex call graphs defined in [`mcp_tools.py`](https://github.com/tirth8205/code-review-graph/blob/main/mcp_tools.py).
- **Watch‑mode tuning** via environment variables maintains the < 2 second update benchmark by controlling debounce behavior and exclusion globs.

## Frequently Asked Questions

### How do I switch from local to cloud embeddings without rebuilding the graph?

Set the environment variable for your chosen provider (e.g., OpenAI‑compatible endpoint or Gemini) and restart the MCP server. The `semantic_search_nodes_tool` will begin querying the remote API for new embeddings while existing graph structure data in `.code-review-graph/` remains intact.

### What environment variable controls the SQLite database location?

While the default path is `.code-review-graph/` in the repository root, you can override the storage directory via environment configuration (see the README environment‑variable reference). Pointing this to a RAM disk or fast NVMe drive reduces I/O bottlenecks during `build_or_update_graph_tool` runs.

### Can I increase the timeout for `detect_changes_tool` on very large repositories?

Yes. The MCP server (`code-review-graph serve`) respects timeout environment variables that extend the default limit for complex blast‑radius calculations. Increasing this prevents the tool from terminating early when analyzing deep dependency chains in [`code_review_graph/mcp_tools.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/mcp_tools.py).

### Why does watch mode use environment variables instead of CLI flags?

Environment variables allow the `crg-daemon` background process to inherit configuration consistently across shell sessions and IDE integrations. Settings like polling interval and debounce delay are read once at daemon startup, ensuring stable resource usage while [`parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/parser.py) handles incremental file changes.