File size: 4,027 Bytes
40781c4
 
 
 
 
 
 
 
 
 
 
 
2f98d98
40781c4
 
 
 
 
 
 
2f98d98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40781c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
language:
  - en
  - code
tags:
  - python
  - code-search
  - code-embeddings
  - sentence-transformers
  - unixcoder
  - matryoshka
  - onnx
  - mteb
license: cc-by-nc-4.0
pipeline_tag: feature-extraction
library_name: sentence-transformers
metrics:
  - mrr
  - ndcg
  - recall
model-index:
  - name: Code-Embed
    results:
      - task:
          type: feature-extraction
          name: Code Search
        dataset:
          name: CodeSearchNet (Python)
          type: code_search_net
          config: python
          split: test
        metrics:
          - type: mrr@10
            value: 0.7514
            name: MRR@10 (100-pool)
          - type: mrr@10
            value: 0.8241
            name: MRR@10 (15k-corpus)
          - type: recall@10
            value: 0.9230
            name: Recall@10 (15k-corpus)
      - task:
          type: feature-extraction
          name: Code Question Answering
        dataset:
          name: CoSQA
          type: cosqa
          split: validation
        metrics:
          - type: mrr@10
            value: 0.7509
            name: MRR@10
          - type: recall@10
            value: 0.8600
            name: Recall@10
---

# 💻 code-embed

CodeEmbed is a lightweight, high-performance code embedding model (≤130M parameters) developed by **[Divakant Pandey](https://github.com/divakantpandey)**. Specialized for semantic code search, code retrieval, and repository navigation with **8,192 token context** and **Matryoshka representation learning**.

## 🚀 Key Features

- **Author / Maintainer**: [Divakant Pandey](https://github.com/divakantpandey)
- **Backbone**: UniXcoder bi-encoder architecture with a 2-layer MLP projection head and unit-sphere L2 normalization.
- **3-Stage Curriculum**:
  1. *SimCSE Unsupervised Contrastive Learning* (uniformity on hypersphere).
  2. *Supervised Fine-Tuning* (MNRL with BM25 lexical hard negatives).
  3. *Matryoshka Representation Learning (MRL)* (nested dimensions: 64, 128, 256, 384, 768, 1536).
- **Fast CPU Inference**: ~20.8 ms per code snippet on standard laptop CPU.
- **Production-Ready**: Exportable to ONNX with dynamic axes and dynamic INT8 quantization.

## 📊 Benchmark Results

| Benchmark | Metric | Value | Gate Status |
| :--- | :--- | :---: | :---: |
| **CodeSearchNet (Python)** | **MRR@10** | **0.7514** | **PASS** (≥ 0.65) |
| **CoSQA (Code Search QA)** | **MRR@10** | **0.7509** | **PASS** (≥ 0.50) |
| **Hypersphere Uniformity** | **Uniformity** | **-1.9758** | **PASS** (≤ -1.0) |
| **Single-Snippet Latency** | **CPU Latency** | **20.8 ms** | **PASS** (< 100 ms) |

## 💻 Quickstart Usage

### With Sentence-Transformers:
```python
from sentence_transformers import SentenceTransformer

# Automatically downloads from Hugging Face Hub
model = SentenceTransformer("divakantpandey/code-embed")

queries = ["binary search in sorted list", "read json file"]
snippets = [
    "def binary_search(arr, target): ...",
    "import json\ndef load_json(path): return json.load(open(path))"
]

query_embeddings = model.encode(queries, normalize_embeddings=True)
code_embeddings = model.encode(snippets, normalize_embeddings=True)

# Compute cosine similarity
similarities = query_embeddings @ code_embeddings.T
print(similarities)
```

## 📜 License & Commercial Inquiries

This model and its weights are released under the **Creative Commons Attribution-NonCommercial 4.0 International (CC-BY-NC 4.0)** license.

- **Non-Commercial Use:** Free for academic research, education, benchmarking, and non-commercial projects with attribution.
- **Attribution:** Please cite **Divakant Pandey** and link to [https://github.com/divakantpandey/code-embed](https://github.com/divakantpandey/code-embed).
- **Commercial Licensing:** To use this model in commercial applications, proprietary software, enterprise APIs, or SaaS products, please contact:
  - **Maintainer:** Divakant Pandey
  - **Email:** `divakant01@gmail.com`
  - **GitHub:** [@divakantpandey](https://github.com/divakantpandey)