PubMed-GraphRAG Dataset
A large-scale biomedical knowledge graph dataset for Graph-based Retrieval-Augmented Generation (GraphRAG).
Dataset Overview
| Component |
Size |
Description |
| Papers |
12.5M |
PubMed abstracts (2000-2024) with title, abstract, DOI |
| Entities |
7.5M |
Genes, Diseases, Chemicals, Species, Mutations, Cell Lines |
| Relationships |
266M+ |
MENTIONED_IN, TREAT, ASSOCIATE, CAUSE, INHIBIT, etc. |
| Embeddings |
12.5M vectors |
MedCPT, BiCA, MedTE (768-dim) |
Dataset Structure
pubmed-graphrag-data/
βββ graph_ready/ # Papers & major MENTIONED_IN relationships
β βββ papers.csv # 12.5M papers (pmid, title, abstract, year, doi)
β βββ mentioned_in_gene.csv # Gene-Paper relationships
β βββ mentioned_in_disease.csv # Disease-Paper relationships
β βββ mentioned_in_chemical.csv # Chemical-Paper relationships
β βββ entity_relations.csv # Entity-Entity semantic relationships
β βββ complete_papers_with_metadata.jsonl # Full data in JSONL format
β
βββ neo4j_csv/ # Entity definitions & additional relationships
β βββ gene_entities.csv # 3.8M genes (entity_id, mention)
β βββ disease_entities.csv # 12K diseases
β βββ chemical_entities.csv # 120K chemicals
β βββ species_entities.csv # 359K species
β βββ mutation_entities.csv # 3.2M mutations
β βββ cellline_entities.csv # 63K cell lines
β βββ mentioned_in_species.csv # Species-Paper relationships
β βββ mentioned_in_mutation.csv # Mutation-Paper relationships
β βββ mentioned_in_cellline.csv # CellLine-Paper relationships
β βββ rel_*.csv # 32 semantic relationship files (TREAT, CAUSE, etc.)
β
βββ medcpt/ # MedCPT embeddings (recommended)
β βββ embeddings_000000.npz # Each NPZ contains 'embeddings' and 'pmids' arrays
β βββ ...
β βββ embeddings_000251.npz
β
βββ bica_base/ # BiCA embeddings
β βββ embeddings_*.npz
β
βββ medte/ # MedTE embeddings
βββ embeddings_*.npz
Quick Start: Building the Knowledge Graph
Prerequisites
- Neo4j 5.x (Community Edition works)
- Python 3.8+
- ~50GB disk space
- 16GB+ RAM recommended
Step 1: Download all CSV files
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="dannyroxas/pubmed-graphrag-data",
repo_type="dataset",
local_dir="./pubmed-data",
allow_patterns=["graph_ready/*.csv", "neo4j_csv/*.csv"]
)
Step 2: Import to Neo4j
sudo systemctl stop neo4j
cd ./pubmed-data
sudo neo4j-admin database import full \
--nodes=Paper="graph_ready/papers.csv" \
--nodes=Gene="neo4j_csv/gene_entities.csv" \
--nodes=Disease="neo4j_csv/disease_entities.csv" \
--nodes=Chemical="neo4j_csv/chemical_entities.csv" \
--nodes=Species="neo4j_csv/species_entities.csv" \
--nodes=Mutation="neo4j_csv/mutation_entities.csv" \
--nodes=CellLine="neo4j_csv/cellline_entities.csv" \
--relationships=MENTIONED_IN="graph_ready/mentioned_in_gene.csv" \
--relationships=MENTIONED_IN="graph_ready/mentioned_in_disease.csv" \
--relationships=MENTIONED_IN="graph_ready/mentioned_in_chemical.csv" \
--relationships=MENTIONED_IN="neo4j_csv/mentioned_in_species.csv" \
--relationships=MENTIONED_IN="neo4j_csv/mentioned_in_mutation.csv" \
--relationships=MENTIONED_IN="neo4j_csv/mentioned_in_cellline.csv" \
--relationships=ASSOCIATE="neo4j_csv/rel_*_ASSOCIATE.csv" \
--relationships=TREAT="neo4j_csv/rel_*_TREAT.csv" \
--relationships=CAUSE="neo4j_csv/rel_*_CAUSE.csv" \
--relationships=INHIBIT="neo4j_csv/rel_*_INHIBIT.csv" \
--relationships=STIMULATE="neo4j_csv/rel_*_STIMULATE.csv" \
--relationships=INTERACT="neo4j_csv/rel_*_INTERACT.csv" \
--relationships=POSITIVE_CORRELATE="neo4j_csv/rel_*_POSITIVE_CORRELATE.csv" \
--relationships=NEGATIVE_CORRELATE="neo4j_csv/rel_*_NEGATIVE_CORRELATE.csv" \
--relationships=COTREAT="neo4j_csv/rel_*_COTREAT.csv" \
--relationships=COMPARE="neo4j_csv/rel_*_COMPARE.csv" \
--relationships=PREVENT="neo4j_csv/rel_*_PREVENT.csv" \
--relationships=DRUG_INTERACT="neo4j_csv/rel_*_DRUG_INTERACT.csv" \
--skip-bad-relationships \
--skip-duplicate-nodes \
neo4j
sudo chown -R neo4j:neo4j /var/lib/neo4j/data
sudo systemctl start neo4j
Step 3: Create indexes
CREATE INDEX paper_pmid FOR (p:Paper) ON (p.pmid);
CREATE INDEX gene_mention FOR (g:Gene) ON (g.mention);
CREATE INDEX gene_id FOR (g:Gene) ON (g.entity_id);
CREATE INDEX disease_mention FOR (d:Disease) ON (d.mention);
CREATE INDEX chemical_mention FOR (c:Chemical) ON (c.mention);
CREATE INDEX species_mention FOR (s:Species) ON (s.mention);
CREATE INDEX mutation_mention FOR (m:Mutation) ON (m.mention);
Quick Start: Building FAISS Index
Step 1: Download embeddings
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="dannyroxas/pubmed-graphrag-data",
repo_type="dataset",
local_dir="./pubmed-data",
allow_patterns="medcpt/*.npz"
)
Step 2: Build IVF-PQ index
import numpy as np
import faiss
from pathlib import Path
from tqdm import tqdm
NPZ_DIR = Path("./pubmed-data/medcpt")
OUTPUT_DIR = Path("./faiss_index")
OUTPUT_DIR.mkdir(exist_ok=True)
NLIST = 4096
M = 96
NBITS = 8
TRAIN_SIZE = 500000
npz_files = sorted(NPZ_DIR.glob("embeddings_*.npz"))
print(f"Found {len(npz_files)} embedding files")
print("Sampling vectors for training...")
train_vectors = []
for npz_file in tqdm(npz_files[:50], desc="Sampling"):
data = np.load(npz_file)
emb = data["embeddings"].astype(np.float32)
idx = np.random.choice(len(emb), min(10000, len(emb)), replace=False)
train_vectors.append(emb[idx])
train_vectors = np.vstack(train_vectors)[:TRAIN_SIZE]
faiss.normalize_L2(train_vectors)
dim = train_vectors.shape[1]
print(f"Training set: {len(train_vectors):,} vectors, dim={dim}")
print("Training IVF-PQ index...")
quantizer = faiss.IndexFlatIP(dim)
index = faiss.IndexIVFPQ(quantizer, dim, NLIST, M, NBITS, faiss.METRIC_INNER_PRODUCT)
index.train(train_vectors)
index.nprobe = 128
del train_vectors
print("Adding all vectors...")
all_pmids = []
for npz_file in tqdm(npz_files, desc="Adding"):
data = np.load(npz_file)
emb = data["embeddings"].astype(np.float32)
pmids = data["pmids"]
faiss.normalize_L2(emb)
index.add(emb)
all_pmids.extend(pmids.tolist())
print("Saving index...")
faiss.write_index(index, str(OUTPUT_DIR / "index.faiss"))
np.save(OUTPUT_DIR / "pmids.npy", np.array(all_pmids))
print(f"\nDone!")
print(f" Index: {index.ntotal:,} vectors")
print(f" Size: ~{index.ntotal * M / 1e9:.1f} GB (compressed)")
NPZ File Format
Each .npz file contains:
embeddings: numpy array of shape (N, 768) - float32 vectors
pmids: numpy array of shape (N,) - corresponding PubMed IDs
import numpy as np
data = np.load("medcpt/embeddings_000000.npz")
print(data["embeddings"].shape)
print(data["pmids"].shape)
Entity Types
| Type |
Count |
ID Format |
Example |
| Gene |
3.8M |
NCBI Gene ID |
348 (APOE) |
| Disease |
12K |
MeSH ID |
MESH:D000544 (Alzheimer Disease) |
| Chemical |
120K |
MeSH ID |
MESH:D001241 (Aspirin) |
| Species |
359K |
NCBI Taxonomy |
9606 (Homo sapiens) |
| Mutation |
3.2M |
dbSNP/HGVS |
rs121912438 |
| Cell Line |
63K |
Cellosaurus |
CVCL_0030 |
Relationship Types
| Type |
Count |
Example |
| MENTIONED_IN |
248M |
(Gene)-[:MENTIONED_IN]->(Paper) |
| ASSOCIATE |
9.2M |
(Gene)-[:ASSOCIATE]->(Disease) |
| TREAT |
3.1M |
(Chemical)-[:TREAT]->(Disease) |
| POSITIVE_CORRELATE |
1.8M |
(Chemical)-[:POSITIVE_CORRELATE]->(Gene) |
| NEGATIVE_CORRELATE |
1.8M |
(Chemical)-[:NEGATIVE_CORRELATE]->(Gene) |
| CAUSE |
1.3M |
(Mutation)-[:CAUSE]->(Disease) |
| STIMULATE |
388K |
(Chemical)-[:STIMULATE]->(Gene) |
| INHIBIT |
307K |
(Chemical)-[:INHIBIT]->(Gene) |
| COTREAT |
237K |
(Chemical)-[:COTREAT]->(Chemical) |
| COMPARE |
208K |
(Chemical)-[:COMPARE]->(Chemical) |
| INTERACT |
123K |
(Gene)-[:INTERACT]->(Gene) |
| PREVENT |
~5K |
(Mutation)-[:PREVENT]->(Disease) |
Embedding Models
Sample Neo4j Queries
Find genes associated with Alzheimer's disease
MATCH (d:Disease)-[:ASSOCIATE]-(g:Gene)
WHERE d.mention CONTAINS "Alzheimer"
RETURN g.mention AS gene, g.entity_id AS ncbi_id
LIMIT 20
Find drugs that treat diabetes
MATCH (c:Chemical)-[:TREAT]->(d:Disease)
WHERE d.mention CONTAINS "Diabetes"
RETURN c.mention AS drug, count(*) AS evidence_count
ORDER BY evidence_count DESC
LIMIT 10
Multi-hop: Find genes related to drugs treating a disease
MATCH (c:Chemical)-[:TREAT]->(d:Disease)
WHERE d.mention CONTAINS "Breast"
MATCH (c)-[r:ASSOCIATE|INHIBIT|STIMULATE]-(g:Gene)
RETURN DISTINCT g.mention AS gene, c.mention AS drug, type(r) AS relationship
LIMIT 25
Find papers discussing a specific gene
MATCH (g:Gene {mention: "BRCA1"})-[:MENTIONED_IN]->(p:Paper)
RETURN p.pmid, p.title, p.year
ORDER BY p.year DESC
LIMIT 10
Data Sources
Citation
@dataset{pubmed_graphrag_2025,
author = {Roxas, Danny},
title = {PubMed-GraphRAG: A Large-scale Biomedical Knowledge Graph Dataset},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/datasets/dannyroxas/pubmed-graphrag-data}}
}
License
This dataset is derived from publicly available biomedical databases:
Released under CC-BY-4.0 for academic research purposes.
Acknowledgments