--- 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)