How kaustubhas/biorag works
Purpose and entry points
Biomedical Assistant is a Python RAG application for disease/symptom questions over a structured biomedical dataset. Primary launch routing is main.py, selecting CLI or Streamlit UI. UI launchers invoke Streamlit through app/run_ui.py or root run_ui.py; interactive CLI behavior resides in app/cli.py.
Data ingestion and preprocessing
Raw disease-to-symptom records originate in data/dataset.csv. The optional scalable preprocessing stage in pipeline/spark_processor.py cleans CSV data and writes Parquet to data/processed/data.parquet; Spark write failures on Windows fall back to Pandas/PyArrow. Runtime loaders prefer processed Parquet and otherwise consume CSV, creating a clear raw-versus-preprocessed data boundary.
Knowledge graph construction
knowledge_graph/data_processor.py normalizes loaded data into disease and symptom entities. knowledge_graph/graph_builder.py constructs the in-memory NetworkX disease–symptom graph, while knowledge_graph/build_knowledge_graph.py coordinates graph-building work. The graph is the retrieval substrate for entity lookup, neighborhood search, graph statistics, and visualization.
Retrieval and query interpretation
The RAG orchestration boundary is rag/biomedical_rag.py, which combines graph access, query interpretation, and answer generation. rag/query_processor.py performs direct, fuzzy, and optional semantic matching using sentence-transformer/PyTorch capabilities. If those dependencies fail or are unavailable, rag/query_processor_simple.py provides compatible text-based retrieval, preserving application operation without the ML runtime.
Response generation and fallbacks
rag/response_generator.py turns retrieved graph context into an answer. Its primary external inference dependency is a locally running Ollama service with the llama3.2 model. When Ollama is unavailable, generation degrades to rule-based and text-matching responses rather than failing the request. This separates deterministic retrieval from optional generative enrichment.
User-facing application layer
app/streamlit_app.py provides the stateful Streamlit experience: graph exploration, search/filtering, Q&A, history, and data-source status. app/cli.py exposes the same system through a terminal workflow. The application layer should consume the graph/RAG interfaces rather than directly duplicating preprocessing or matching logic.
Optional integrations and operational dependencies
Core runtime is Python 3.8+, with Pandas, NetworkX, Plotly, and Streamlit. PySpark is optional for preprocessing; Sentence Transformers and PyTorch are optional for semantic retrieval. Neo4j integration is isolated in knowledge_graph/neo4j_builder.py, indicating a potential persistent graph backend distinct from the default in-memory NetworkX path. Shared configuration is centralized in config.py.
Main entry points: biomedical_rag.py Biomedical RAG · streamlit_app.py Streamlit application · spark_processor.py Optional preprocessing · data_processor.py Entity normalization
Components 18
Entry points
- Launch router · Selects CLI or Streamlit mode.
main.py - Shared configuration
config.py
Data pipeline
- Raw disease dataset
data/dataset.csv - Optional preprocessing · Cleans CSV and writes Parquet, with a Windows fallback.
pipeline/spark_processor.py - Processed dataset
data/processed/data.parquet
Knowledge graph
- Entity normalization · Loads preferred Parquet or fallback CSV into disease and symptom entities.
knowledge_graph/data_processor.py - NetworkX graph builder · Builds the in-memory disease–symptom graph.
knowledge_graph/graph_builder.py - Graph build coordinator
knowledge_graph/build_knowledge_graph.py - Disease–symptom graph · Supports lookup, neighborhood search, statistics, and visualization.
- Optional Neo4j backend · Alternative persistent graph path.
knowledge_graph/neo4j_builder.py
RAG runtime
- Biomedical RAG · Combines graph access, query interpretation, and answer generation.
rag/biomedical_rag.py - Semantic query processor · Uses direct, fuzzy, and optional semantic matching.
rag/query_processor.py - Text retrieval fallback · Compatible retrieval without the ML runtime.
rag/query_processor_simple.py - Response generator · Falls back to rule-based responses when Ollama is unavailable.
rag/response_generator.py - Ollama llama3.2 · Optional generative enrichment.
User interfaces
- Streamlit application · Provides graph exploration, Q&A, history, and data status.
app/streamlit_app.py - Interactive CLI
app/cli.py - UI launchers
app/run_ui.py
Connections 21
- Launch router → Interactive CLI: CLI mode
- Launch router → UI launchers: UI mode
- UI launchers → Streamlit application: launches
- Shared configuration → Optional preprocessing: configures
- Shared configuration → Biomedical RAG: configures
- Raw disease dataset → Optional preprocessing: clean input
- Optional preprocessing → Processed dataset: writes
- Processed dataset → Entity normalization: preferred input
- Raw disease dataset → Entity normalization: fallback input
- Entity normalization → NetworkX graph builder: normalized entities
- Graph build coordinator → NetworkX graph builder: coordinates
- NetworkX graph builder → Disease–symptom graph: builds
- Graph build coordinator → Optional Neo4j backend: optional backend path
- Biomedical RAG → Disease–symptom graph: retrieves context
- Biomedical RAG → Semantic query processor: interprets query
- Semantic query processor → Text retrieval fallback: ML unavailable
- Biomedical RAG → Response generator: generates answer
- Response generator → Ollama llama3.2: optional inference
- Streamlit application → Biomedical RAG: Q&A and search
- Streamlit application → Disease–symptom graph: explores
- Interactive CLI → Biomedical RAG: terminal queries