The Stack v1 / v2
A newer edition is available: The Stack v2.
The Stack is BigCode's open dataset of source code. Version 1 collects files scraped from GitHub and keeps only those under permissive licences such as MIT, Apache, and BSD, with duplicate and near-duplicate files removed so you are not storing the same snippet many times over. Version 2 is a large step up in scale: it draws from Software Heritage, a long-term public archive of code, and spans more than 600 programming languages.
Both versions live on HuggingFace as Parquet files. A practical difference to plan for: v1 includes the file contents directly, whereas v2's main tables hold metadata and pointers, and you fetch the actual code blobs from Software Heritage's S3 bucket. So for a quick start v1 is simpler to stream with the `datasets` library, while v2 rewards a bit more pipeline setup in exchange for far broader coverage.
For RAG, The Stack is a strong retrieval corpus for code assistants, letting you index real-world implementations across many languages, and it is also the pretraining data behind code models such as StarCoder. Because every file is tracked back to its repository licence, it is a much safer starting point than a raw GitHub scrape when you care about the terms attached to the code you index and ship.
The caveats are mostly about provenance and consent. Filtering is by repository licence, so the collection permits commercial use in principle, but individual files keep their own permissive terms, several of which still require you to preserve attribution notices in any redistributed code. BigCode also honours an opt-out: developers can ask for their code to be excluded, so a given snapshot is not a complete mirror of public code.
If you want the discussion around code rather than the code itself, GH Archive covers issues and pull requests, while Stack Exchange covers question-and-answer threads; The Stack is the piece that gives you the source files.
Related sources
DevDocs
An open-source aggregator that pulls API documentation for major programming languages, frameworks, and tools into one searchable place. A tidy RAG source when you want up-to-date developer reference material without scraping dozens of separate documentation sites yourself.
GitHub Public Repositories (GH Archive / GHTorrent)
Two projects that capture public GitHub activity for analysis. GH Archive records the public GitHub event timeline as downloadable hourly archives, and GHTorrent offers a queryable mirror of GitHub metadata. Together they help you mine code, issues, pull requests, and documentation at scale.
RefineCode (OpenCoder)
A reproducible code pretraining corpus of roughly 960 billion tokens spanning about 607 programming languages, built with a published cleaning pipeline. It is the pretraining data behind the OpenCoder code models.
Software Heritage
A non-profit universal archive built specifically for software source code, preserving not just files but their full development history. Over 27 billion unique source files collected from public repositories, each identified by a cryptographic hash. The upstream source for The Stack v2.