# pavankumarmanagoli/biomedical-rag architecture

> Architecture diagram of the GitHub repository pavankumarmanagoli/biomedical-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pavankumarmanagoli/biomedical-rag
- Repository: https://github.com/pavankumarmanagoli/biomedical-rag

## Overview

Biomedical-RAG automates SPM terminology expansion, literature collection, semantic search, evidence-grounded Q&A, interaction extraction, and knowledge-graph loading. Its principal user workflow is a question in the Streamlit chat, followed by FAISS retrieval and a Mistral answer with supporting sources. The broader documented pipeline also includes PubChem synonym expansion and PubMed/PMC collection, which feed indexing and downstream interaction analysis. Edges use sampled source excerpts or README statements; unsampled connections are omitted where their implementation cannot be verified.

Main entry points: [`rag_app/extract_interactions.py`](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/extract_interactions.py) (Interaction Extractor), [`rag_app/app.py`](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/app.py) (RAG Chat), [`get_pubchem_synonyms.py`](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubchem_synonyms.py) (Synonym Expansion), [`get_pubmed_data.py`](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubmed_data.py) (Paper Collection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_literature["Literature Collection"]
  node_spm_curator["SPM Catalog"]
  node_synonym_expansion["Synonym Expansion"]
  node_pubmed_collection["Paper Collection<br/>[get_pubmed_data.py]"]
  node_mongo_papers[("MongoDB Papers")]
end

subgraph group_rag["Retrieval and QA"]
  node_index_builder["Index Builder"]
  node_doc_formatter["Document Formatter<br/>[utils.py]"]
  node_vector_index[("FAISS Index")]
  node_chat_ui["RAG Chat<br/>[app.py]"]
  node_embedding_model["Embedding Model"]
  node_mistral_qa["Mistral QA"]
end

subgraph group_extract["Interaction Analysis"]
  node_interaction_extractor["Interaction Extractor"]
  node_interaction_store[("MongoDB Interactions")]
end

subgraph group_graph["Knowledge Graph"]
  node_neo4j_loader["Graph Loader<br/>[neo4j_load.py]"]
  node_neo4j[("Neo4j")]
end

node_pubchem(("PubChem"))
node_pubmed(("PubMed / PMC"))
node_chat_user(("Researcher"))

node_spm_curator -->|"provides catalog"| node_synonym_expansion
node_synonym_expansion -->|"fetches synonyms"| node_pubchem
node_synonym_expansion -->|"expands terms"| node_pubmed_collection
node_pubmed_collection -->|"retrieves papers"| node_pubmed
node_pubmed_collection -->|"stores papers"| node_mongo_papers
node_mongo_papers -->|"reads papers"| node_index_builder
node_index_builder -->|"formats documents"| node_doc_formatter
node_index_builder -->|"builds index"| node_vector_index
node_chat_user -->|"asks question"| node_chat_ui
node_chat_ui -->|"embeds query"| node_embedding_model
node_chat_ui -->|"searches chunks"| node_vector_index
node_chat_ui -->|"requests answer"| node_mistral_qa
node_interaction_extractor -->|"retrieves context"| node_vector_index
node_interaction_extractor -->|"embeds SPM"| node_embedding_model
node_interaction_extractor -->|"extracts relations"| node_mistral_qa
node_interaction_extractor -->|"upserts evidence"| node_interaction_store
node_mongo_papers -->|"reads papers"| node_neo4j_loader
node_interaction_store -->|"reads interactions"| node_neo4j_loader
node_neo4j_loader -->|"loads graph"| node_neo4j

click node_spm_curator "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubchem_synonyms.py"
click node_synonym_expansion "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubchem_synonyms.py"
click node_pubmed_collection "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubmed_data.py"
click node_index_builder "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/build_index_mongo_chunks.py"
click node_doc_formatter "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/utils.py"
click node_chat_ui "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/app.py"
click node_interaction_extractor "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/extract_interactions.py"
click node_neo4j_loader "https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/neo4j_load.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spm_curator,node_synonym_expansion,node_pubmed_collection,node_mongo_papers toneBlue
class node_index_builder,node_doc_formatter,node_vector_index,node_chat_ui,node_embedding_model,node_mistral_qa toneAmber
class node_interaction_extractor,node_interaction_store toneMint
class node_neo4j_loader,node_neo4j toneRose
class node_pubchem,node_pubmed,node_chat_user toneIndigo
```

## Components

### Literature Collection

- [SPM Catalog](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubchem_synonyms.py): `get_pubchem_synonyms.py`
- [Synonym Expansion](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubchem_synonyms.py): `get_pubchem_synonyms.py`
- [Paper Collection](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/get_pubmed_data.py): `get_pubmed_data.py`
- **MongoDB Papers**

### Retrieval and QA

- [Index Builder](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/build_index_mongo_chunks.py): `rag_app/build_index_mongo_chunks.py`
- [Document Formatter](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/utils.py): `rag_app/utils.py`
- **FAISS Index**
- [RAG Chat](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/app.py): `rag_app/app.py`
- **Embedding Model**
- **Mistral QA**

### Interaction Analysis

- [Interaction Extractor](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/extract_interactions.py): `rag_app/extract_interactions.py`
- **MongoDB Interactions**

### Knowledge Graph

- [Graph Loader](https://github.com/pavankumarmanagoli/biomedical-rag/blob/main/rag_app/neo4j_load.py): `rag_app/neo4j_load.py`
- **Neo4j**

### Other components

- **PubChem**
- **PubMed / PMC**
- **Researcher**

## Connections

- SPM Catalog → Synonym Expansion: provides catalog (evidence: `README.md`)
- Synonym Expansion → PubChem: fetches synonyms (evidence: `get_pubchem_synonyms.py`)
- Synonym Expansion → Paper Collection: expands terms (evidence: `README.md`)
- Paper Collection → PubMed / PMC: retrieves papers (evidence: `get_pubmed_data.py`)
- Paper Collection → MongoDB Papers: stores papers (evidence: `get_pubmed_data.py`)
- MongoDB Papers → Index Builder: reads papers (evidence: `README.md`)
- Index Builder → Document Formatter: formats documents (evidence: `rag_app/build_index_mongo_chunks.py`)
- Index Builder → FAISS Index: builds index (evidence: `rag_app/build_index_mongo_chunks.py`)
- Researcher → RAG Chat: asks question (evidence: `rag_app/app.py`)
- RAG Chat → Embedding Model: embeds query (evidence: `rag_app/app.py`)
- RAG Chat → FAISS Index: searches chunks (evidence: `rag_app/app.py`)
- RAG Chat → Mistral QA: requests answer (evidence: `rag_app/app.py`)
- Interaction Extractor → FAISS Index: retrieves context (evidence: `rag_app/extract_interactions.py`)
- Interaction Extractor → Embedding Model: embeds SPM (evidence: `rag_app/extract_interactions.py`)
- Interaction Extractor → Mistral QA: extracts relations (evidence: `rag_app/extract_interactions.py`)
- Interaction Extractor → MongoDB Interactions: upserts evidence (evidence: `rag_app/extract_interactions.py`)
- MongoDB Papers → Graph Loader: reads papers (evidence: `rag_app/neo4j_load.py`)
- MongoDB Interactions → Graph Loader: reads interactions (evidence: `rag_app/neo4j_load.py`)
- Graph Loader → Neo4j: loads graph (evidence: `rag_app/neo4j_load.py`)
