๐Ÿ’ป CodeEmbed v2: Multilingual Code & Query Embedding Model (131M)

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.

On the official Massive Text Embedding Benchmark (MTEB), CodeEmbed v2 achieves Rank #3 Worldwide in Code-to-Code Reranking, ranks Top 20 Worldwide on the CoREB benchmark suite, and outperforms frontier enterprise 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.

Hugging Face Model MTEB Official Leaderboard Coreb C2C Reranking CoREB(v1) Rank CoIR Rank MTEB Code Rank MTEB Openness Context Length: 8192 MTEB Results Sentence-Transformers License: CC-BY-NC-4.0


๐ŸŒŸ Key Product Capabilities

  • 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).
  • Multilingual Programming Support: First-class embedding support for Python, JavaScript, TypeScript, Go, Java, Ruby, PHP, SQL, and natural language technical English.
  • 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).
  • 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.
  • Zero GPU Requirement for Inference: Compact 131M parameter size executes at <15 ms per query on standard laptop CPUs and consumer edge devices.
  • Ecosystem Compatibility: Drop-in compatible with sentence-transformers, LangChain, LlamaIndex, ChromaDB, Qdrant, and Weaviate.

๐Ÿ† Official MTEB Leaderboard Achievements & Scorecard

Temporal Snapshot & Benchmark Version Notice: The rankings, scores, and competitive metrics documented below reflect the official Massive Text Embedding Benchmark (MTEB) snapshot as of October 23, 2026 (MTEB Leaderboard Build 39959364296 / mteb==2.26.16 / PR #803 merged into embeddings-benchmark/results:main). 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.

๐ŸŒŸ Key Benchmark Highlights

  1. ๐Ÿฅ‡ Rank #3 Worldwide on Code-to-Code Reranking (CorebC2CReranking)

    • Score: 0.4205 (Rank #3 globally out of all models ever evaluated).
    • Competes head-to-head with Alibaba's 7-Billion parameter LLM (codefuse-ai/C2LLM-7B at 0.4238, a margin of just 0.003).
    • 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).
    • Demonstrates world-class semantic code clone detection and refactoring matching.
  2. ๐ŸฅŠ Outperforming Enterprise Frontier Models Head-to-Head

    • Multi-Turn Assistant Feedback (CodeFeedbackMT):
      • divakantpandey/code-embed-v2: 0.6164 (Global Rank #45)
      • google/gemini-embedding-001: 0.5628 (Global Rank #54) โž” +5.4 points higher than Google Gemini
      • intfloat/multilingual-e5-large: 0.4278 (Global Rank #93) โž” +18.9 points higher than Microsoft E5-Large (+44% relative)
      • BAAI/bge-large-en-v1.5: 0.3689 (Global Rank #113) โž” +24.8 points higher than BAAI BGE-Large
    • Cross-Framework Deep Learning Translation (CodeTransOceanDL):
      • divakantpandey/code-embed-v2: 0.3533 (Global Rank #21 Worldwide)
      • google/gemini-embedding-001: 0.3147 (Global Rank #89) โž” +3.9 points higher than Google Gemini
      • intfloat/multilingual-e5-large: 0.3128 (Global Rank #94) โž” +4.1 points higher than Microsoft E5-Large
      • BAAI/bge-large-en-v1.5: 0.2104 (Global Rank #171) โž” +14.3 points higher than BAAI BGE-Large
  3. ๐ŸŽ–๏ธ Top 20 Global Benchmark Placement on CoREB(v1)

    • Overall Rank: #19 Worldwide across all evaluated models with a mean score of 43.62%.
    • Pairwise Reranking Mean: 48.94%, led by CorebC2TReranking (0.7937) and CorebC2CReranking (0.4205).
  4. โšก Massive Efficiency Advantage (92M Active Params)

    • Nearly all models outranking code-embed-v2 are massive 7Bโ€“14B parameter generative LLMs.
    • 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.
  5. ๐Ÿ”“ High Openness Rating (4 / 5)

    • Evaluated by MTEB with an Openness Score of 4/5: Open Weights (โœ…), Open Training Code (โœ…), Open Training Data (โœ…), and Complete Model Card (โœ…).

๐Ÿ“Š Official MTEB Scorecard & Global Ranks (Snapshot: October 23, 2026)

Benchmark / Task Category Metric Global Rank Total Models Score Comparison vs Baselines
CorebC2CReranking Code-to-Code Reranking MAP #3 25 0.4205 Top 3 Worldwide; beats Naver SPLADE 600M (0.4198)
CorebC2TReranking Code-to-Text Reranking MAP #20 25 0.7937 ~80% pairwise alignment accuracy
CorebT2CReranking Text-to-Code Reranking MAP #21 25 0.2539 Near 7B LLM ceiling (0.2882)
CodeTransOceanDL DL Framework Translation NDCG@10 #21 246 0.3533 Beats Gemini-Embedding-001 (0.3147) & E5-Large (0.3128)
CodeFeedbackMT Multi-Turn Code Assistant NDCG@10 #45 246 0.6164 Beats Gemini-Embedding-001 (0.5628) & E5-Large (0.4278)
COIRCodeSearchNetRetrieval Full 300k Corpus Code Search NDCG@10 #45 264 0.7488 High-scale multilingual code retrieval
CodeFeedbackST Single-Turn Code Feedback NDCG@10 #52 246 0.6680 Robust assistant instruction alignment
CodeSearchNetRetrieval Multilingual Code Search NDCG@10 #66 265 0.8574 Beats multilingual-e5-large (0.8412)
CodeTransOceanContest Competitive Code Translation NDCG@10 #82 246 0.6814 Cross-language algorithmic problem matching
StackOverflowQA Developer Q&A Matching NDCG@10 #92 246 0.7131 High-precision question-to-code resolution
CodeSearchNetCCRetrieval Code Clone Retrieval NDCG@10 โ€” 246 0.5661 Multilingual semantic clone search
SyntheticText2SQL Natural Language to SQL NDCG@10 โ€” 246 0.4938 Schema-aware SQL query retrieval
CosQA Web Query Code QA NDCG@10 โ€” 246 0.3000 Real-world search engine query matching
AppsRetrieval Complex Problem Retrieval NDCG@10 โ€” 246 0.2017 Algorithmic specification retrieval
CoREB(v1) Macro-Average Full Benchmark Suite MeanTask #19 25 0.4362 Top 20 Worldwide (Reranking: 0.4894, Retrieval: 0.3831)
CoIR Macro-Average Full Benchmark Suite MeanTask #60 264 0.5343 100% Zero-Shot generalizability
MTEB(Code, v1) Macro-Average Full Benchmark Suite MeanTask #69 265 0.5475 Top quartile of all models across all sizes

Note: All scores above were evaluated with mteb==2.26.16 and official reference implementation under revision e3b5ded5d2448ee53043f95c414635e2d8e915e1.


๐Ÿ’ป Production Usage & Complex Examples

Example 1: Basic Semantic Code Search with sentence-transformers

from sentence_transformers import SentenceTransformer

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

queries = [
    "binary search implementation with edge handling",
    "http json get request with retry logic",
    "worker pool concurrency pattern using channels"
]

code_candidates = [
    """def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1""",
    """async function fetchWithRetry(url, retries = 3) {
    for (let i = 0; i < retries; i++) {
        try {
            const res = await fetch(url);
            if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
            return await res.json();
        } catch (err) {
            if (i === retries - 1) throw err;
            await new Promise(r => setTimeout(r, 1000 * Math.pow(2, i)));
        }
    }
}""",
    """func WorkerPool(numWorkers int, jobs <-chan int, results chan<- int) {
    var wg sync.WaitGroup
    for i := 0; i < numWorkers; i++ {
        wg.Add(1)
        go func() {
            defer wg.Done()
            for j := range jobs {
                results <- j * 2
            }
        }()
    }
    wg.Wait()
    close(results)
}"""
]

# Compute dense vectors (1536-dimensional native)
query_vecs = model.encode(queries, normalize_embeddings=True)
code_vecs = model.encode(code_candidates, normalize_embeddings=True)

# Pairwise cosine similarity
similarity_matrix = query_vecs @ code_vecs.T

for i, q in enumerate(queries):
    best_match_idx = similarity_matrix[i].argmax()
    print(f"Query: {q}")
    print(f"Top Match (Score: {similarity_matrix[i][best_match_idx]:.4f}):")
    print(code_candidates[best_match_idx][:100] + "...\n")

Example 2: Cross-Language Clone & Duplicate Detection

Search across repositories to find functionally identical functions implemented in different programming languages:

from sentence_transformers import SentenceTransformer
import numpy as np

model = SentenceTransformer("divakantpandey/code-embed-v2")

# Reference Python implementation
reference_python = """
def quicksort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quicksort(left) + middle + quicksort(right)
"""

# Candidate implementations in different languages
candidates = [
    # Candidate A: Quicksort in Go
    """func QuickSort(arr []int) []int {
        if len(arr) <= 1 { return arr }
        pivot := arr[len(arr)/2]
        var left, middle, right []int
        for _, x := range arr {
            if x < pivot { left = append(left, x) } else if x == pivot { middle = append(middle, x) } else { right = append(right, x) }
        }
        return append(append(QuickSort(left), middle...), QuickSort(right)...)
    }""",
    # Candidate B: Bubble sort in Go (different algorithm)
    """func BubbleSort(arr []int) []int {
        n := len(arr)
        for i := 0; i < n-1; i++ {
            for j := 0; j < n-i-1; j++ {
                if arr[j] > arr[j+1] { arr[j], arr[j+1] = arr[j+1], arr[j] }
            }
        }
        return arr
    }"""
]

ref_emb = model.encode(reference_python, normalize_embeddings=True)
cand_embs = model.encode(candidates, normalize_embeddings=True)

scores = cand_embs @ ref_emb
print("Candidate A (Go Quicksort) Clone Similarity:", scores[0]) # High similarity (>0.85)
print("Candidate B (Go Bubble Sort) Clone Similarity:", scores[1]) # Significantly lower

Example 3: Two-Stage Coarse-to-Fine Retrieval (Matryoshka MRL)

Use 128-dimensional truncated embeddings for fast initial database scanning, then rerank the top candidates with full 1536-dimensional vectors:

from sentence_transformers import SentenceTransformer
import numpy as np

model = SentenceTransformer("divakantpandey/code-embed-v2")

query = "JWT token generation with expiration time"
corpus = [
    "import jwt, datetime\ndef make_token(uid): return jwt.encode({'sub': uid, 'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=1)}, 'secret')",
    "import hashlib\ndef hash_password(pwd): return hashlib.sha256(pwd.encode()).hexdigest()",
    "def connect_db(): return psycopg2.connect('dbname=app user=postgres')",
    "import jwt\ndef decode_token(tok): return jwt.decode(tok, 'secret', algorithms=['HS256'])"
] * 250  # 1,000 document simulated corpus

# --- STAGE 1: Coarse Filtering (128 Dimensions -> 12x storage & speed savings) ---
coarse_query = model.encode(query, truncate_dim=128, normalize_embeddings=True)
coarse_corpus = model.encode(corpus, truncate_dim=128, normalize_embeddings=True)

# Fast candidate selection (top 10)
coarse_scores = coarse_corpus @ coarse_query
top_10_indices = np.argsort(coarse_scores)[-10:][::-1]

# --- STAGE 2: Fine Reranking (1536 Dimensions) ---
top_candidates = [corpus[idx] for idx in top_10_indices]
fine_query = model.encode(query, truncate_dim=1536, normalize_embeddings=True)
fine_candidates = model.encode(top_candidates, truncate_dim=1536, normalize_embeddings=True)

fine_scores = fine_candidates @ fine_query
final_best_idx = top_10_indices[np.argmax(fine_scores)]

print(f"Top Matched Snippet (Final score: {fine_scores.max():.4f}):")
print(corpus[final_best_idx])

Example 4: Debugging & Crash Traceback Matching

Retrieve the buggy function in your codebase directly from a runtime exception traceback:

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("divakantpandey/code-embed-v2")

traceback_query = """
Traceback (most recent call last):
  File "payment_service.py", line 42, in process_transaction
    charge_amount = invoice.total * (1 - discount_rate)
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
"""

repo_functions = [
    """def calculate_shipping(weight, distance):
    base_rate = 5.0
    return base_rate + (weight * 0.5) + (distance * 0.1)""",
    
    """def process_transaction(user_id, invoice, discount_rate=None):
    if discount_rate is None:
        discount_rate = 0.0
    charge_amount = invoice.total * (1 - discount_rate)
    return payment_gateway.charge(user_id, charge_amount)""",
    
    """def validate_email(email_address):
    import re
    regex = r'^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w+$'
    return bool(re.search(regex, email_address))"""
]

query_vec = model.encode(traceback_query, normalize_embeddings=True)
doc_vecs = model.encode(repo_functions, normalize_embeddings=True)

best_idx = (doc_vecs @ query_vec).argmax()
print("Associated Buggy Function Identified:")
print(repo_functions[best_idx])

Example 5: Qdrant Vector Database Integration

from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
from sentence_transformers import SentenceTransformer

# Initialize client & model
qdrant = QdrantClient(":memory:")
model = SentenceTransformer("divakantpandey/code-embed-v2")

collection_name = "codebase_symbols"
qdrant.create_collection(
    collection_name=collection_name,
    vectors_config=VectorParams(size=1536, distance=Distance.COSINE),
)

# Ingest code files with metadata
files = [
    {"id": 1, "path": "auth/session.go", "lang": "go", "code": "func VerifySession(token string) bool { return redis.Exists(token) }"},
    {"id": 2, "path": "models/user.py", "lang": "python", "code": "class User(BaseModel): id: int; name: str; active: bool"},
]

points = []
for f in files:
    vector = model.encode(f["code"], normalize_embeddings=True).tolist()
    points.append(PointStruct(id=f["id"], vector=vector, payload=f))

qdrant.upsert(collection_name=collection_name, points=points)

# Search with metadata filtering
query_emb = model.encode("validate active user session", normalize_embeddings=True).tolist()
search_results = qdrant.query_points(
    collection_name=collection_name,
    query=query_emb,
    limit=1
)

for hit in search_results.points:
    print(f"Path: {hit.payload['path']} (Score: {hit.score:.4f})")
    print(f"Code: {hit.payload['code']}")

Example 6: LangChain Code Repository Q&A (RAG Pipeline)

from langchain_community.embeddings import HuggingFaceEmbeddings
from langchain_community.vectorstores import Chroma
from langchain_core.documents import Document

# 1. Initialize embeddings with CodeEmbed v2
embeddings = HuggingFaceEmbeddings(
    model_name="divakantpandey/code-embed-v2",
    encode_kwargs={"normalize_embeddings": True}
)

# 2. Build local document store
documents = [
    Document(page_content="func RateLimiter(ip string) bool { return limiter.Allow(ip) }", metadata={"file": "security/ratelimit.go"}),
    Document(page_content="def send_metric(name, val): statsd.increment(name, val)", metadata={"file": "telemetry/metrics.py"})
]

vector_db = Chroma.from_documents(documents, embeddings)

# 3. Retrieve relevant context for an LLM query
retriever = vector_db.as_retriever(search_kwargs={"k": 1})
matched_docs = retriever.invoke("how do we prevent DDOS attacks on our API endpoints?")

for doc in matched_docs:
    print(f"Source: {doc.metadata['file']}")
    print(f"Content: {doc.page_content}")

๐Ÿ“œ License & Citation

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

  • Non-Commercial Use: Free for open-source research, academic benchmarking, developer tooling experiments, and non-commercial projects with attribution.
  • Attribution: Please attribute Divakant Pandey and cite:
    @misc{pandey2026codeembedv2,
      author = {Divakant Pandey},
      title = {CodeEmbed v2: High-Performance Multilingual Code Embedding Model},
      year = {2026},
      publisher = {Hugging Face / GitHub},
      howpublished = {\url{https://huggingface.co/divakantpandey/code-embed-v2}}
    }
    
  • Commercial Inquiries: For commercial deployments, SaaS integration, or enterprise licenses, contact:
    • Maintainer: Divakant Pandey
    • Email: divakant01@gmail.com
    • GitHub: @divakantpandey
Downloads last month
13
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