divakantpandey commited on
Commit
9d73782
·
verified ·
1 Parent(s): da00134

Set max length to 1024 and correct model card

Browse files
Modelfile CHANGED
@@ -1,6 +1,6 @@
1
  # Ollama Modelfile for Code-Embed v2
2
  FROM ./outputs/gguf/code-embed-v2-q8_0.gguf
3
 
4
- PARAMETER num_ctx 8192
5
 
6
 
 
1
  # Ollama Modelfile for Code-Embed v2
2
  FROM ./outputs/gguf/code-embed-v2-q8_0.gguf
3
 
4
+ PARAMETER num_ctx 1024
5
 
6
 
README.md CHANGED
@@ -11,7 +11,6 @@ tags:
11
  - php
12
  - code-search
13
  - code-embeddings
14
- - multilingual
15
  - sentence-transformers
16
  - matryoshka
17
  - unixcoder
@@ -22,364 +21,343 @@ tags:
22
  license: cc-by-nc-4.0
23
  pipeline_tag: feature-extraction
24
  library_name: sentence-transformers
25
- metrics:
26
- - mrr
27
- - ndcg
28
- - map
29
  model-index:
30
  - name: code-embed-v2
31
  results:
32
  - task:
33
- type: reranking
34
- name: CoREB(v1)
35
  dataset:
36
- name: CoREB(v1) Macro-Average (Rank #3 in <=150M Category)
37
- type: mteb/coreb
 
38
  metrics:
39
  - type: main_score
40
- value: 0.4362
41
- name: Main Score (Rank #3 in <=150M Category)
42
- - type: reranking_mean
43
- value: 0.4894
44
- name: Reranking Mean
45
- - type: retrieval_mean
46
- value: 0.3831
47
- name: Retrieval Mean
48
  - task:
49
- type: reranking
50
- name: Code-to-Code Reranking
51
  dataset:
52
- name: CorebC2CReranking
53
- type: coreb_c2c_reranking
54
  split: test
55
  metrics:
56
- - type: map
57
- value: 0.4205
58
- name: MAP (Rank #3 Worldwide)
59
  - task:
60
  type: retrieval
61
- name: CoIR
62
  dataset:
63
- name: CoIR Macro-Average (Rank #8 in <=150M Category)
64
- type: mteb/coir
 
65
  metrics:
66
- - type: ndcg_at_10
67
- value: 0.5343
68
- name: NDCG@10 (Rank #8 in <=150M Category)
69
  - task:
70
  type: retrieval
71
- name: MTEB(Code, v1)
72
  dataset:
73
- name: MTEB(Code, v1) Macro-Average (Rank #9 in <=150M Category)
74
- type: mteb/code
 
75
  metrics:
76
- - type: ndcg_at_10
77
- value: 0.5475
78
- name: NDCG@10 (Rank #9 in <=150M Category)
79
  - task:
80
- type: reranking
81
- name: Code-to-Text Reranking
82
  dataset:
83
- name: CorebC2TReranking
84
- type: coreb_c2t_reranking
85
  split: test
86
  metrics:
87
- - type: map
88
- value: 0.7937
89
- name: MAP
90
  - task:
91
- type: reranking
92
- name: Text-to-Code Reranking
93
  dataset:
94
- name: CorebT2CReranking
95
- type: coreb_t2c_reranking
96
- split: test
97
  metrics:
98
- - type: map
99
- value: 0.2539
100
- name: MAP
101
  - task:
102
  type: retrieval
103
- name: Multi-Turn Feedback
104
  dataset:
105
  name: CodeFeedbackMT
106
- type: code_feedback_mt
107
  split: test
108
  metrics:
109
- - type: ndcg_at_10
110
  value: 0.6164
111
- name: NDCG@10 (Rank #45 Worldwide)
112
  - task:
113
  type: retrieval
114
- name: Deep Learning Translation
115
  dataset:
116
- name: CodeTransOceanDL
117
- type: code_trans_ocean_dl
118
  split: test
119
  metrics:
120
- - type: ndcg_at_10
121
- value: 0.3533
122
- name: NDCG@10 (Rank #21 Worldwide)
123
  - task:
124
  type: retrieval
125
- name: Code Search
 
 
 
 
 
 
 
 
 
 
 
126
  dataset:
127
  name: CodeSearchNetRetrieval
128
- type: code_search_net
129
  split: test
130
  metrics:
131
- - type: ndcg_at_10
132
  value: 0.8574
133
- name: NDCG@10
134
  - task:
135
  type: retrieval
136
- name: COIR Code Search
137
  dataset:
138
- name: COIRCodeSearchNetRetrieval
139
- type: coir_code_search_net
140
  split: test
141
  metrics:
142
- - type: ndcg_at_10
143
- value: 0.7488
144
- name: NDCG@10
145
  - task:
146
  type: retrieval
147
- name: StackOverflow QA
148
  dataset:
149
- name: StackOverflowQA
150
- type: stackoverflow_qa
151
  split: test
152
  metrics:
153
- - type: ndcg_at_10
154
- value: 0.7131
155
- name: NDCG@10
156
  - task:
157
- type: retrieval
158
- name: Algorithmic Translation
159
  dataset:
160
- name: CodeTransOceanContest
161
- type: code_trans_ocean_contest
162
  split: test
163
  metrics:
164
- - type: ndcg_at_10
165
- value: 0.6814
166
- name: NDCG@10
167
  - task:
168
  type: retrieval
169
- name: Code Feedback (Single-Turn)
170
  dataset:
171
- name: CodeFeedbackST
172
- type: code_feedback_st
173
  split: test
174
  metrics:
175
- - type: ndcg_at_10
176
- value: 0.6680
177
- name: NDCG@10
178
  - task:
179
- type: retrieval
180
- name: Code Clone Search
181
  dataset:
182
- name: CodeSearchNetCCRetrieval
183
- type: code_search_net_cc
184
  split: test
185
  metrics:
186
- - type: ndcg_at_10
187
- value: 0.5661
188
- name: NDCG@10
189
  - task:
190
  type: retrieval
191
- name: Code-to-Text Search
192
  dataset:
193
  name: CorebC2TRetrieval
194
- type: coreb_c2t_retrieval
195
  split: test
196
  metrics:
197
- - type: ndcg_at_10
198
  value: 0.6073
199
- name: NDCG@10
 
 
 
 
 
 
 
 
 
 
 
200
  - task:
201
  type: retrieval
202
- name: Text to SQL
203
  dataset:
204
- name: SyntheticText2SQL
205
- type: synthetic_text2sql
206
  split: test
207
  metrics:
208
- - type: ndcg_at_10
209
- value: 0.4938
210
- name: NDCG@10
211
  - task:
212
  type: retrieval
213
- name: Code Question Answering
214
  dataset:
215
  name: CosQA
216
- type: cosqa
217
  split: test
218
  metrics:
219
- - type: ndcg_at_10
220
- value: 0.3000
221
- name: NDCG@10
222
  - task:
223
  type: retrieval
224
- name: Competitive Programming
225
  dataset:
226
- name: AppsRetrieval
227
- type: apps_retrieval
228
  split: test
229
  metrics:
230
- - type: ndcg_at_10
231
- value: 0.2017
232
- name: NDCG@10
 
 
 
 
 
 
 
 
 
 
 
233
  ---
234
 
235
- # 💻 CodeEmbed v2: Multilingual Code & Query Embedding Model (131M)
236
 
237
- > **CodeEmbed v2** (`divakantpandey/code-embed-v2`) is an ultra-compact, high-speed 131M parameter dense embedding model optimized for software engineering workflows: natural language code search, cross-language clone detection, multi-turn code assistant retrieval, and error trace debugging.
238
- >
239
- > On the official **Massive Text Embedding Benchmark (MTEB)**, CodeEmbed v2 dominates the 150M compact model category ($\le$ 150M parameters): **Rank #3 on CoREB(v1)**, **Rank #8 on CoIR**, and **Rank #9 on MTEB(Code, v1)**, alongside **Rank #3 Worldwide** across all model sizes on Code-to-Code Reranking (`CorebC2CReranking`). It consistently outperforms enterprise frontier models including Google Gemini Embedding and Microsoft E5-Large in conversational code feedback and deep learning framework translation at a fraction of the compute and memory footprint.
240
 
241
  [![Hugging Face Model](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-divakantpandey%2Fcode--embed--v2-blue)](https://huggingface.co/divakantpandey/code-embed-v2)
242
- [![MTEB Official Leaderboard](https://img.shields.io/badge/MTEB%20Leaderboard-divakantpandey%2Fcode--embed--v2-blue)](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2)
243
- [![Coreb C2C Reranking](https://img.shields.io/badge/Coreb%20C2C%20Reranking-%233%20Worldwide%20(0.4205)-gold)](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2)
244
- [![CoREB(v1) Rank #3 (≤150M)](https://img.shields.io/badge/CoREB(v1)%20(≤150M)-Rank%20%233-gold)](https://mteb-leaderboard.hf.space/benchmark/CoREB(v1)?minSize=33&maxSize=150)
245
- [![CoIR Rank #8 (≤150M)](https://img.shields.io/badge/CoIR%20(≤150M)-Rank%20%238-gold)](https://mteb-leaderboard.hf.space/benchmark/CoIR?minSize=2&maxSize=150)
246
- [![MTEB Code Rank #9 (≤150M)](https://img.shields.io/badge/MTEB(Code%2C%20v1)%20(≤150M)-Rank%20%239-gold)](https://mteb-leaderboard.hf.space/benchmark/MTEB(Code%2C%20v1)?minSize=2&maxSize=150)
247
- [![CoREB(v1) Overall](https://img.shields.io/badge/CoREB(v1)%20Overall-Rank%20%2319-orange)](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2)
248
- [![CoIR Overall](https://img.shields.io/badge/CoIR%20Overall-Rank%20%2360-orange)](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2)
249
- [![MTEB Code Overall](https://img.shields.io/badge/MTEB(Code%2C%20v1)%20Overall-Rank%20%2369-orange)](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2)
250
- [![MTEB Openness](https://img.shields.io/badge/MTEB%20Openness-4%20%2F%205-brightgreen)](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2)
251
- [![Context Length: 8192](https://img.shields.io/badge/Context%20Length-8192%20tokens-brightgreen.svg)]()
252
- [![MTEB Results](https://img.shields.io/badge/MTEB%20Results-Merged%20(PR%20%23803)-brightgreen)](https://github.com/embeddings-benchmark/results/pull/803)
253
- [![Sentence-Transformers](https://img.shields.io/badge/Sentence--Transformers-Compatible-orange.svg)](https://sbert.net)
254
  [![License: CC-BY-NC-4.0](https://img.shields.io/badge/License-CC--BY--NC--4.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc/4.0/)
255
 
256
- ---
257
-
258
- ## 🌟 Key Product Capabilities
259
-
260
- * **8,192-Token Long Context Window**: Ingests complete repository files, large multi-function modules, complex classes, and detailed error tracebacks without truncation (via Position Interpolation).
261
- * **Multilingual Programming Support**: First-class embedding support for **Python, JavaScript, TypeScript, Go, Java, Ruby, PHP, SQL**, and natural language technical English.
262
- * **Cross-Language Semantic Alignment**: Directly queries across language boundaries (e.g. searching with a Python snippet to find equivalent logic implemented in Go or Java).
263
- * **Adaptive Matryoshka Dimensions (MRL)**: Native 1,536-dimensional embeddings can be truncated dynamically to **768, 512, 256, or 128 dimensions** for up to **12× storage savings** and extreme query speedups in vector databases.
264
- * **Zero GPU Requirement for Inference**: Compact 131M parameter size executes at **<15 ms per query** on standard laptop CPUs and consumer edge devices.
265
- * **Ecosystem Compatibility**: Drop-in compatible with `sentence-transformers`, `LangChain`, `LlamaIndex`, `ChromaDB`, `Qdrant`, and `Weaviate`.
266
-
267
- ---
268
-
269
- ## 🏆 Official MTEB Leaderboard Achievements & Scorecard
270
-
271
- > [!IMPORTANT]
272
- > **Temporal Snapshot & Benchmark Version Notice**:
273
- > The rankings, scores, and competitive metrics documented below reflect the official **Massive Text Embedding Benchmark (MTEB)** snapshot as of **October 24, 2026** (MTEB Leaderboard Build `39959364296` / `mteb==2.26.16` / PR [#803](https://github.com/embeddings-benchmark/results/pull/803) merged into `embeddings-benchmark/results:main`).
274
- > Because the MTEB Leaderboard dynamically recalculates ranks daily as new community and proprietary models are submitted, global rankings are subject to shift over time. Live metrics and interactive task drill-downs can always be verified directly on the [Official MTEB Model Page](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2).
275
-
276
- ### 🥇 Top Rankings in the $\le$ 150M Parameter Category (Compact Models)
277
-
278
- When filtering by parameter scale for lightweight, production-ready edge models ($\le$ 150M category), CodeEmbed v2 establishes top-tier standing globally:
279
-
280
- | Rank in Category | Benchmark Suite | Parameter Category | Score | Official Leaderboard Filter Link |
281
- | :---: | :--- | :---: | :---: | :--- |
282
- | 🥉 **#3** | **`CoREB(v1)`** | $\le$ 150M Category | **`0.4362`** | 👉 [CoREB(v1) Leaderboard (Rank #3)](https://mteb-leaderboard.hf.space/benchmark/CoREB(v1)?minSize=33&maxSize=150) |
283
- | 🏅 **#8** | **`CoIR`** | $\le$ 150M Category | **`0.5343`** | 👉 [CoIR Leaderboard (Rank #8)](https://mteb-leaderboard.hf.space/benchmark/CoIR?minSize=2&maxSize=150) |
284
- | 🏅 **#9** | **`MTEB(Code, v1)`** | $\le$ 150M Category | **`0.5475`** | 👉 [MTEB Code Leaderboard (Rank #9)](https://mteb-leaderboard.hf.space/benchmark/MTEB(Code%2C%20v1)?minSize=2&maxSize=150) |
285
-
286
- ---
287
-
288
- ### 🌟 Key Benchmark Highlights *(Sorted by Rank Ascending)*
289
-
290
- 1. **🥉 Rank #3 Worldwide on Code-to-Code Reranking (`CorebC2CReranking`)** *(Across ALL model sizes)*
291
- - **Score: `0.4205`** (Rank #3 globally out of all models ever evaluated).
292
- - Competes head-to-head with Alibaba's 7-Billion parameter LLM (`codefuse-ai/C2LLM-7B` at `0.4238`, a margin of just 0.003).
293
- - Directly outperforms specialized code models including `naver/splade-code-06B` (600M, `0.4198`), `codefuse-ai/F2LLM-v2-160M` (`0.4155`), and `codefuse-ai/F2LLM-v2-330M` (`0.4143`).
294
- - Demonstrates world-class semantic code clone detection and refactoring matching.
295
-
296
- 2. **🥉 Rank #3 Worldwide on `CoREB(v1)`** *(In the $\le$ 150M category)*
297
- - **Score: `0.4362`** (Pairwise Reranking Mean: `0.4894`).
298
- - Ranks 3rd globally in the 150M compact model category on the Code Representation Benchmark suite.
299
-
300
- 3. **🏅 Rank #8 Worldwide on `CoIR`** *(In the $\le$ 150M category)*
301
- - **Score: `0.5343`** (100% Zero-Shot generalizability).
302
- - Ranks 8th worldwide in the 150M category on Code Information Retrieval.
303
-
304
- 4. **🏅 Rank #9 Worldwide on `MTEB(Code, v1)`** *(In the $\le$ 150M category)*
305
- - **Score: `0.5475`** (meanTask NDCG@10).
306
- - Ranks 9th worldwide in the 150M category on the primary Code benchmark suite.
307
-
308
- 5. **🎖️ Rank #19 Worldwide on `CoREB(v1)` Overall** *(Across ALL model sizes)*
309
- - **Overall Rank #19 Worldwide** across all evaluated models regardless of parameter scale with a mean score of **`43.62%`**.
310
- - **Pairwise Reranking Mean: `48.94%`**, led by `CorebC2TReranking` (**`0.7937`**) and `CorebC2CReranking` (**`0.4205`**).
311
-
312
- 6. **🎖️ Rank #20 Worldwide on `CorebC2TReranking`** *(Across ALL model sizes)*
313
- - **Score: `0.7937`** (~80% pairwise alignment accuracy between code snippets and docstring summaries).
314
-
315
- 7. **⚡ Rank #21 Worldwide on `CodeTransOceanDL`** *(Across ALL model sizes)*
316
- - **Score: `0.3533`** (Rank #21 Worldwide).
317
- - **Beats Enterprise Models**: Outperforms `google/gemini-embedding-001` (`0.3147`, **+3.9 pts**) and `intfloat/multilingual-e5-large` (`0.3128`, **+4.1 pts**), as well as `BAAI/bge-large-en-v1.5` (`0.2104`, **+14.3 pts**).
318
-
319
- 8. **⚡ Rank #21 Worldwide on `CorebT2CReranking`** *(Across ALL model sizes)*
320
- - **Score: `0.2539`** (Near 7B LLM ceiling of `0.2882`).
321
-
322
- 9. **🥊 Rank #45 Worldwide on `CodeFeedbackMT`** *(Across ALL model sizes)*
323
- - **Score: `0.6164`** (Multi-Turn Assistant Feedback).
324
- - **Beats Enterprise Models**: Outperforms `google/gemini-embedding-001` (`0.5628`, **+5.4 pts**), `intfloat/multilingual-e5-large` (`0.4278`, **+18.9 pts / +44% relative**), and `BAAI/bge-large-en-v1.5` (`0.3689`, **+24.8 pts**).
325
-
326
- 10. **⚡ Rank #45 Worldwide on `COIRCodeSearchNetRetrieval`** *(Across ALL model sizes)*
327
- - **Score: `0.7488`** across full 300k corpus code retrieval.
328
-
329
- 11. **⚡ Massive Efficiency Advantage (92M Active Params)**
330
- - Nearly all models outranking `code-embed-v2` in the global tiers are massive 7B–14B parameter generative LLMs.
331
- - At only **92M active parameters (131M total)**, `code-embed-v2` runs **50×–100× faster**, consumes **<500 MB memory**, and supports dynamic Matryoshka dimension truncation (1536 → 768 → 512 → 256 → 128 → 64) for **up to 12× vector storage savings** with minimal metric degradation.
332
-
333
- 12. **🔓 High Openness Rating (`4 / 5`)**
334
- - Evaluated by MTEB with an Openness Score of 4/5: Open Weights (✅), Open Training Code (✅), Open Training Data (✅), and Complete Model Card (✅).
335
-
336
- ---
337
-
338
- ### 📊 Official MTEB Scorecard & Global Ranks *(Snapshot: October 24, 2026 — Sorted by Rank Ascending)*
339
-
340
- | Benchmark / Task | Category | Metric | Rank (Class / Global) | Total Models | Score | Comparison vs Baselines |
341
- | :--- | :--- | :---: | :---: | :---: | :---: | :--- |
342
- | **`CorebC2CReranking`** | Code-to-Code Reranking | MAP | **#3 Global** | 25 | **`0.4205`** | **Top 3 Worldwide**; beats Naver SPLADE 600M (`0.4198`) |
343
- | **`CoREB(v1)` (Compact Tier)** | Full Benchmark Suite | MeanTask | **#3 (≤150M)** | 8 | **`0.4362`** | **Top 3 Worldwide** in $\le$150M category; [View Filter](https://mteb-leaderboard.hf.space/benchmark/CoREB(v1)?minSize=33&maxSize=150) |
344
- | **`CoIR` (Compact Tier)** | Full Benchmark Suite | MeanTask | **#8 (≤150M)** | 17 | **`0.5343`** | **Top 8 Worldwide** in $\le$150M category; [View Filter](https://mteb-leaderboard.hf.space/benchmark/CoIR?minSize=2&maxSize=150) |
345
- | **`MTEB(Code, v1)` (Compact Tier)** | Full Benchmark Suite | MeanTask | **#9 (≤150M)** | 17 | **`0.5475`** | **Top 9 Worldwide** in $\le$150M category; [View Filter](https://mteb-leaderboard.hf.space/benchmark/MTEB(Code%2C%20v1)?minSize=2&maxSize=150) |
346
- | **`CoREB(v1)` Macro-Average** | Full Benchmark Suite | MeanTask | **#19 Global** | 25 | **`0.4362`** | **Top 20 Worldwide** (Reranking: `0.4894`, Retrieval: `0.3831`) |
347
- | **`CorebC2TReranking`** | Code-to-Text Reranking | MAP | **#20 Global** | 25 | **`0.7937`** | ~80% pairwise alignment accuracy |
348
- | **`CorebT2CReranking`** | Text-to-Code Reranking | MAP | **#21 Global** | 25 | **`0.2539`** | Near 7B LLM ceiling (`0.2882`) |
349
- | **`CodeTransOceanDL`** | DL Framework Translation | NDCG@10 | **#21 Global** | 246 | **`0.3533`** | **Beats Gemini-Embedding-001** (`0.3147`) & **E5-Large** (`0.3128`) |
350
- | **`CodeFeedbackMT`** | Multi-Turn Code Assistant | NDCG@10 | **#45 Global** | 246 | **`0.6164`** | **Beats Gemini-Embedding-001** (`0.5628`) & **E5-Large** (`0.4278`) |
351
- | **`COIRCodeSearchNetRetrieval`** | Full 300k Corpus Code Search | NDCG@10 | **#45 Global** | 264 | **`0.7488`** | High-scale multilingual code retrieval |
352
- | **`CodeFeedbackST`** | Single-Turn Code Feedback | NDCG@10 | **#52 Global** | 246 | **`0.6680`** | Robust assistant instruction alignment |
353
- | **`CoIR` Macro-Average** | Full Benchmark Suite | MeanTask | **#60 Global** | 264 | **`0.5343`** | 100% Zero-Shot generalizability across all models |
354
- | **`CodeSearchNetRetrieval`** | Multilingual Code Search | NDCG@10 | **#66 Global** | 265 | **`0.8574`** | **Beats multilingual-e5-large** (`0.8412`) |
355
- | **`MTEB(Code, v1)` Macro-Average** | Full Benchmark Suite | MeanTask | **#69 Global** | 265 | **`0.5475`** | Top quartile of all models across all sizes |
356
- | **`CodeTransOceanContest`** | Competitive Code Translation | NDCG@10 | **#82 Global** | 246 | **`0.6814`** | Cross-language algorithmic problem matching |
357
- | **`StackOverflowQA`** | Developer Q&A Matching | NDCG@10 | **#92 Global** | 246 | **`0.7131`** | High-precision question-to-code resolution |
358
- | **`CodeSearchNetCCRetrieval`** | Code Clone Retrieval | NDCG@10 | — | 246 | **`0.5661`** | Multilingual semantic clone search |
359
- | **`SyntheticText2SQL`** | Natural Language to SQL | NDCG@10 | — | 246 | **`0.4938`** | Schema-aware SQL query retrieval |
360
- | **`CosQA`** | Web Query Code QA | NDCG@10 | — | 246 | **`0.3000`** | Real-world search engine query matching |
361
- | **`AppsRetrieval`** | Complex Problem Retrieval | NDCG@10 | — | 246 | **`0.2017`** | Algorithmic specification retrieval |
362
-
363
- *Note: All scores above were evaluated with `mteb==2.26.16` and official reference implementation under revision `e3b5ded5d2448ee53043f95c414635e2d8e915e1`.*
364
-
365
- *Note: All scores above were evaluated with `mteb==2.26.16` and official reference implementation under revision `e3b5ded5d2448ee53043f95c414635e2d8e915e1`.*
366
-
367
- ---
368
-
369
- ## 💻 Production Usage & Complex Examples
370
-
371
- ### Example 1: Basic Semantic Code Search with `sentence-transformers`
372
 
373
  ```python
374
  from sentence_transformers import SentenceTransformer
375
 
376
- # Load model directly from Hugging Face Hub
377
  model = SentenceTransformer("divakantpandey/code-embed-v2")
378
 
379
  queries = [
380
  "binary search implementation with edge handling",
381
  "http json get request with retry logic",
382
- "worker pool concurrency pattern using channels"
383
  ]
384
 
385
  code_candidates = [
@@ -419,36 +397,25 @@ code_candidates = [
419
  }
420
  wg.Wait()
421
  close(results)
422
- }"""
423
  ]
424
 
425
- # Compute dense vectors (1536-dimensional native)
426
  query_vecs = model.encode(queries, normalize_embeddings=True)
427
  code_vecs = model.encode(code_candidates, normalize_embeddings=True)
428
-
429
- # Pairwise cosine similarity
430
- similarity_matrix = query_vecs @ code_vecs.T
431
 
432
  for i, q in enumerate(queries):
433
- best_match_idx = similarity_matrix[i].argmax()
434
- print(f"Query: {q}")
435
- print(f"Top Match (Score: {similarity_matrix[i][best_match_idx]:.4f}):")
436
- print(code_candidates[best_match_idx][:100] + "...\n")
437
  ```
438
 
439
- ---
440
-
441
- ### Example 2: Cross-Language Clone & Duplicate Detection
442
-
443
- Search across repositories to find functionally identical functions implemented in different programming languages:
444
 
445
  ```python
446
  from sentence_transformers import SentenceTransformer
447
- import numpy as np
448
 
449
  model = SentenceTransformer("divakantpandey/code-embed-v2")
450
 
451
- # Reference Python implementation
452
  reference_python = """
453
  def quicksort(arr):
454
  if len(arr) <= 1:
@@ -460,9 +427,7 @@ def quicksort(arr):
460
  return quicksort(left) + middle + quicksort(right)
461
  """
462
 
463
- # Candidate implementations in different languages
464
  candidates = [
465
- # Candidate A: Quicksort in Go
466
  """func QuickSort(arr []int) []int {
467
  if len(arr) <= 1 { return arr }
468
  pivot := arr[len(arr)/2]
@@ -472,7 +437,6 @@ candidates = [
472
  }
473
  return append(append(QuickSort(left), middle...), QuickSort(right)...)
474
  }""",
475
- # Candidate B: Bubble sort in Go (different algorithm)
476
  """func BubbleSort(arr []int) []int {
477
  n := len(arr)
478
  for i := 0; i < n-1; i++ {
@@ -481,26 +445,23 @@ candidates = [
481
  }
482
  }
483
  return arr
484
- }"""
485
  ]
486
 
487
- ref_emb = model.encode(reference_python, normalize_embeddings=True)
488
- cand_embs = model.encode(candidates, normalize_embeddings=True)
489
-
490
- scores = cand_embs @ ref_emb
491
- print("Candidate A (Go Quicksort) Clone Similarity:", scores[0]) # High similarity (>0.85)
492
- print("Candidate B (Go Bubble Sort) Clone Similarity:", scores[1]) # Significantly lower
493
  ```
494
 
495
- ---
496
 
497
- ### Example 3: Two-Stage Coarse-to-Fine Retrieval (Matryoshka MRL)
498
 
499
- Use 128-dimensional truncated embeddings for fast initial database scanning, then rerank the top candidates with full 1536-dimensional vectors:
500
 
501
  ```python
502
- from sentence_transformers import SentenceTransformer
503
  import numpy as np
 
504
 
505
  model = SentenceTransformer("divakantpandey/code-embed-v2")
506
 
@@ -509,239 +470,116 @@ corpus = [
509
  "import jwt, datetime\ndef make_token(uid): return jwt.encode({'sub': uid, 'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=1)}, 'secret')",
510
  "import hashlib\ndef hash_password(pwd): return hashlib.sha256(pwd.encode()).hexdigest()",
511
  "def connect_db(): return psycopg2.connect('dbname=app user=postgres')",
512
- "import jwt\ndef decode_token(tok): return jwt.decode(tok, 'secret', algorithms=['HS256'])"
513
- ] * 250 # 1,000 document simulated corpus
514
-
515
- # --- STAGE 1: Coarse Filtering (128 Dimensions -> 12x storage & speed savings) ---
516
- coarse_query = model.encode(query, truncate_dim=128, normalize_embeddings=True)
517
- coarse_corpus = model.encode(corpus, truncate_dim=128, normalize_embeddings=True)
518
-
519
- # Fast candidate selection (top 10)
520
- coarse_scores = coarse_corpus @ coarse_query
521
- top_10_indices = np.argsort(coarse_scores)[-10:][::-1]
522
-
523
- # --- STAGE 2: Fine Reranking (1536 Dimensions) ---
524
- top_candidates = [corpus[idx] for idx in top_10_indices]
525
- fine_query = model.encode(query, truncate_dim=1536, normalize_embeddings=True)
526
- fine_candidates = model.encode(top_candidates, truncate_dim=1536, normalize_embeddings=True)
527
-
528
- fine_scores = fine_candidates @ fine_query
529
- final_best_idx = top_10_indices[np.argmax(fine_scores)]
530
-
531
- print(f"Top Matched Snippet (Final score: {fine_scores.max():.4f}):")
532
- print(corpus[final_best_idx])
533
- ```
534
-
535
- ---
536
-
537
- ### Example 4: Debugging & Crash Traceback Matching
538
-
539
- Retrieve the buggy function in your codebase directly from a runtime exception traceback:
540
-
541
- ```python
542
- from sentence_transformers import SentenceTransformer
543
-
544
- model = SentenceTransformer("divakantpandey/code-embed-v2")
545
-
546
- traceback_query = """
547
- Traceback (most recent call last):
548
- File "payment_service.py", line 42, in process_transaction
549
- charge_amount = invoice.total * (1 - discount_rate)
550
- TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
551
- """
552
-
553
- repo_functions = [
554
- """def calculate_shipping(weight, distance):
555
- base_rate = 5.0
556
- return base_rate + (weight * 0.5) + (distance * 0.1)""",
557
-
558
- """def process_transaction(user_id, invoice, discount_rate=None):
559
- if discount_rate is None:
560
- discount_rate = 0.0
561
- charge_amount = invoice.total * (1 - discount_rate)
562
- return payment_gateway.charge(user_id, charge_amount)""",
563
-
564
- """def validate_email(email_address):
565
- import re
566
- regex = r'^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w+$'
567
- return bool(re.search(regex, email_address))"""
568
  ]
569
 
570
- query_vec = model.encode(traceback_query, normalize_embeddings=True)
571
- doc_vecs = model.encode(repo_functions, normalize_embeddings=True)
 
 
572
 
573
- best_idx = (doc_vecs @ query_vec).argmax()
574
- print("Associated Buggy Function Identified:")
575
- print(repo_functions[best_idx])
 
576
  ```
577
 
578
- ---
579
-
580
- ### Example 5: Qdrant Vector Database Integration
581
 
582
  ```python
583
  from qdrant_client import QdrantClient
584
  from qdrant_client.models import Distance, VectorParams, PointStruct
585
  from sentence_transformers import SentenceTransformer
586
 
587
- # Initialize client & model
588
  qdrant = QdrantClient(":memory:")
589
  model = SentenceTransformer("divakantpandey/code-embed-v2")
590
 
591
- collection_name = "codebase_symbols"
592
  qdrant.create_collection(
593
- collection_name=collection_name,
594
  vectors_config=VectorParams(size=1536, distance=Distance.COSINE),
595
  )
596
 
597
- # Ingest code files with metadata
598
  files = [
599
- {"id": 1, "path": "auth/session.go", "lang": "go", "code": "func VerifySession(token string) bool { return redis.Exists(token) }"},
600
- {"id": 2, "path": "models/user.py", "lang": "python", "code": "class User(BaseModel): id: int; name: str; active: bool"},
601
  ]
602
-
603
- points = []
604
- for f in files:
605
- vector = model.encode(f["code"], normalize_embeddings=True).tolist()
606
- points.append(PointStruct(id=f["id"], vector=vector, payload=f))
607
-
608
- qdrant.upsert(collection_name=collection_name, points=points)
609
-
610
- # Search with metadata filtering
611
- query_emb = model.encode("validate active user session", normalize_embeddings=True).tolist()
612
- search_results = qdrant.query_points(
613
- collection_name=collection_name,
614
- query=query_emb,
615
- limit=1
616
  )
617
 
618
- for hit in search_results.points:
619
- print(f"Path: {hit.payload['path']} (Score: {hit.score:.4f})")
620
- print(f"Code: {hit.payload['code']}")
 
 
 
 
621
  ```
622
 
623
- ---
624
-
625
- ### Example 6: LangChain Code Repository Q&A (RAG Pipeline)
626
 
627
  ```python
628
  from langchain_community.embeddings import HuggingFaceEmbeddings
629
  from langchain_community.vectorstores import Chroma
630
  from langchain_core.documents import Document
631
 
632
- # 1. Initialize embeddings with CodeEmbed v2
633
  embeddings = HuggingFaceEmbeddings(
634
  model_name="divakantpandey/code-embed-v2",
635
- encode_kwargs={"normalize_embeddings": True}
636
  )
637
 
638
- # 2. Build local document store
639
  documents = [
640
  Document(page_content="func RateLimiter(ip string) bool { return limiter.Allow(ip) }", metadata={"file": "security/ratelimit.go"}),
641
- Document(page_content="def send_metric(name, val): statsd.increment(name, val)", metadata={"file": "telemetry/metrics.py"})
642
  ]
643
-
644
  vector_db = Chroma.from_documents(documents, embeddings)
645
 
646
- # 3. Retrieve relevant context for an LLM query
647
- retriever = vector_db.as_retriever(search_kwargs={"k": 1})
648
- matched_docs = retriever.invoke("how do we prevent DDOS attacks on our API endpoints?")
649
-
650
- for doc in matched_docs:
651
- print(f"Source: {doc.metadata['file']}")
652
- print(f"Content: {doc.page_content}")
653
  ```
654
 
655
- ---
656
-
657
- ### Example 7: Local Serving with Ollama
658
-
659
- Run `code-embed-v2` locally with Ollama (native embed API or OpenAI-compatible endpoint).
660
 
661
  > [!NOTE]
662
- > `code-embed-v2`'s native dimension is **1536-d** (active in SentenceTransformers, ONNX, FastEmbed, and TEI). Ollama/`llama.cpp` executes the 12-layer RoBERTa transformer graph up to layer-norm, outputting the **768-d Matryoshka representation**.
663
 
664
  ```bash
665
- # 1. Pull & run directly from Hugging Face
666
  ollama pull hf.co/divakantpandey/code-embed-v2:code-embed-v2-q8_0.gguf
667
 
668
- # Or if pulled from the Ollama registry:
669
- # ollama pull divakantpandey/code-embed-v2
670
-
671
- # 2. Generate embeddings via cURL:
672
  curl http://localhost:11434/api/embed -d '{
673
- "model": "divakantpandey/code-embed-v2",
674
  "input": "def binary_search(arr, target):"
675
  }'
676
-
677
- # 3. Query via OpenAI-compatible endpoint (/v1/embeddings):
678
- curl http://localhost:11434/v1/embeddings \
679
- -H "Content-Type: application/json" \
680
- -d '{
681
- "model": "divakantpandey/code-embed-v2",
682
- "input": "def binary_search(arr, target):"
683
- }'
684
  ```
685
 
686
- ---
687
-
688
- ### Example 8: High-Performance C++ Inference with `llama.cpp`
689
-
690
- Use the Q8_0 GGUF quantized weights for standalone C++ embedding generation or an OpenAI-compatible microservice:
691
-
692
  ```bash
693
- # Download GGUF weights (135MB)
694
  wget https://huggingface.co/divakantpandey/code-embed-v2/resolve/main/code-embed-v2-q8_0.gguf
695
-
696
- # Start an OpenAI-compatible embedding server:
697
- llama-server \
698
- -m code-embed-v2-q8_0.gguf \
699
- --embedding \
700
- -c 8192 \
701
- --port 8080
702
-
703
- # Query with standard OpenAI Python SDK:
704
- from openai import OpenAI
705
-
706
- client = OpenAI(base_url="http://localhost:8080/v1", api_key="not-needed")
707
- response = client.embeddings.create(
708
- model="code-embed-v2",
709
- input="def find_max(nums):"
710
- )
711
- print("Vector length:", len(response.data[0].embedding))
712
  ```
713
 
714
- ---
715
-
716
- ### Example 9: Production Serving with Text Embeddings Inference (TEI)
717
-
718
- For enterprise throughput with dynamic batching and token truncation:
719
 
720
  ```bash
721
- # Deploy with Hugging Face TEI (Docker)
722
  docker run --gpus all -p 8080:80 \
723
  ghcr.io/huggingface/text-embeddings-inference:1.5 \
724
  --model-id divakantpandey/code-embed-v2
725
  ```
726
 
727
- ---
728
 
729
- ## 📜 License & Citation
730
-
731
- This project and its model weights are licensed under the **Creative Commons Attribution-NonCommercial 4.0 International License (CC-BY-NC 4.0)**.
732
-
733
- - **Non-Commercial Use:** Free for open-source research, academic benchmarking, developer tooling experiments, and non-commercial projects with attribution.
734
- - **Attribution:** Please attribute **Divakant Pandey** and cite:
735
- ```bibtex
736
- @misc{pandey2026codeembedv2,
737
- author = {Divakant Pandey},
738
- title = {CodeEmbed v2: High-Performance Multilingual Code Embedding Model},
739
- year = {2026},
740
- publisher = {Hugging Face / GitHub},
741
- howpublished = {\url{https://huggingface.co/divakantpandey/code-embed-v2}}
742
- }
743
- ```
744
- - **Commercial Inquiries:** For commercial deployments, SaaS integration, or enterprise licenses, contact:
745
- - **Maintainer:** Divakant Pandey
746
- - **Email:** `divakant01@gmail.com`
747
- - **GitHub:** [@divakantpandey](https://github.com/divakantpandey)
 
11
  - php
12
  - code-search
13
  - code-embeddings
 
14
  - sentence-transformers
15
  - matryoshka
16
  - unixcoder
 
21
  license: cc-by-nc-4.0
22
  pipeline_tag: feature-extraction
23
  library_name: sentence-transformers
24
+ base_model: microsoft/unixcoder-base
25
+ datasets:
26
+ - code-search-net/code_search_net
 
27
  model-index:
28
  - name: code-embed-v2
29
  results:
30
  - task:
31
+ type: retrieval
32
+ name: MTEB(Code, v1)
33
  dataset:
34
+ name: MTEB(Code, v1) mean over 12 tasks
35
+ type: mteb/benchmark
36
+ split: test
37
  metrics:
38
  - type: main_score
39
+ value: 0.5475
40
+ name: mean main_score
 
 
 
 
 
 
41
  - task:
42
+ type: retrieval
43
+ name: CoIR
44
  dataset:
45
+ name: CoIR mean over 10 tasks
46
+ type: mteb/benchmark
47
  split: test
48
  metrics:
49
+ - type: main_score
50
+ value: 0.5343
51
+ name: mean main_score
52
  - task:
53
  type: retrieval
54
+ name: CoREB(v1)
55
  dataset:
56
+ name: CoREB(v1) mean over 6 tasks
57
+ type: mteb/benchmark
58
+ split: test
59
  metrics:
60
+ - type: main_score
61
+ value: 0.4362
62
+ name: mean main_score
63
  - task:
64
  type: retrieval
65
+ name: AppsRetrieval
66
  dataset:
67
+ name: AppsRetrieval
68
+ type: mteb/AppsRetrieval
69
+ split: test
70
  metrics:
71
+ - type: main_score
72
+ value: 0.2017
73
+ name: main_score (ndcg_at_10 or map)
74
  - task:
75
+ type: retrieval
76
+ name: COIRCodeSearchNetRetrieval
77
  dataset:
78
+ name: COIRCodeSearchNetRetrieval
79
+ type: mteb/COIRCodeSearchNetRetrieval
80
  split: test
81
  metrics:
82
+ - type: main_score
83
+ value: 0.7488
84
+ name: main_score (ndcg_at_10 or map)
85
  - task:
86
+ type: retrieval
87
+ name: CodeEditSearchRetrieval
88
  dataset:
89
+ name: CodeEditSearchRetrieval
90
+ type: mteb/CodeEditSearchRetrieval
91
+ split: train
92
  metrics:
93
+ - type: main_score
94
+ value: 0.3703
95
+ name: main_score (ndcg_at_10 or map)
96
  - task:
97
  type: retrieval
98
+ name: CodeFeedbackMT
99
  dataset:
100
  name: CodeFeedbackMT
101
+ type: mteb/CodeFeedbackMT
102
  split: test
103
  metrics:
104
+ - type: main_score
105
  value: 0.6164
106
+ name: main_score (ndcg_at_10 or map)
107
  - task:
108
  type: retrieval
109
+ name: CodeFeedbackST
110
  dataset:
111
+ name: CodeFeedbackST
112
+ type: mteb/CodeFeedbackST
113
  split: test
114
  metrics:
115
+ - type: main_score
116
+ value: 0.6680
117
+ name: main_score (ndcg_at_10 or map)
118
  - task:
119
  type: retrieval
120
+ name: CodeSearchNetCCRetrieval
121
+ dataset:
122
+ name: CodeSearchNetCCRetrieval
123
+ type: mteb/CodeSearchNetCCRetrieval
124
+ split: test
125
+ metrics:
126
+ - type: main_score
127
+ value: 0.5664
128
+ name: main_score (ndcg_at_10 or map)
129
+ - task:
130
+ type: retrieval
131
+ name: CodeSearchNetRetrieval
132
  dataset:
133
  name: CodeSearchNetRetrieval
134
+ type: mteb/CodeSearchNetRetrieval
135
  split: test
136
  metrics:
137
+ - type: main_score
138
  value: 0.8574
139
+ name: main_score (ndcg_at_10 or map)
140
  - task:
141
  type: retrieval
142
+ name: CodeTransOceanContest
143
  dataset:
144
+ name: CodeTransOceanContest
145
+ type: mteb/CodeTransOceanContest
146
  split: test
147
  metrics:
148
+ - type: main_score
149
+ value: 0.6814
150
+ name: main_score (ndcg_at_10 or map)
151
  - task:
152
  type: retrieval
153
+ name: CodeTransOceanDL
154
  dataset:
155
+ name: CodeTransOceanDL
156
+ type: mteb/CodeTransOceanDL
157
  split: test
158
  metrics:
159
+ - type: main_score
160
+ value: 0.3533
161
+ name: main_score (ndcg_at_10 or map)
162
  - task:
163
+ type: reranking
164
+ name: CorebC2CReranking
165
  dataset:
166
+ name: CorebC2CReranking
167
+ type: mteb/CorebC2CReranking
168
  split: test
169
  metrics:
170
+ - type: main_score
171
+ value: 0.4205
172
+ name: main_score (ndcg_at_10 or map)
173
  - task:
174
  type: retrieval
175
+ name: CorebC2CRetrieval
176
  dataset:
177
+ name: CorebC2CRetrieval
178
+ type: mteb/CorebC2CRetrieval
179
  split: test
180
  metrics:
181
+ - type: main_score
182
+ value: 0.2750
183
+ name: main_score (ndcg_at_10 or map)
184
  - task:
185
+ type: reranking
186
+ name: CorebC2TReranking
187
  dataset:
188
+ name: CorebC2TReranking
189
+ type: mteb/CorebC2TReranking
190
  split: test
191
  metrics:
192
+ - type: main_score
193
+ value: 0.7937
194
+ name: main_score (ndcg_at_10 or map)
195
  - task:
196
  type: retrieval
197
+ name: CorebC2TRetrieval
198
  dataset:
199
  name: CorebC2TRetrieval
200
+ type: mteb/CorebC2TRetrieval
201
  split: test
202
  metrics:
203
+ - type: main_score
204
  value: 0.6073
205
+ name: main_score (ndcg_at_10 or map)
206
+ - task:
207
+ type: reranking
208
+ name: CorebT2CReranking
209
+ dataset:
210
+ name: CorebT2CReranking
211
+ type: mteb/CorebT2CReranking
212
+ split: test
213
+ metrics:
214
+ - type: main_score
215
+ value: 0.2539
216
+ name: main_score (ndcg_at_10 or map)
217
  - task:
218
  type: retrieval
219
+ name: CorebT2CRetrieval
220
  dataset:
221
+ name: CorebT2CRetrieval
222
+ type: mteb/CorebT2CRetrieval
223
  split: test
224
  metrics:
225
+ - type: main_score
226
+ value: 0.2671
227
+ name: main_score (ndcg_at_10 or map)
228
  - task:
229
  type: retrieval
230
+ name: CosQA
231
  dataset:
232
  name: CosQA
233
+ type: mteb/CosQA
234
  split: test
235
  metrics:
236
+ - type: main_score
237
+ value: 0.2997
238
+ name: main_score (ndcg_at_10 or map)
239
  - task:
240
  type: retrieval
241
+ name: StackOverflowQA
242
  dataset:
243
+ name: StackOverflowQA
244
+ type: mteb/StackOverflowQA
245
  split: test
246
  metrics:
247
+ - type: main_score
248
+ value: 0.7131
249
+ name: main_score (ndcg_at_10 or map)
250
+ - task:
251
+ type: retrieval
252
+ name: SyntheticText2SQL
253
+ dataset:
254
+ name: SyntheticText2SQL
255
+ type: mteb/SyntheticText2SQL
256
+ split: test
257
+ metrics:
258
+ - type: main_score
259
+ value: 0.4938
260
+ name: main_score (ndcg_at_10 or map)
261
  ---
262
 
263
+ # code-embed-v2
264
 
265
+ `divakantpandey/code-embed-v2` is a 129.5M-parameter code embedding model fine-tuned from [microsoft/unixcoder-base](https://huggingface.co/microsoft/unixcoder-base) on the CodeSearchNet train split (Python, JavaScript, Go, Java, Ruby, PHP). It maps natural-language queries and functions to 1536-dimensional unit vectors for code search.
 
 
266
 
267
  [![Hugging Face Model](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-divakantpandey%2Fcode--embed--v2-blue)](https://huggingface.co/divakantpandey/code-embed-v2)
268
+ [![MTEB Leaderboard](https://img.shields.io/badge/MTEB%20Leaderboard-code--embed--v2-blue)](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2)
269
+ [![MTEB Results](https://img.shields.io/badge/MTEB%20Results-PR%20%23803-brightgreen)](https://github.com/embeddings-benchmark/results/pull/803)
270
+ [![Context Length: 1024](https://img.shields.io/badge/Context%20Length-1024%20tokens-lightgrey.svg)]()
 
 
 
 
 
 
 
 
 
271
  [![License: CC-BY-NC-4.0](https://img.shields.io/badge/License-CC--BY--NC--4.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc/4.0/)
272
 
273
+ > [!WARNING]
274
+ > **Corrections (2026-11-17).** Earlier versions of this card and the accompanying preprint draft contained claims that were wrong or not backed by a measurement:
275
+ >
276
+ > - **Context length is 1,024 tokens, not 8,192.** The model has 1,026 absolute position embeddings and was trained and evaluated at 1,024 tokens. The previous config advertised 8,192, which made any input over 1,024 tokens fail with `IndexError: index 1026 is out of bounds`. The config now truncates at 1,024.
277
+ > - **Not fully zero-shot.** The model was trained on CodeSearchNet, which is the source of `CodeSearchNetRetrieval`, `COIRCodeSearchNetRetrieval` and `CodeSearchNetCCRetrieval`. Scores on those three tasks are in-distribution.
278
+ > - **Matryoshka truncation quality and CPU latency were never measured.** The tables that reported them have been removed.
279
+ > - **Training used in-batch negatives only**, not BM25 hard negatives. Pooling is mean pooling, not CLS. The Matryoshka dimensions were 64, 128, 256, 384, 768 and 1536.
280
+ > - **Supported languages are the six CodeSearchNet languages.** TypeScript and SQL were never in the training data.
281
+ > - **Parameter count is 129.5M** (90.0M excluding the token embedding table), not 131M total / 92M active.
282
+
283
+ ## Model details
284
+
285
+ | | |
286
+ |---|---|
287
+ | Base model | `microsoft/unixcoder-base` (RoBERTa architecture, 12 layers, hidden size 768) |
288
+ | Pooling | Mean over tokens |
289
+ | Head | Linear 768 → 1536, GELU, Linear 1536 → 1536, L2 normalisation |
290
+ | Output dimension | 1536 (trained with a Matryoshka loss at 64, 128, 256, 384, 768, 1536) |
291
+ | Maximum input | 1,024 tokens; longer inputs are truncated |
292
+ | Parameters | 129,471,744 total; 89,984,256 excluding the token embedding table |
293
+ | Training data | CodeSearchNet train split, 6 languages, 1,838,250 docstring–function pairs after filtering and deduplication |
294
+ | Formats | safetensors (Sentence Transformers), ONNX (`model_optimized.onnx`, 135 MB), GGUF Q8_0 (138 MB, see the note under Ollama) |
295
+ | License | CC-BY-NC-4.0 |
296
+
297
+ ## Training
298
+
299
+ Three stages, each one epoch, effective batch 128 (32 × 4 gradient accumulation), bf16 autocast, maximum length 1,024 tokens. Config: [`configs/v2_multilingual_config.yaml`](https://github.com/divakantpandey/code-embed/blob/main/configs/v2_multilingual_config.yaml).
300
+
301
+ 1. **SimCSE** on functions: two dropout views (p = 0.1) of the same function are positives, temperature 0.05, lr 3e-5.
302
+ 2. **Multiple Negatives Ranking Loss** on docstring → function pairs with in-batch negatives only, scale 25, lr 2.7e-5.
303
+ 3. **Matryoshka loss** wrapping the same ranking loss at dimensions 64, 128, 256, 384, 768, 1536 with weights 0.10, 0.10, 0.15, 0.15, 0.25, 0.25, lr 1e-5.
304
+
305
+ ## Evaluation
306
+
307
+ Official MTEB results, `mteb` 2.26, model revision `d7759ca2`, merged in [embeddings-benchmark/results#803](https://github.com/embeddings-benchmark/results/pull/803). Evaluation used 1,024 tokens.
308
+
309
+ | Benchmark | Tasks | Mean main score |
310
+ |---|---|---|
311
+ | MTEB(Code, v1) | 12 | 0.5475 |
312
+ | CoIR | 10 | 0.5343 |
313
+ | CoREB(v1) | 6 | 0.4362 |
314
+
315
+ | Task | Metric | Score | Note |
316
+ |---|---|---|---|
317
+ | AppsRetrieval | nDCG@10 | 0.2017 | |
318
+ | CodeEditSearchRetrieval | nDCG@10 | 0.3703 | |
319
+ | CodeFeedbackMT | nDCG@10 | 0.6164 | |
320
+ | CodeFeedbackST | nDCG@10 | 0.6680 | |
321
+ | CodeSearchNetCCRetrieval | nDCG@10 | 0.5664 | in-distribution |
322
+ | CodeSearchNetRetrieval | nDCG@10 | 0.8574 | in-distribution |
323
+ | COIRCodeSearchNetRetrieval | nDCG@10 | 0.7488 | in-distribution |
324
+ | CodeTransOceanContest | nDCG@10 | 0.6814 | |
325
+ | CodeTransOceanDL | nDCG@10 | 0.3533 | |
326
+ | CosQA | nDCG@10 | 0.2997 | |
327
+ | StackOverflowQA | nDCG@10 | 0.7131 | |
328
+ | SyntheticText2SQL | nDCG@10 | 0.4938 | |
329
+ | CorebC2CReranking | MAP | 0.4205 | |
330
+ | CorebC2CRetrieval | nDCG@10 | 0.2750 | |
331
+ | CorebC2TReranking | MAP | 0.7937 | |
332
+ | CorebC2TRetrieval | nDCG@10 | 0.6073 | |
333
+ | CorebT2CReranking | MAP | 0.2539 | |
334
+ | CorebT2CRetrieval | nDCG@10 | 0.2671 | |
335
+
336
+ **Leaderboard position.** On 2026-10-24, filtered to models with at most 150M parameters, the MTEB leaderboard listed this model 3rd on CoREB(v1), 8th on CoIR and 9th on MTEB(Code, v1), and 3rd of 25 models overall on CorebC2CReranking. Ranks change as models are added; check the [live leaderboard](https://mteb-leaderboard.hf.space/models/divakantpandey/code-embed-v2).
337
+
338
+ **Zero-shot status.** The model's current mteb metadata declares only `CodeSearchNetRetrieval` as training data, which gives 91% zero-shot on MTEB(Code, v1). `COIRCodeSearchNetRetrieval` and `CodeSearchNetCCRetrieval` are also built from CodeSearchNet. Declaring all three gives 75% zero-shot on MTEB(Code, v1), 80% on CoIR and 100% on CoREB(v1).
339
+
340
+ ## Limitations
341
+
342
+ - **No comparison against the base model.** UniXcoder-base was not evaluated with the same harness, so the gain from this fine-tune is not quantified.
343
+ - **Truncated dimensions are untested.** The model was trained with a Matryoshka loss, but retrieval quality at truncated dimensions has not been measured. Validate on your own data before relying on it.
344
+ - **Latency is not benchmarked.**
345
+ - **The GGUF file is not the same embedding.** It outputs the 768-dimensional backbone representation without the projection head, and it has not been evaluated. Do not mix GGUF vectors with Sentence Transformers vectors in one index.
346
+ - **Function-level training only.** Training pairs are single functions with their docstrings, at most 1,024 tokens. Whole files, other languages, and non-docstring queries are out of distribution.
347
+
348
+ ## Usage
349
+
350
+ ### Semantic code search with `sentence-transformers`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
 
352
  ```python
353
  from sentence_transformers import SentenceTransformer
354
 
 
355
  model = SentenceTransformer("divakantpandey/code-embed-v2")
356
 
357
  queries = [
358
  "binary search implementation with edge handling",
359
  "http json get request with retry logic",
360
+ "worker pool concurrency pattern using channels",
361
  ]
362
 
363
  code_candidates = [
 
397
  }
398
  wg.Wait()
399
  close(results)
400
+ }""",
401
  ]
402
 
 
403
  query_vecs = model.encode(queries, normalize_embeddings=True)
404
  code_vecs = model.encode(code_candidates, normalize_embeddings=True)
405
+ similarity = query_vecs @ code_vecs.T
 
 
406
 
407
  for i, q in enumerate(queries):
408
+ best = similarity[i].argmax()
409
+ print(f"{q!r} -> candidate {best} (score {similarity[i][best]:.4f})")
 
 
410
  ```
411
 
412
+ ### Code-to-code similarity
 
 
 
 
413
 
414
  ```python
415
  from sentence_transformers import SentenceTransformer
 
416
 
417
  model = SentenceTransformer("divakantpandey/code-embed-v2")
418
 
 
419
  reference_python = """
420
  def quicksort(arr):
421
  if len(arr) <= 1:
 
427
  return quicksort(left) + middle + quicksort(right)
428
  """
429
 
 
430
  candidates = [
 
431
  """func QuickSort(arr []int) []int {
432
  if len(arr) <= 1 { return arr }
433
  pivot := arr[len(arr)/2]
 
437
  }
438
  return append(append(QuickSort(left), middle...), QuickSort(right)...)
439
  }""",
 
440
  """func BubbleSort(arr []int) []int {
441
  n := len(arr)
442
  for i := 0; i < n-1; i++ {
 
445
  }
446
  }
447
  return arr
448
+ }""",
449
  ]
450
 
451
+ ref = model.encode(reference_python, normalize_embeddings=True)
452
+ cands = model.encode(candidates, normalize_embeddings=True)
453
+ print(cands @ ref)
 
 
 
454
  ```
455
 
456
+ The model was not trained on cross-language pairs. Code-to-code scores across languages come from the shared docstring-to-code objective; check them on your own data.
457
 
458
+ ### Truncated embeddings
459
 
460
+ The model was trained with a Matryoshka loss at 64, 128, 256, 384, 768 and 1536 dimensions, so leading prefixes of the vector can be used as smaller embeddings. Quality at each size has not been measured.
461
 
462
  ```python
 
463
  import numpy as np
464
+ from sentence_transformers import SentenceTransformer
465
 
466
  model = SentenceTransformer("divakantpandey/code-embed-v2")
467
 
 
470
  "import jwt, datetime\ndef make_token(uid): return jwt.encode({'sub': uid, 'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=1)}, 'secret')",
471
  "import hashlib\ndef hash_password(pwd): return hashlib.sha256(pwd.encode()).hexdigest()",
472
  "def connect_db(): return psycopg2.connect('dbname=app user=postgres')",
473
+ "import jwt\ndef decode_token(tok): return jwt.decode(tok, 'secret', algorithms=['HS256'])",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  ]
475
 
476
+ # Stage 1: shortlist with 256-d prefixes.
477
+ q256 = model.encode(query, truncate_dim=256, normalize_embeddings=True)
478
+ c256 = model.encode(corpus, truncate_dim=256, normalize_embeddings=True)
479
+ shortlist = np.argsort(c256 @ q256)[::-1][:2]
480
 
481
+ # Stage 2: rerank the shortlist with full 1536-d vectors.
482
+ q = model.encode(query, normalize_embeddings=True)
483
+ c = model.encode([corpus[i] for i in shortlist], normalize_embeddings=True)
484
+ print(corpus[shortlist[np.argmax(c @ q)]])
485
  ```
486
 
487
+ ### Qdrant
 
 
488
 
489
  ```python
490
  from qdrant_client import QdrantClient
491
  from qdrant_client.models import Distance, VectorParams, PointStruct
492
  from sentence_transformers import SentenceTransformer
493
 
 
494
  qdrant = QdrantClient(":memory:")
495
  model = SentenceTransformer("divakantpandey/code-embed-v2")
496
 
 
497
  qdrant.create_collection(
498
+ collection_name="codebase_symbols",
499
  vectors_config=VectorParams(size=1536, distance=Distance.COSINE),
500
  )
501
 
 
502
  files = [
503
+ {"id": 1, "path": "auth/session.go", "code": "func VerifySession(token string) bool { return redis.Exists(token) }"},
504
+ {"id": 2, "path": "models/user.py", "code": "class User(BaseModel): id: int; name: str; active: bool"},
505
  ]
506
+ qdrant.upsert(
507
+ collection_name="codebase_symbols",
508
+ points=[
509
+ PointStruct(id=f["id"], vector=model.encode(f["code"], normalize_embeddings=True).tolist(), payload=f)
510
+ for f in files
511
+ ],
 
 
 
 
 
 
 
 
512
  )
513
 
514
+ hits = qdrant.query_points(
515
+ collection_name="codebase_symbols",
516
+ query=model.encode("validate active user session", normalize_embeddings=True).tolist(),
517
+ limit=1,
518
+ )
519
+ for hit in hits.points:
520
+ print(hit.payload["path"], round(hit.score, 4))
521
  ```
522
 
523
+ ### LangChain
 
 
524
 
525
  ```python
526
  from langchain_community.embeddings import HuggingFaceEmbeddings
527
  from langchain_community.vectorstores import Chroma
528
  from langchain_core.documents import Document
529
 
 
530
  embeddings = HuggingFaceEmbeddings(
531
  model_name="divakantpandey/code-embed-v2",
532
+ encode_kwargs={"normalize_embeddings": True},
533
  )
534
 
 
535
  documents = [
536
  Document(page_content="func RateLimiter(ip string) bool { return limiter.Allow(ip) }", metadata={"file": "security/ratelimit.go"}),
537
+ Document(page_content="def send_metric(name, val): statsd.increment(name, val)", metadata={"file": "telemetry/metrics.py"}),
538
  ]
 
539
  vector_db = Chroma.from_documents(documents, embeddings)
540
 
541
+ for doc in vector_db.as_retriever(search_kwargs={"k": 1}).invoke("rate limit requests per client IP"):
542
+ print(doc.metadata["file"])
 
 
 
 
 
543
  ```
544
 
545
+ ### Ollama and llama.cpp (GGUF)
 
 
 
 
546
 
547
  > [!NOTE]
548
+ > The GGUF file contains the transformer only. It returns the 768-dimensional pooled backbone output, without the 1536-d projection head, so its vectors are not the same as the Sentence Transformers output and have not been evaluated. Keep the context at 1,024 tokens.
549
 
550
  ```bash
 
551
  ollama pull hf.co/divakantpandey/code-embed-v2:code-embed-v2-q8_0.gguf
552
 
 
 
 
 
553
  curl http://localhost:11434/api/embed -d '{
554
+ "model": "hf.co/divakantpandey/code-embed-v2:code-embed-v2-q8_0.gguf",
555
  "input": "def binary_search(arr, target):"
556
  }'
 
 
 
 
 
 
 
 
557
  ```
558
 
 
 
 
 
 
 
559
  ```bash
 
560
  wget https://huggingface.co/divakantpandey/code-embed-v2/resolve/main/code-embed-v2-q8_0.gguf
561
+ llama-server -m code-embed-v2-q8_0.gguf --embedding -c 1024 --port 8080
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  ```
563
 
564
+ ### Text Embeddings Inference
 
 
 
 
565
 
566
  ```bash
 
567
  docker run --gpus all -p 8080:80 \
568
  ghcr.io/huggingface/text-embeddings-inference:1.5 \
569
  --model-id divakantpandey/code-embed-v2
570
  ```
571
 
572
+ Check that the returned vectors are 1536-dimensional. A 768-dimensional result means the projection head was not applied.
573
 
574
+ ## License and citation
575
+
576
+ Code and weights are released under [CC-BY-NC-4.0](https://creativecommons.org/licenses/by-nc/4.0/). For commercial use, contact Divakant Pandey (`divakant01@gmail.com`, [@divakantpandey](https://github.com/divakantpandey)).
577
+
578
+ ```bibtex
579
+ @misc{pandey2026codeembedv2,
580
+ author = {Divakant Pandey},
581
+ title = {code-embed-v2: A UniXcoder-Based Code Embedding Model Fine-Tuned on CodeSearchNet},
582
+ year = {2026},
583
+ howpublished = {\url{https://huggingface.co/divakantpandey/code-embed-v2}}
584
+ }
585
+ ```
 
 
 
 
 
 
 
code_embed_config.json CHANGED
@@ -3,7 +3,7 @@
3
  "backbone_hidden_size": 768,
4
  "embedding_dim": 1536,
5
  "projection_hidden_dim": 1536,
6
- "pooling": "cls",
7
- "max_seq_length": 8192,
8
  "dropout": 0.1
9
- }
 
3
  "backbone_hidden_size": 768,
4
  "embedding_dim": 1536,
5
  "projection_hidden_dim": 1536,
6
+ "pooling": "mean",
7
+ "max_seq_length": 1024,
8
  "dropout": 0.1
9
+ }
sentence_bert_config.json CHANGED
@@ -7,5 +7,5 @@
7
  }
8
  },
9
  "module_output_name": "token_embeddings",
10
- "max_seq_length": 8192
11
- }
 
7
  }
8
  },
9
  "module_output_name": "token_embeddings",
10
+ "max_seq_length": 1024
11
+ }
tokenizer_config.json CHANGED
@@ -8,8 +8,8 @@
8
  "is_local": true,
9
  "local_files_only": false,
10
  "mask_token": "<mask>",
11
- "max_length": 8192,
12
- "model_max_length": 8192,
13
  "pad_to_multiple_of": null,
14
  "pad_token": "<pad>",
15
  "pad_token_type_id": 0,
@@ -21,4 +21,4 @@
21
  "truncation_side": "right",
22
  "truncation_strategy": "longest_first",
23
  "unk_token": "<unk>"
24
- }
 
8
  "is_local": true,
9
  "local_files_only": false,
10
  "mask_token": "<mask>",
11
+ "max_length": 1024,
12
+ "model_max_length": 1024,
13
  "pad_to_multiple_of": null,
14
  "pad_token": "<pad>",
15
  "pad_token_type_id": 0,
 
21
  "truncation_side": "right",
22
  "truncation_strategy": "longest_first",
23
  "unk_token": "<unk>"
24
+ }