Repository navigation
feat(code-intel): make the potion-code-16M-v2 code model the default embedding - #749
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
potion-code-16M-v2(16M-parameter static code model, MIT, 256 dimensions), selected bybrain.embedding: autoand explicitly bypotion.autofalls back topretrained(if compiled) andhashingwhen the model cannot be downloaded.cora index,cora brainorcora 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_DIRuses a model already on disk (any Model2Vec model),CORA_EMBED_MODEL_URLpoints to a mirror,CORA_EMBED_OFFLINE=1never touches the network.cora_index.potion-code-v2.usearch;hashingandpretrainedkeep the historical name) and the model is part of every symbol's embedding fingerprint, so a model change re-embeds the project on the nextcora indexeven when no file changed (no--rebuildneeded).cora brain;hashingandpretrainedcount for a quarter (they were neutral to harmful at half). The warning text for a weak embedding is corrected.cora brainand the MCPcora.brain_search(hybrid),cora explorewith a multi-word query now completes keyword results with a separate block of matches by meaning (--no-semanticturns it off,--jsonmarks each resultvia: keyword | semantic),cora reviewcontext lookups. The MCP tool descriptions say which search to use for a question and which for a known name.Why
cora brainembedded 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 branchchore/spike-potion-code-embeddingand is not part of this PR).Testing
tests/potion_backend.rs, a toy Model2Vec model intests/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 explorecompletes a question by meaning and--no-semanticturns it off. Existing process tests run withCORA_EMBED_OFFLINE=1.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.cora brainMRR@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.