id stringlengths 16 16 | repo stringclasses 85
values | repo_url stringclasses 85
values | path stringlengths 3 233 | content_hash stringlengths 16 16 | num_chars int64 0 66.1M | content stringlengths 0 66.1M |
|---|---|---|---|---|---|---|
cc16fa1d0111ca56 | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/strings/substitute.cc | cc16fa1d0111ca56 | 6,744 | // Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agr... |
34f2142ddaec427c | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/strings/substitute_test.cc | 34f2142ddaec427c | 11,616 | // Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agr... |
a9427fa0cc223bc1 | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/strings/internal/str_split_internal.h | a9427fa0cc223bc1 | 19,786 | // Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agr... |
e6df7d8bdc626bc8 | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/debugging/stacktrace.cc | e6df7d8bdc626bc8 | 7,843 | // Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agr... |
2fcb667b8968a95a | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/debugging/stacktrace.h | 2fcb667b8968a95a | 11,404 | // Copyright 2018 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agr... |
3d226e5166e8d78c | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/strings/escaping.cc | 3d226e5166e8d78c | 50,069 | // Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agr... |
cf8024c07c6445a2 | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/container/internal/raw_hash_set.cc | cf8024c07c6445a2 | 104,233 | "// Copyright 2018 The Abseil Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \(...TRUNCATED) |
d4afd213964e303b | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/container/internal/raw_hash_set.h | d4afd213964e303b | 168,149 | "// Copyright 2018 The Abseil Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \(...TRUNCATED) |
556de3b9008986f3 | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/container/internal/raw_hash_set_test.cc | 556de3b9008986f3 | 171,656 | "// Copyright 2018 The Abseil Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \(...TRUNCATED) |
ff37748b4666bb00 | abseil-cpp | https://github.com/abseil/abseil-cpp.git | absl/status/internal/status_internal.h | ff37748b4666bb00 | 5,775 | "// Copyright 2019 The Abseil Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \(...TRUNCATED) |
Co-Change Code Retrieval
A repository-level code retrieval dataset built from what real developers actually do together. Positives are labeled by co-change — files that engineers repeatedly modified in the same commits — not by imports, folder co-location, or any other structural proxy. Every training row ships with 128 hard + 128 easy negatives, where hard negatives are mined in the embedding space of a strong open model (Qwen3-Embedding-4B) and filtered through an eight-signal banned-negative rule so the model is never punished for a real relationship.
Phase 1 (this release) ships the code → code branch: query a file, retrieve related files. Phase 2 (in progress) will add the text → code branch: query a natural-language search phrase, retrieve the files a developer would open.
TL;DR
- 101 repositories, 8 languages, ~26 domain categories, hand-picked from mature open-source projects.
- Split by repo (85 train / 16 test) — a whole repository goes to train or test, so no file appears on both sides.
- Positives from co-change graphs. A pair is a positive only if the two files were changed together in ≥ 2 filtered commits.
- Negatives are safety-checked. 128 hard negatives mined with Qwen3-Embedding-4B; 128 easy random negatives. An 8-signal banned-negative filter strips any candidate that shares a real relationship with the query.
- Corpus lives once. Each unique file is stored a single time, keyed by content hash — rows point at IDs, so there is zero content duplication across queries or splits.
- Parquet on the Hub; ready to stream via
datasets.load_dataset.
Quick start
from datasets import load_dataset
# Rows: one training example per query file.
rows = load_dataset("aysinghal/cochange-code-retrieval", "rows_code")
print(rows["train"][0])
# {
# "query": "b81f0c...", # corpus id of the query file
# "query_type": "code",
# "positives": ["a91f...", "c02d...", ...], # co-change neighbours
# "positive_weights": [7, 4, 3, ...], # times each pair co-changed
# "hard_negatives": ["7f...", ...], # 128 mined confusables
# "easy_negatives": ["1c...", ...], # 128 random unrelated files
# "group_key": "django", # repo — drives the leakage-safe split
# "query_path": "django/db/models/query.py",
# }
# Corpus: id -> file content lookup, shared across splits and phases.
corpus = load_dataset("aysinghal/cochange-code-retrieval", "corpus")
print(corpus["corpus"][0])
# {"id": "b81f0c...", "repo": "django", "path": "django/db/models/query.py",
# "content_hash": "b81f0c...", "num_chars": 12483, "content": "from ... "}
At training time, resolve query / positives / hard_negatives / easy_negatives against the corpus to get file text.
Why this dataset exists
Most public code-retrieval datasets label relevance with imports (or file co-location, or docstring proximity). Imports are a narrow, leaky, language-specific proxy for "these files are related." Same-folder heuristics for hard negatives are worse — they routinely mark true collaborators as wrong answers, so the model gets penalized for correctly noticing a real relationship. Both failure modes bake bias into every model trained on them.
This dataset takes a different definition of relevance:
Two files are related if developers repeatedly changed them together.
Git history is the ground truth. It captures relationships imports can't see — a config and the code that reads it, a test and the thing it tests, a data schema and the migration that touches it, two files that always ship together for the same feature. It is also language-agnostic: Python, Java, JS/TS, Go, C/C++, Ruby, PHP, and C# repos all yield co-change edges the same way.
Every design choice below traces back to that premise: derive positives from co-change, protect them with a banned-negative filter, and let a strong open embedding model surface the actually confusing look-alikes.
How the dataset is built
The pipeline runs one repo at a time — clone → filter → graph → corpus → rows → mine negatives → push — and never keeps the whole dataset resident locally.
1. Filter commits. Walk each repo's history and keep only focused, honest commits. Drop merges, bot authors, mega-commits (> 10 files or > 1000 lines), version bumps, pure-docs / pure-data commits, and machine-noise (lockfiles, build artifacts).
2. Build the co-change graph. Nodes are files; an edge means "changed together in a kept commit," with weight = number of times. A pair is a positive only if it co-changed at least twice — the 1 → 2 jump is where signal separates from coincidence. All edges are stored, so downstream stages can weight positives by co-change frequency.
3. Drop hub files (safely). Bookkeeping files that ride along with almost every commit — changelogs, pyproject.toml, CMakeLists.txt, doc indexes — produce false relatedness. We drop a file only when it is both non-code and connected to a big share of the repo (either wide by degree or deep by max edge weight). Real code is never dropped, however central. The dropped set is recorded and reused by the corpus.
4. Build the corpus. Every kept file is stored exactly once, keyed by a 64-bit content hash. Identical files collapse across commits and across repositories automatically. Rows reference corpus IDs, not raw text, so there is zero duplication in the training rows themselves.
5. Emit code → code rows. Walk the graph. For each file above the co-change threshold: query = that file's corpus id; positives = its co-change neighbours (also above the threshold); positive_weights = per-neighbour co-change counts, sorted strongest first.
6. Mine hard negatives. For every row, encode the query and every candidate file with Qwen/Qwen3-Embedding-4B, chunk files into overlapping 1024-token windows (128-token overlap), aggregate similarity with max-over-chunks, and take the top-K nearest that survive the banned-negative filter (below). Then top up with 128 uniformly-random files from the repo as easy negatives.
7. Split by repo. Deterministic sha1(repo_name) % 100 < 20 → test. A whole repo lands in exactly one split, so no file can appear on both sides.
8. Export & push. JSONL → parquet, one file per repo per split, uploaded per-repo so the whole dataset never has to live on one machine at once.
The banned-negative filter
Hard-negative mining is only safe if the mining process can never label a real positive as a negative. The 8-signal filter below runs on every mined candidate; the candidate is discarded (never used as a negative) if any signal fires. None of these signals ever create a positive — they only protect candidates from being punished.
| Signal | Rule |
|---|---|
| co-change | The candidate shares a co-change edge with the query. |
| import | Query imports the candidate, or the candidate imports the query. |
| path reference | One file writes the other's path or filename as a string. |
| test-of | test_foo.py ↔ foo.py-style pair. |
| same issue | Both files' commits reference the same #123 issue tag. |
| inheritance | One file's class extends or implements a class in the other. |
| content Jaccard | Line-level Jaccard ≥ 0.8 (renames, vendored copies, near-duplicates). |
| doc stem | Doc ↔ code pair by shared basename stem (encoder.md ↔ encoders.py). |
Positives themselves stay co-change-only. These extra checks are a one-way safety net.
Data files on the Hub
data/
├── corpus/
│ ├── django.parquet
│ ├── react.parquet
│ └── ... (one per repo)
├── rows_code_train/
│ ├── django.parquet
│ └── ... (85 repos)
└── rows_code_test/
├── react.parquet
└── ... (16 repos)
corpus/is split-agnostic. Every row across every split resolves its IDs here.rows_code_{train,test}/are the code → code training rows.rows_text_{train,test}/will appear when Phase 2 lands — the loader below already anticipates the folder.
Phase 2 will not rewrite the corpus. The parquet in data/corpus/ is the frozen source of truth for every corpus ID; text-branch rows will point at the same IDs.
Schemas
corpus
| Column | Type | Description |
|---|---|---|
id |
string | 16-hex-char content hash (64 bits). Unique across the whole dataset. |
repo |
string | Repo the file was first seen in. Same content in two repos → still one row (repo is one of them). |
path |
string | Path of the representative version of this file within its repo. |
content_hash |
string | Same as id. Kept as a separate column for readability. |
num_chars |
int64 | Byte count of content, precomputed for length-based filtering. |
content |
string | The full UTF-8 file text. |
rows_code (both train and test)
| Column | Type | Description |
|---|---|---|
query |
string | Corpus ID of the query file. |
query_type |
string | "code". Phase 2 will add "text" rows to a separate folder. |
positives |
list<string> | Corpus IDs of co-change neighbours, sorted strongest first. |
positive_weights |
list<int64> | Number of times each (query, positive) pair co-changed. |
hard_negatives |
list<string> | 128 IDs mined with Qwen3-Embedding-4B, filtered through the banned-negative rule. Fewer than 128 if the repo did not have enough safe candidates. |
easy_negatives |
list<string> | 128 randomly-sampled unrelated files from the same repo. |
group_key |
string | Repo name. Use this as the group when doing leakage-safe cross-validation within the train split. |
query_path |
string | Path of the query file, for debugging / eyeballing. Not intended as a training feature. |
Coverage
Languages (by primary language of each source repo): Python (heavy), Java, JavaScript / TypeScript, Go, C / C++, Ruby, PHP, C#.
Domains (~26): Web Frameworks (backend), Frontend Frameworks, HTTP Clients, Networking / RPC, Databases & ORMs, ML / AI, Data Processing, Scientific Computing, CLI & TUI, Testing Frameworks, DevOps & Orchestration, Workflow / Pipeline Orchestration, Linters / Formatters / Type Checkers, Package Management & Build Tools, Async & Concurrency, Data Visualization, Validation & Serialization, Scraping / Browser Automation, Security & Cryptography, Documentation Generators, Templating, Graph & Network Analysis, Image Processing, Streaming / Messaging, Utility & Core Libraries, Language Interop.
Split composition (85 train / 16 test):
- Test repos —
abseil-cpp,aspnetcore,black,cobra,folly,grpc-go,laravel,marshmallow,paramiko,prefect,prometheus,react,svelte,sympy,typescript,vitest. - All other 85 repos → train.
The split is deterministic on repo name (SHA-1 mod 100 < 20 → test), so re-running the pipeline reproduces the same partition without a manifest.
Positive/negative philosophy — the one-page version
- Positive edge ⇔ the two files co-changed ≥ 2 times in filtered commits.
- Positives are ordered by co-change weight; downstream trainers can sample proportional to weight if they want a soft-confidence signal.
- 128 hard negatives per row, mined with Qwen3-Embedding-4B in its own embedding space. This is the same family of model the dataset is designed to fine-tune, so the hard negatives are exactly the confusables the model actually mistakes.
- 128 easy negatives per row, sampled uniformly from unrelated files in the same repo. Easy negatives keep the loss surface from collapsing when everything is hard.
- Every hard negative candidate is checked against the 8-signal banned-negative filter above; if any signal fires the candidate is discarded and never used as a negative.
Intended use
- Training / fine-tuning code embedding models for file-level retrieval in code assistants, IDE agents, and RAG-over-code pipelines.
- Reranker training (
(query, positive)vs(query, hard_negative)). - Ablations on what "relatedness" means for code — imports vs co-change vs hybrid.
- Repository-level evaluation of retrievers with a leakage-safe held-out split.
External benchmarks are the yardstick. This dataset ships a train/test split for internal hygiene (loss curves, overfitting checks). Headline numbers should come from public benchmarks — CoIR, SWE-bench-style retrieval slices, RepoEval — not from the internal test split.
What isn't in here (yet)
- Text → code rows. Phase 2 will add natural-language queries generated by an LLM from each kept commit (diff + message). The rows will live in
data/rows_text_{train,test}/, share the same corpus, and reuse the same banned-negative filter. See "Roadmap" below. - Cross-repo negatives. All negatives are drawn from within the query's own repo; a candidate can never be another repo's file. This keeps the retrieval task well-defined per repo.
- PR / issue metadata columns. The banned-negative filter uses same-issue signals internally, but the resulting rows do not expose the raw issue / PR IDs. Ask if you need them exposed.
Roadmap
- Phase 2 — text → code. LLM-generated search phrases from kept commits (diff + message) as queries, files touched by the commit as positives. Reuses corpus, banned-negative filter, and repo-level split unchanged. Target loader:
load_dataset("aysinghal/cochange-code-retrieval", "rows_text") - Repo expansion. Additional domains where co-change edges are especially informative (databases internals, compilers, kernels).
- Cross-repo hard negatives as an optional column, for retrievers that want to model in-repo vs out-of-repo separation explicitly.
- Row-count balancing. Cap or downsample rows so a giant repo (
pytorch,kubernetes) can't dominate the loss.
Known limitations
- Co-change is a noisy label. Two files touched together for unrelated reasons in a small commit will look positive; the ≥ 2 threshold + hub-file drop + banned-negative filter mitigate but do not eliminate this.
- Repo skew. Train has 85 repos and test has 16; the exact row-count distribution is heavy-tailed because large repos produce many more graph nodes. Weight or cap during training if this matters for your evaluation.
- Language coverage is deliberate but not exhaustive. Rust, Kotlin, Scala, Zig, and functional-first languages are not represented. The pipeline is language-agnostic — adding them is a matter of extending
clone_repos.py. - Hard negatives are model-specific. They were mined in
Qwen/Qwen3-Embedding-4B's embedding space. Confusables for a very different model family (e.g. a small BERT retriever) may be different; the easy negatives, positives, and corpus all stay valid for any model.
Citation
If you use this dataset, please cite the source repositories (all under permissive licenses) and this dataset. A stable citation entry will be added when the accompanying write-up lands.
@misc{singhal_cochange_2026,
title = {Co-Change Code Retrieval: a repository-level dataset for code embedding models},
author = {Singhal, Ayush},
year = {2026},
howpublished = {\url{https://huggingface.co/datasets/aysinghal/cochange-code-retrieval}},
}
License
Released under Apache 2.0. Each source repository retains its own license; file contents in the corpus are excerpted from those repositories and are used consistently with each project's license terms. If your project appears in this dataset and you'd like it removed, please open an issue on the dataset repository and it will be dropped in the next revision.
- Downloads last month
- 1