Software Heritage
Software Heritage is a non-profit, long-term archive built specifically for software source code. It collects, preserves, and makes publicly available code from across the software world, and crucially it keeps not just the latest snapshot of a project but its full development history, so you can see how a codebase changed commit by commit. Marking a decade of operation, the archive holds over 27 billion unique source files and has been recognised as a digital public good by the Digital Public Goods Alliance.
The underlying model is a giant graph: repositories, directories, files, and revisions, each file carrying an intrinsic identifier (a SWHID) derived from cryptographic hashes, so any artefact can be referenced permanently and verified. You can explore it through the web interface, which acts as a "wayback machine" for source code, or programmatically through the public REST API and the graph and vault services that let you retrieve directories and full histories. For large-scale work, a full graph export is available rather than crawling the API file by file.
For RAG, this is a strong foundation for code-aware retrieval: building a system that answers questions about how something is implemented, tracing a function across versions, or assembling a corpus of real-world code and commit messages to ground a coding assistant. Its breadth and its emphasis on history are hard to match anywhere else.
The big caveat is licensing, and it is not a small one. Software Heritage's own infrastructure is open source, but the code it preserves keeps whatever licence its original authors set, and those vary from one file to the next, from permissive to strongly copyleft to no licence at all. Archiving is not the same as a grant of reuse rights, so you must check the licence on individual files before redistributing or training on them. If you would rather have that filtering done for you, this is the upstream source for The Stack v2, which selects only permissively licensed code and is the more practical starting point for most model training.
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.
Stack Exchange Data Dump
Periodic XML dumps of every site in the Stack Exchange network, including Stack Overflow. Each dump holds questions, answers, comments, votes, and user profiles. One of the richest question-and-answer datasets you can freely download, and a natural fit for building technical support and developer RAG systems.