| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Natural language queries using GenAI systems are known to generate hallucinations of facts and may not be able to provide evidence for explanations. For use in biomedical research, GenAI must provide valid and well-grounded results. Therefore, a biomedical system that generates results based on factual biomedical knowledge and publications are needed.
BioGraphRAG bridges biomedical data and publication knowledge graphs with GraphRAG, based upon the G-retriever architecture, to enhance and ensure that the natural language responses are generated from only information from the knowledge sources.
We tackle biomedical question answering by pairing graph-native retrieval with neural reasoning. For every question, we retrieve a targeted slice of our knowledge graphs and pass that evidence to a graph-aware neural reader.
Given a question $Q_i$, we seek an answer set $A_i \subseteq V$ from a large graph $G=(V,E)$. Our pipeline formalizes subgraph retrieval as a Prize-Collecting Steiner Tree (PCST) optimization, then conditions a GNN+LLM reader on the retrieved subgraph. This design reduces hallucinations by grounding in the graph, while scaling beyond a single-context window for dense biomedical domains via structured retrieval, aligning with the GraphRAG patterns described in the NVIDIA technical blog and the G-Retriever paper.
Goal: Implement a system to use GNNs + LLM to integrate knowledge graphs made from large public datasets with literature to turn a free-text biomedical question into a grounded answer with biomedical information and PMIDs / experiment IDs.
Our knowledge graph stores heterogeneous biomedical entities such as drugs, diseases, genes, and proteins, alongside richly typed relationships. Ingestion enforces schema-level guarantees (label-specific uniqueness, referential integrity) and attaches text embeddings to every node. We maintain both semantic indexes (vector similarity) and structural indexes (label/property) so that questions can be seeded semantically while traversals stay performant. Production graphs live in Amazon Neptune with supporting artifacts in Amazon S3, and configuration defaults are kept in configs/default.yaml with loaders under src/ingest/.
Incoming questions are embedded with our text encoder. We identify the top-matching nodes via cosine similarity, then expand their one-hop neighborhoods inside Neptune using IAM-signed openCypher queries that enforce namespace prefixes and degree caps. The result is a base subgraph that balances recall against the combinatorial growth typical in dense biomedical graphs.
Within the base subgraph we assign a "prize" score to nodes and edges based on three cues: semantic similarity to the question, membership in the original seed set, and curated edge semantics. Traversal costs discourage overly large subgraphs. We then run a prize-collecting Steiner tree procedure that returns a compact, connected subgraph with high total prize. This pruning stage preserves multi-hop evidence while keeping the context manageable for downstream models.
The pruned subgraph passes through a PyTorch Geometric GATv1 encoder to produce node representations that capture multi-hop structure and textual attributes. We serialize the subgraph into an ordered, human-readable description (node names, descriptions, relation types) and feed it—alongside the question and a soft prompt derived from the GNN outputs—into an instruction-tuned large language model. The LLM remains frozen so we benefit from its language fluency while the GNN-derived prompt focuses attention on graph evidence.
Supervision uses tuples of question, answer nodes, and source subgraphs. Training optimizes two losses jointly: a node-level loss that encourages the model to rank true answers above distractors, and a generation loss that compels the LLM to produce grounded natural-language answers conditioned on the serialized subgraph and soft prompt.
At inference we return the generated answer together with the top-ranked answer nodes extracted from the subgraph. When recall is critical, we append additional high-prize nodes from the pruned subgraph, effectively ensembling the retrieval and reasoning stages.
Retrieval and pruning logic resides in src/retrieval/g_retriever.py and src/retrieval/expand.py, while the graph-aware reader and reranking pipeline are implemented in src/gnn/pyg_rag.py and orchestrated via src/rag/pipeline.py. Neptune remains the source of truth for production graphs, with strict schema validation and uniqueness checks during ingest. Neptune loaders live in src/ingest/. Configuration, seeds, and embedding utilities are centralized in configs/default.yaml, src/utils/seed.py, and src/embeddings/ respectively.
We run with fixed random seeds, log every relevant hyperparameter, and evaluate on multi-hop biomedical QA benchmarks using metrics such as hits at K, recall, and mean reciprocal rank. Sensitivity analyses cover the number of retrieved seeds, expansion depth, prize schedules, and pruning strength, echoing the coupled hyperparameter behavior observed in GraphRAG literature.
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
# Generate embeddings and seed vector store
make embed
# Run an end-to-end demo
make qaexport BIO_KG_vector_store__backend=faiss
make embed
make qaDownload PrimeKG extracts into data/local/primekg/exports/ using the filenames referenced in configs/ingest_prime.yaml.
Place PubMedKG exports under data/local/pubmedkg/exports/ or point the config to an S3 prefix.
Convert raw files into Neptune-friendly CSVs:
make prime_to_neptune
make pkg_to_neptuneUpload the generated CSVs to S3 and trigger Neptune bulk loads via make load_prime / make load_pkg.
docker build -t biographrag-api -f infra/docker/Dockerfile.api.
docker build -t biographrag-ui -f infra/docker/Dockerfile.ui.The system is designed to run fully on AWS with Amazon Neptune (openCypher), Amazon OpenSearch for vector retrieval, and S3 for graph CSVs. For production, supply endpoints and credentials via environment variables (preferred) or update configs/default.yaml and override with env.
GET /health → { "status": "ok" }
POST /qa → run retrieval + PyG fusion + LLM; body:
{ "question": "Which PrimeKG findings highlight EGFR involvement in colon cancer?" }Response includes the grounded answer, prompt, nodes, edges, and evidence hits.
These are not bundled with the repository and must be provided at deploy time.
MIT License. See LICENSE for the full text.
If you use BioGraphRAG in published work, please cite the NVIDIA GraphRAG blog and G-Retriever paper listed above.
| Back | FazBrowse Home | New Git URL |