Sentence Similarity
sentence-transformers
ONNX
English
code
bert
code-search
embeddings
LoRA
E5
cqs
Eval Results
text-embeddings-inference
Instructions to use jamie8johnson/e5-base-v2-code-search with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use jamie8johnson/e5-base-v2-code-search with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("jamie8johnson/e5-base-v2-code-search") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
docs: update model card for LoRA v7 (0.707 CSN, 49.19 CoIR)
Browse files
README.md
CHANGED
|
@@ -28,7 +28,7 @@ model-index:
|
|
| 28 |
name: CodeSearchNet
|
| 29 |
metrics:
|
| 30 |
- type: ndcg_at_10
|
| 31 |
-
value: 0.
|
| 32 |
name: NDCG@10 (avg, 6 languages)
|
| 33 |
- task:
|
| 34 |
type: Retrieval
|
|
@@ -37,13 +37,13 @@ model-index:
|
|
| 37 |
name: CosQA
|
| 38 |
metrics:
|
| 39 |
- type: ndcg_at_10
|
| 40 |
-
value: 0.
|
| 41 |
name: NDCG@10
|
| 42 |
---
|
| 43 |
|
| 44 |
# e5-base-v2-code-search
|
| 45 |
|
| 46 |
-
A fine-tuned code search embedding model based on [intfloat/e5-base-v2](https://huggingface.co/intfloat/e5-base-v2) (110M parameters). Optimized for natural language → code retrieval across
|
| 47 |
|
| 48 |
Built for [cqs](https://github.com/jamie8johnson/cqs), a semantic code search tool for AI agents.
|
| 49 |
|
|
@@ -51,8 +51,9 @@ Built for [cqs](https://github.com/jamie8johnson/cqs), a semantic code search to
|
|
| 51 |
|
| 52 |
| Benchmark | Metric | Score | vs Base E5 |
|
| 53 |
|-----------|--------|-------|------------|
|
| 54 |
-
| CodeSearchNet (6 lang avg) | NDCG@10 | **0.
|
| 55 |
-
|
|
|
|
|
| 56 |
| Hard eval (55 confusable pairs) | Recall@1 | **92.7%** | +1.8pp* |
|
| 57 |
|
| 58 |
*Hard eval improvement from full pipeline (LoRA + NL enrichment + doc comments), not LoRA alone.
|
|
@@ -61,38 +62,38 @@ Built for [cqs](https://github.com/jamie8johnson/cqs), a semantic code search to
|
|
| 61 |
|
| 62 |
| Language | Base E5 | This Model | Delta |
|
| 63 |
|----------|---------|------------|-------|
|
| 64 |
-
| Go | 0.624 | **0.
|
| 65 |
-
| Java | 0.571 | **0.
|
| 66 |
-
| JavaScript | 0.487 | **0.
|
| 67 |
-
| Ruby | 0.526 | **0.
|
| 68 |
-
| Python | 0.888 | **0.
|
| 69 |
-
| PHP | 0.601 | **0.
|
| 70 |
|
| 71 |
### CoIR Leaderboard Context
|
| 72 |
|
| 73 |
-
Among 110M-class models on the [CoIR benchmark](https://archersama.github.io/coir/) (ACL 2025), E5-base-v2 is already #7 out of 13 entries. This LoRA fine-tune extends the lead over other 110M models (BGE-Base 42.77, GTE-Base 36.75, UniXcoder 37.33) while remaining CPU-runnable in <100ms per query.
|
| 74 |
|
| 75 |
## Training
|
| 76 |
|
| 77 |
- **Method:** LoRA (rank 16) fine-tuning of E5-base-v2
|
| 78 |
-
- **Data:**
|
| 79 |
-
- **
|
|
|
|
| 80 |
- **Epochs:** 1
|
| 81 |
-
- **
|
| 82 |
|
| 83 |
-
### Why
|
| 84 |
|
| 85 |
-
We trained 10 LoRA variants with different data sizes
|
| 86 |
|
| 87 |
-
| Config |
|
| 88 |
-
|--------|------
|
| 89 |
-
| Base E5 | — | — | 0.627 |
|
| 90 |
-
|
|
| 91 |
-
| **
|
| 92 |
-
| v4 | 166k |
|
| 93 |
-
| rank-32 | 186k | 1 | 0.681 | 0.350 |
|
| 94 |
|
| 95 |
-
|
| 96 |
|
| 97 |
## Usage
|
| 98 |
|
|
@@ -149,9 +150,10 @@ The enrichment transforms code into richer text before the embedding model sees
|
|
| 149 |
|
| 150 |
## Limitations
|
| 151 |
|
| 152 |
-
- Trained
|
| 153 |
- English queries only. E5-base-v2's multilingual capability is untested for code search.
|
| 154 |
- 512 token max sequence length. Long functions are truncated.
|
|
|
|
| 155 |
|
| 156 |
## Citation
|
| 157 |
|
|
|
|
| 28 |
name: CodeSearchNet
|
| 29 |
metrics:
|
| 30 |
- type: ndcg_at_10
|
| 31 |
+
value: 0.707
|
| 32 |
name: NDCG@10 (avg, 6 languages)
|
| 33 |
- task:
|
| 34 |
type: Retrieval
|
|
|
|
| 37 |
name: CosQA
|
| 38 |
metrics:
|
| 39 |
- type: ndcg_at_10
|
| 40 |
+
value: 0.354
|
| 41 |
name: NDCG@10
|
| 42 |
---
|
| 43 |
|
| 44 |
# e5-base-v2-code-search
|
| 45 |
|
| 46 |
+
A fine-tuned code search embedding model based on [intfloat/e5-base-v2](https://huggingface.co/intfloat/e5-base-v2) (110M parameters). Optimized for natural language → code retrieval across 9 programming languages.
|
| 47 |
|
| 48 |
Built for [cqs](https://github.com/jamie8johnson/cqs), a semantic code search tool for AI agents.
|
| 49 |
|
|
|
|
| 51 |
|
| 52 |
| Benchmark | Metric | Score | vs Base E5 |
|
| 53 |
|-----------|--------|-------|------------|
|
| 54 |
+
| CodeSearchNet (6 lang avg) | NDCG@10 | **0.707** | **+8.0pp** |
|
| 55 |
+
| CoIR (9 tasks overall) | Avg NDCG@10 | **49.19** | -0.3pp |
|
| 56 |
+
| CosQA (out-of-distribution) | NDCG@10 | **0.354** | **+2.5pp** |
|
| 57 |
| Hard eval (55 confusable pairs) | Recall@1 | **92.7%** | +1.8pp* |
|
| 58 |
|
| 59 |
*Hard eval improvement from full pipeline (LoRA + NL enrichment + doc comments), not LoRA alone.
|
|
|
|
| 62 |
|
| 63 |
| Language | Base E5 | This Model | Delta |
|
| 64 |
|----------|---------|------------|-------|
|
| 65 |
+
| Go | 0.624 | **0.785** | +0.161 |
|
| 66 |
+
| Java | 0.571 | **0.656** | +0.085 |
|
| 67 |
+
| JavaScript | 0.487 | **0.545** | +0.058 |
|
| 68 |
+
| Ruby | 0.526 | **0.613** | +0.087 |
|
| 69 |
+
| Python | 0.888 | **0.975** | +0.087 |
|
| 70 |
+
| PHP | 0.601 | **0.667** | +0.066 |
|
| 71 |
|
| 72 |
### CoIR Leaderboard Context
|
| 73 |
|
| 74 |
+
Among 110M-class models on the [CoIR benchmark](https://archersama.github.io/coir/) (ACL 2025), E5-base-v2 is already #7 out of 13 entries. This LoRA fine-tune nearly matches the base model's generalist performance (49.19 vs 49.48) while dramatically improving code search (+8.0pp CSN). It extends the lead over other 110M models (BGE-Base 42.77, GTE-Base 36.75, UniXcoder 37.33) while remaining CPU-runnable in <100ms per query.
|
| 75 |
|
| 76 |
## Training
|
| 77 |
|
| 78 |
- **Method:** LoRA (rank 16) fine-tuning of E5-base-v2
|
| 79 |
+
- **Data:** 200,000 pairs from 9 languages (CSN: Go/Java/JS/Ruby/Python/PHP + Stack: Rust/TS/C++), with CoRNStack hard negatives
|
| 80 |
+
- **Loss:** CachedGISTEmbedLoss (guide model: base E5, margin 0.05) + MatryoshkaLoss (768/384/192/128)
|
| 81 |
+
- **Training time:** ~7 hours on A6000
|
| 82 |
- **Epochs:** 1
|
| 83 |
+
- **Hardware:** NVIDIA A6000 48GB
|
| 84 |
|
| 85 |
+
### Why v7?
|
| 86 |
|
| 87 |
+
We trained 10+ LoRA variants with different data sizes, ranks, epochs, losses, and data mixes. v7 uses GISTEmbedLoss with hard negatives to prevent the generalist degradation seen in earlier versions:
|
| 88 |
|
| 89 |
+
| Config | Data | Loss | CSN NDCG@10 | CoIR Overall |
|
| 90 |
+
|--------|------|------|-------------|--------------|
|
| 91 |
+
| Base E5 | — | — | 0.627 | 49.48 |
|
| 92 |
+
| v5 (previous) | 166k CSN, MNR | MNR | 0.683 | 48.67 |
|
| 93 |
+
| **v7 (current)** | **200k 9-lang, hard negs** | **GIST+Matryoshka** | **0.707** | **49.19** |
|
| 94 |
+
| v4 | 166k CSN | MNR, 3ep | 0.695 | — (over-specialized) |
|
|
|
|
| 95 |
|
| 96 |
+
v5 improved CSN but degraded generalist tasks (-0.81pp overall). v7 uses GISTEmbedLoss (false negative filtering via frozen guide model) and hard negatives (CoRNStack recipe) to recover most of the generalist loss while pushing CSN even higher.
|
| 97 |
|
| 98 |
## Usage
|
| 99 |
|
|
|
|
| 150 |
|
| 151 |
## Limitations
|
| 152 |
|
| 153 |
+
- Trained on 9 languages (Go, Java, JavaScript, Ruby, Python, PHP, Rust, TypeScript, C++). Other languages rely on E5's base capability.
|
| 154 |
- English queries only. E5-base-v2's multilingual capability is untested for code search.
|
| 155 |
- 512 token max sequence length. Long functions are truncated.
|
| 156 |
+
- Adversarial confusable-function pairs (e.g., 6 sorting variants) regress vs base model. Real-world NL→code retrieval improves.
|
| 157 |
|
| 158 |
## Citation
|
| 159 |
|