Code-Embed v2 (Fast Lane Update) ๐Ÿš€

State-of-the-Art Code Embedding & Semantic Search Model

Hugging Face License: CC BY-NC 4.0 Framework: Sentence-Transformers Supported Languages

Developed by Divakant Pandey, code-embed-v2 is a premier code embedding model engineered for dense code retrieval, developer Q&A search, competitive algorithm matching, cross-language translation, and multi-turn instruction following.


๐ŸŒŸ Benchmark Performance: Yesterday vs. Fast Lane

Evaluating across all 17 official MTEB, CoIR, and CoREB benchmarks shows massive empirical gains across every single programming modality:

Benchmark Task Category Baseline (Yesterday) Fast Lane (Updated) Absolute Gain Relative Gain
CodeSearchNetRetrieval Text-to-Code Search 38.67% 89.16% +50.49% +130.6% (2.3ร—)
CodeSearchNetCCRetrieval Code-to-Code Clone Search 15.58% 63.95% +48.37% +310.5% (4.1ร—)
CorebC2TRetrieval Code-to-Text Documentation 22.32% 60.73% +38.41% +172.1%
CodeTransOceanContest Algorithmic Translation 36.40% 68.14% +31.74% +87.2%
CodeFeedbackMT Multi-Turn Context Matching 31.88% 61.64% +29.76% +93.4%
CorebC2CRetrieval Code-to-Code Cross-Repo 2.87% 27.50% +24.63% +858.2% (9.6ร—)
CodeFeedbackST Single-Turn Instruction Match 46.93% 66.80% +19.87% +42.3%
CorebT2CRetrieval Text-to-Code Search 7.45% 26.71% +19.26% +258.5% (3.6ร—)
CorebC2TReranking Code-to-Text Reranking 66.74% 84.55% +17.81% +26.7%
AppsRetrieval Complex Problem Solving 3.06% 20.17% +17.11% +559.0% (6.6ร—)
SyntheticText2SQL Natural Language to SQL 32.77% 49.38% +16.61% +50.7%
StackOverflowQA Developer Q&A Matching 55.30% 71.31% +16.01% +29.0%
CorebC2CReranking Code-to-Code Reranking 36.87% 51.54% +14.67% +39.8%
CosQA Web Query Code Search 15.99% 29.97% +13.98% +87.4%
CorebT2CReranking Text-to-Code Reranking 26.44% 36.81% +10.37% +39.2%
CodeTransOceanDL Deep Learning Translation 34.39% 35.33% +0.94% +2.7%
COIRCodeSearchNetRetrieval Multilingual Search 98.45% 94.22% -4.23% -4.3%
OVERALL MACRO-AVERAGE 17 Official Benchmarks 33.65% 55.17% +21.52% +63.9%

๐Ÿ’ป Quickstart Usage

1. Basic Semantic Code Search with sentence-transformers

from sentence_transformers import SentenceTransformer

# Load updated model directly from Hugging Face Hub
model = SentenceTransformer("divakantpandey/code-embed-v2")

queries = [
    "binary search implementation",
    "fetch json from api endpoint",
    "goroutine channel worker pool"
]

code_snippets = [
    "def binary_search(arr, target):\n    left, right = 0, len(arr) - 1\n    while left <= right:\n        mid = (left + right) // 2\n        if arr[mid] == target: return mid\n        elif arr[mid] < target: left = mid + 1\n        else: right = mid - 1\n    return -1",
    "async function fetchJSON(url) {\n    const response = await fetch(url);\n    return await response.json();\n}",
    "func worker(id int, jobs <-chan int, results chan<- int) {\n    for j := range jobs {\n        results <- j * 2\n    }\n}"
]

# Generate normalized embeddings (1536-dim native)
query_embeddings = model.encode(queries, normalize_embeddings=True)
code_embeddings = model.encode(code_snippets, normalize_embeddings=True)

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

2. Matryoshka Representation Learning (Adaptive Dimensions)

code-embed-v2 supports adaptive vector truncation. You can truncate embeddings down to 768, 512, 256, or 128 dimensions for reduced storage with minimal retrieval accuracy trade-off:

# Truncate to 768 dimensions (50% storage & compute reduction)
compact_query_embs = model.encode(queries, truncate_dim=768, normalize_embeddings=True)
compact_code_embs = model.encode(code_snippets, truncate_dim=768, normalize_embeddings=True)

similarity = compact_query_embs @ compact_code_embs.T

๐Ÿ“œ License & Commercial Terms

This model and its associated weights are licensed under the Creative Commons Attribution-NonCommercial 4.0 International Public License (CC-BY-NC 4.0).

  • Non-Commercial Use: Free for academic research, educational use, personal exploration, open-source evaluations, and non-commercial benchmarking with attribution.
  • Attribution: Please attribute Divakant Pandey and reference the repository at https://github.com/divakantpandey/code-embed.
  • Commercial Licensing: To license CodeEmbed v2 for commercial products, enterprise SaaS applications, closed-source systems, or proprietary developer tools, please contact:
    • Licensor / Maintainer: Divakant Pandey
    • Email: divakant01@gmail.com
    • GitHub: @divakantpandey
Downloads last month
3
Safetensors
Model size
0.1B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Space using divakantpandey/code-embed-v2 1

Collection including divakantpandey/code-embed-v2

Evaluation results