Optimal context selection for AI coding assistants using QUBO/Ising formulation
Project description
Anneal
Optimal context selection for AI coding assistants. Cooling random context down to exactly what your AI needs.
Anneal reads your codebase's structural graph, formulates "which chunks are optimal?" as a QUBO problem, solves with simulated annealing, and returns the minimum context set for your task.
Quick Start
pip install anneal-context
cd your-project
anneal init # builds graph from source, writes config
That's it. anneal init parses your codebase using tree-sitter, extracts functions, classes, and import relationships, and writes the graph to .anneal/graph.db. Then point your MCP client at anneal-server and you're ready to go.
How It Works
- Build graph —
anneal initwalks your source tree and extracts structural relationships via tree-sitter, supporting 20+ languages (Python, JavaScript, TypeScript, Go, Rust, Java, Ruby, C/C++, and more) - Generate candidates — keyword matching + graph topology identify relevant chunks
- Formulate QUBO — minimize token cost, maximize relevance, reward dependency coverage
- Solve via simulated annealing — SpinChain engine finds optimal selection
- Return results — stability-ranked, dependency-ordered chunks within your token budget
Requirements
- Python 3.11+
Installation
pip install anneal-context
Or with uv:
uv tool install anneal-context
Setup
Primary: anneal init
cd your-project
anneal init # builds graph from source, writes config
anneal init uses tree-sitter to parse your codebase directly — no external tools required. It supports 20+ languages including Python, JavaScript, TypeScript, Go, Rust, Java, Ruby, C/C++, C#, Kotlin, Swift, Scala, PHP, and more.
The command:
- Walks your source files
- Extracts functions, classes, and import relationships
- Builds
.anneal/graph.db - Writes a default
.anneal/config.toml
Add .anneal/ to your .gitignore.
Optional: Advanced Graph Sources
If you have code-review-graph or Graphify installed, Anneal merges their graph data alongside the built-in tree-sitter graph. This can provide additional structural signals (e.g., review history from code-review-graph, or Claude-generated summaries from Graphify).
# code-review-graph
npx code-review-graph install
# Graphify (Claude Code)
/plugin marketplace add safishamsi/graphify && /graphify
Configuration
Default config is written by anneal init. You can customize .anneal/config.toml:
[budget]
default_tokens = 5000
strategy = "balanced" # "minimal" | "balanced" | "thorough"
[solver]
backend = "simulated-annealing"
num_reads = 100
num_sweeps = 1000
MCP Server Setup
Claude Code
Add to .claude/settings.json:
{
"mcpServers": {
"anneal": {
"command": "anneal-server"
}
}
}
Gemini CLI
Add to ~/.gemini/settings.json:
{
"mcpServers": {
"anneal": {
"command": "anneal-server"
}
}
}
OpenAI Codex CLI
Add to ~/.codex/config.toml:
[[mcp_servers]]
name = "anneal"
command = "anneal-server"
Cursor / VS Code + Copilot / Aider
Any MCP-compatible client: run anneal-server via stdio transport.
Tools
get_optimal_context
Parameters:
task_description: str -- what you want to do
token_budget: int | None -- max tokens (default: 5000)
include_files: list[str] -- always include these paths
exclude_files: list[str] -- never include these paths
strategy: str -- "balanced" | "minimal" | "thorough"
Returns:
selected_chunks: list[{path, content, relevance_score, tokens}]
total_tokens: int
budget_utilization: float
stability_score: float
dependency_graph: dict
get_status
Returns graph source availability, node counts, solver config.
Development
git clone https://github.com/ameyakhot/anneal
cd anneal
uv venv && source .venv/bin/activate
uv pip install -e /path/to/spinchain
uv pip install -e ".[dev]"
python -m pytest tests/ -v
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anneal_context-0.2.0.tar.gz.
File metadata
- Download URL: anneal_context-0.2.0.tar.gz
- Upload date:
- Size: 143.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85ce6a2afa6a63afee6ea3eb9e3822d75a3bed95f293522a29ffc52634284ccf
|
|
| MD5 |
b2c65f441a119808a91854ec668a5456
|
|
| BLAKE2b-256 |
ad3a1aedbc34db5623db5eb34a22279fbabec48eb7340146195e8c0d412c84d5
|
Provenance
The following attestation bundles were made for anneal_context-0.2.0.tar.gz:
Publisher:
publish.yml on ameyakhot/anneal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anneal_context-0.2.0.tar.gz -
Subject digest:
85ce6a2afa6a63afee6ea3eb9e3822d75a3bed95f293522a29ffc52634284ccf - Sigstore transparency entry: 1284459871
- Sigstore integration time:
-
Permalink:
ameyakhot/anneal@cb4ed0e2cd0df0997f1ec758fc7718c91a391fb7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ameyakhot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cb4ed0e2cd0df0997f1ec758fc7718c91a391fb7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file anneal_context-0.2.0-py3-none-any.whl.
File metadata
- Download URL: anneal_context-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d59f35dda3bdcb61e4b6e9ba16b74c6d28447d025ee38c24be1fa90f94b329a4
|
|
| MD5 |
aaa75b6e44fcfaa465c2035070bf81a5
|
|
| BLAKE2b-256 |
0c6c32162f0dfd023d6eff6540ff1d5bc3b2bb8d652a06630d023822d735acfb
|
Provenance
The following attestation bundles were made for anneal_context-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on ameyakhot/anneal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anneal_context-0.2.0-py3-none-any.whl -
Subject digest:
d59f35dda3bdcb61e4b6e9ba16b74c6d28447d025ee38c24be1fa90f94b329a4 - Sigstore transparency entry: 1284459959
- Sigstore integration time:
-
Permalink:
ameyakhot/anneal@cb4ed0e2cd0df0997f1ec758fc7718c91a391fb7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ameyakhot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cb4ed0e2cd0df0997f1ec758fc7718c91a391fb7 -
Trigger Event:
release
-
Statement type: