Daniel Roxas
Fix Cypher query bug, remove duplicate section, add model links
5930045 verified
---
license: cc-by-4.0
task_categories:
- question-answering
- text-retrieval
language:
- en
tags:
- biomedical
- pubmed
- knowledge-graph
- graphrag
- neo4j
- faiss
- embeddings
size_categories:
- 10M<n<100M
pretty_name: PubMed GraphRAG
---
# 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
```python
from huggingface_hub import snapshot_download
# Download all CSVs
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
```bash
# Stop Neo4j
sudo systemctl stop neo4j
# Import (adjust paths as needed)
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
# Fix permissions and start
sudo chown -R neo4j:neo4j /var/lib/neo4j/data
sudo systemctl start neo4j
```
### Step 3: Create indexes
```cypher
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
```python
from huggingface_hub import snapshot_download
# Download MedCPT embeddings (recommended for biomedical)
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
```python
import numpy as np
import faiss
from pathlib import Path
from tqdm import tqdm
# Configuration
NPZ_DIR = Path("./pubmed-data/medcpt")
OUTPUT_DIR = Path("./faiss_index")
OUTPUT_DIR.mkdir(exist_ok=True)
NLIST = 4096 # Number of clusters
M = 96 # Subquantizers (768/96 = 8 dims each)
NBITS = 8 # Bits per code
TRAIN_SIZE = 500000
# Get all NPZ files
npz_files = sorted(NPZ_DIR.glob("embeddings_*.npz"))
print(f"Found {len(npz_files)} embedding files")
# Step 1: Sample vectors for training
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}")
# Step 2: Create and train index
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
# Step 3: Add all 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())
# Step 4: Save
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
```python
import numpy as np
data = np.load("medcpt/embeddings_000000.npz")
print(data["embeddings"].shape) # (50000, 768)
print(data["pmids"].shape) # (50000,)
```
## 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
| Model | HuggingFace | Dimensions | Recommended For |
|-------|-------------|------------|-----------------|
| MedCPT | [`ncbi/MedCPT-Article-Encoder`](https://huggingface.co/ncbi/MedCPT-Article-Encoder) | 768 | Medical literature search |
| BiCA | [`bisectgroup/BiCA-base`](https://huggingface.co/bisectgroup/BiCA-base) | 768 | Biomedical contrastive learning |
| MedTE | [`MohammadKhodadad/MedTE`](https://huggingface.co/MohammadKhodadad/MedTE) | 768 | Medical text embeddings |
## Sample Neo4j Queries
### Find genes associated with Alzheimer's disease
```cypher
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
```cypher
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
```cypher
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
```cypher
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
| Source | Description | Link |
|--------|-------------|------|
| **PubMed** | 12.5M biomedical abstracts (2000-2024) | [pubmed.ncbi.nlm.nih.gov](https://pubmed.ncbi.nlm.nih.gov/) |
| **PubTator3** | Pre-extracted entities & relationships | [ncbi.nlm.nih.gov/research/pubtator3](https://www.ncbi.nlm.nih.gov/research/pubtator3/) |
| **NCBI Gene** | Gene symbols and metadata | [ncbi.nlm.nih.gov/gene](https://www.ncbi.nlm.nih.gov/gene/) |
| **MeSH** | Medical Subject Headings (diseases, chemicals) | [meshb.nlm.nih.gov](https://meshb.nlm.nih.gov/) |
| **NCBI Taxonomy** | Species classification | [ncbi.nlm.nih.gov/taxonomy](https://www.ncbi.nlm.nih.gov/taxonomy) |
| **Cellosaurus** | Cell line database | [cellosaurus.org](https://www.cellosaurus.org/) |
| **dbSNP** | Mutation/variant identifiers | [ncbi.nlm.nih.gov/snp](https://www.ncbi.nlm.nih.gov/snp/) |
## Citation
```bibtex
@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:
- [PubMed](https://pubmed.ncbi.nlm.nih.gov/) abstracts (NLM/NCBI)
- [PubTator3](https://www.ncbi.nlm.nih.gov/research/pubtator3/) annotations (NCBI)
- [MeSH](https://meshb.nlm.nih.gov/) descriptors (NLM)
- [NCBI Gene](https://www.ncbi.nlm.nih.gov/gene/) and [Taxonomy](https://www.ncbi.nlm.nih.gov/taxonomy) databases
Released under [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/) for academic research purposes.
## Acknowledgments
- [National Center for Biotechnology Information (NCBI)](https://www.ncbi.nlm.nih.gov/)
- [National Library of Medicine (NLM)](https://www.nlm.nih.gov/)
- [Meta AI - FAISS](https://github.com/facebookresearch/faiss)
- [Neo4j](https://neo4j.com/)