Skip to content

feat(code-intel): make the potion-code-16M-v2 code model the default embedding - #749

Merged
ajianaz merged 1 commit into
developfrom
feat/potion-code-embedding
Nov 16, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/potion-code-embedding

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • A new default embedding backend, potion-code-16M-v2 (16M-parameter static code model, MIT, 256 dimensions), selected by brain.embedding: auto and explicitly by potion. auto falls back to pretrained (if compiled) and hashing when the model cannot be downloaded.
  • The model downloads once, all files in one step, on the first cora index, cora brain or cora explore: pinned revision, size and SHA-256 verified per file, installed with a single rename, concurrent runs wait for one download, and a failed download is not retried for an hour (the fallback is used with a warning). CORA_EMBED_MODEL_DIR uses a model already on disk (any Model2Vec model), CORA_EMBED_MODEL_URL points to a mirror, CORA_EMBED_OFFLINE=1 never touches the network.
  • Models never mix. Each model has its own vector index file (cora_index.potion-code-v2.usearch; hashing and pretrained keep the historical name) and the model is part of every symbol's embedding fingerprint, so a model change re-embeds the project on the next cora index even when no file changed (no --rebuild needed).
  • Fusion weights follow the measurements: the code model gets a full vote in cora brain; hashing and pretrained count for a quarter (they were neutral to harmful at half). The warning text for a weak embedding is corrected.
  • Used across code intelligence: cora brain and the MCP cora.brain_search (hybrid), cora explore with a multi-word query now completes keyword results with a separate block of matches by meaning (--no-semantic turns it off, --json marks each result via: keyword | semantic), cora review context lookups. The MCP tool descriptions say which search to use for a question and which for a known name.
  • Docs: configuration, code intelligence (model, download, where vectors are stored, where they are used), CLI reference, README, changelog.

Why

cora brain embedded symbols with a hashing trick. On 1,639 retrieval queries (hand-written questions and doc comments of this repository, of 8 other Rust crates and of the Python standard library, with the documents cora indexes) it was neutral on this repository and harmful elsewhere when fused with keyword search (down to -0.09 MRR@10). The code model beats keyword search alone by +0.07 to +0.12 on every set (95% intervals exclude zero) and by +0.04 to +0.09 when fused at full weight; int8 quantization changed MRR by at most 0.003. Refs #746 (the evaluation harness is on the branch chore/spike-potion-code-embedding and is not part of this PR).

Testing

  • Unit tests: the model store (a verified download from a local server, a wrong checksum or size installs nothing, a missing file fails, an installed model is not fetched again, the failure backoff), the model wrapper on a toy model (dimensions, unit norm, topics, batch, finite output), and the brain diagnostics and weights.
  • Integration tests (tests/potion_backend.rs, a toy Model2Vec model in tests/fixtures/tiny-model, no network): the code model gets its own index file and answers a question with no word in common with the function name; switching the model re-embeds without a file change; a missing model degrades to hashing with a warning; cora explore completes a question by meaning and --no-semantic turns it off. Existing process tests run with CORA_EMBED_OFFLINE=1.
  • Manual end-to-end with the real model: first run downloads and indexes in 2.9 s; a mirror via CORA_EMBED_MODEL_URL; offline run is silent and uses hashing; an unreachable mirror warns once and then backs off; two simultaneous first runs download once; a tampered file from a mirror is rejected and nothing is installed.
  • On this repository cora brain MRR@10 rose from 0.217 to 0.316 (39 hand-written questions) and from 0.388 to 0.517 (400 doc-comment queries). Indexing 4,492 symbols of a large crate: 4.9 s with the code model against 4.2 s with hashing, peak memory 154 MB against 77 MB.
  • cargo fmt --all -- --check, cargo clippy --all-targets --features tree-sitter -- -D warnings, cargo test --features tree-sitter, cora review --base origin/develop: no issues.

…embedding (#746)

cora brain, and every search built on it, embedded symbols with a hashing
trick that, measured on 1,639 retrieval queries, was neutral on this repository
and harmful on other code when fused with keyword search. The default is now
potion-code-16M-v2, a 16M-parameter static code model: alone it beats keyword
search by +0.07 to +0.12 MRR@10 on every set, and on cora brain itself MRR@10
rose from 0.22 to 0.32 (hand-written questions) and 0.39 to 0.52 (doc comments).

The model is downloaded once, all files in one step, on the first command that
needs embeddings: pinned revision, SHA-256 and size verified, installed with a
single rename, concurrent runs wait for one download, and a failed download is
not retried for an hour (the fallback embedding is used with a warning).
CORA_EMBED_MODEL_DIR (a model on disk, any Model2Vec model), CORA_EMBED_MODEL_URL
(a mirror) and CORA_EMBED_OFFLINE=1 control the source.

Each model gets its own vector index file and is part of every symbol's
fingerprint, so changing the model re-embeds the project on the next index run
even when no file changed. Only the code model gets a full vote in the fusion;
hashing and pretrained count for a quarter. brain.embedding accepts potion.

cora explore completes a multi-word query with matches by meaning
(--no-semantic turns it off, --json marks each result via keyword or semantic),
and the MCP tool descriptions say which search to use for a question. The docs
describe the model, the download, the storage and where it is used.
@ajianaz
ajianaz merged commit fd23cf5 into develop Nov 16, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant