# kushagra-1210/scifact-hybrid-retrieval architecture

> Architecture diagram of the GitHub repository kushagra-1210/scifact-hybrid-retrieval, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kushagra-1210/scifact-hybrid-retrieval
- Repository: https://github.com/kushagra-1210/scifact-hybrid-retrieval

## Overview

This is a SciFact scientific-claim retrieval system with a Streamlit demo and an offline evaluation/tuning workflow. The principal user flow loads a claim, ranks abstracts with BM25 and dense retrieval, fuses the rankings, optionally reranks the top results, and displays abstracts and scores. Offline runs also tune fusion weights on training queries and evaluate retrieval quality. The README documents plotting and error analysis as additional capabilities. Edges follow shown calls or README descriptions; the batch orchestration and plotting implementations were not sampled.

Main entry points: [`app/app.py`](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/app/app.py) (Streamlit interface), [`src/data.py`](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/data.py) (SciFact loader), [`run_tune.py`](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/run_tune.py) (Weight tuning), [`src/dense.py`](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/dense.py) (Dense retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_retrieval["Retrieval"]
  node_scifact["SciFact loader<br/>[data.py]"]
  node_bm25["BM25 retrieval<br/>[bm25.py]"]
  node_dense["Dense retrieval<br/>[dense.py]"]
  node_fusion["RRF fusion<br/>[fusion.py]"]
  node_rerank["Cross-encoder reranking<br/>[rerank.py]"]
  node_embedding_store[("Document embeddings<br/>[embeddings.npy]")]
  node_weights["Fusion weights"]
end

subgraph group_demo["Claim-search demo"]
  node_streamlit["Streamlit interface<br/>[app.py]"]
end

subgraph group_experiments["Tuning and evaluation"]
  node_tuning["Weight tuning<br/>[run_tune.py]"]
  node_runs["Run-file utilities<br/>[utils.py]"]
  node_evaluation["Retrieval metrics<br/>[evaluate.py]"]
  node_batch_eval["Ablation workflow<br/>[run_all.py]"]
end

subgraph group_analysis["Result analysis"]
  node_plots["Metric plots<br/>[plots.py]"]
  node_errors["Error analysis<br/>[errors.py]"]
  node_results[("Run and analysis outputs")]
end

node_user(("Claim-search user"))
node_models["Embedding and rerank models"]

node_user -->|"enters claim"| node_streamlit
node_streamlit -->|"loads corpus"| node_scifact
node_streamlit -->|"scores claim"| node_bm25
node_streamlit -->|"retrieves densely"| node_dense
node_streamlit -->|"fuses rankings"| node_fusion
node_streamlit -.->|"reranks optionally"| node_rerank
node_streamlit -->|"reads weights"| node_weights
node_dense -->|"reads or writes"| node_embedding_store
node_dense -->|"encodes queries"| node_models
node_rerank -->|"scores candidates"| node_models
node_bm25 -->|"uses document text"| node_scifact
node_dense -->|"uses document text"| node_scifact
node_tuning -->|"loads splits"| node_scifact
node_tuning -->|"sweeps weights"| node_fusion
node_tuning -->|"loads and saves runs"| node_runs
node_tuning -->|"writes tuned config"| node_weights
node_rerank -->|"loads query data"| node_scifact
node_rerank -->|"loads and saves runs"| node_runs
node_batch_eval -->|"evaluates runs"| node_evaluation
node_batch_eval -->|"uses run utilities"| node_runs
node_evaluation -.->|"reports metrics"| node_results
node_plots -->|"creates figures"| node_results
node_errors -->|"loads retrieval runs"| node_runs
node_errors -->|"loads judgments"| node_scifact
node_errors -->|"writes error analysis"| node_results

click node_streamlit "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/app/app.py"
click node_scifact "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/data.py"
click node_bm25 "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/bm25.py"
click node_dense "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/dense.py"
click node_fusion "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/fusion.py"
click node_rerank "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/rerank.py"
click node_embedding_store "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/artifacts/embeddings.npy"
click node_weights "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/config/fusion_weights.json"
click node_tuning "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/run_tune.py"
click node_runs "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/utils.py"
click node_evaluation "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/evaluate.py"
click node_batch_eval "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/run_all.py"
click node_plots "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/plots.py"
click node_errors "https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/errors.py"
click node_results "https://github.com/kushagra-1210/scifact-hybrid-retrieval/tree/main/results"

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_scifact,node_bm25,node_dense,node_fusion,node_rerank,node_embedding_store,node_weights,node_user toneBlue
class node_streamlit toneAmber
class node_tuning,node_runs,node_evaluation,node_batch_eval toneMint
class node_plots,node_errors,node_results toneRose
class node_models toneIndigo
```

## Components

### Retrieval

- [SciFact loader](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/data.py): `src/data.py`
- [BM25 retrieval](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/bm25.py): `src/bm25.py`
- [Dense retrieval](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/dense.py): `src/dense.py`
- [RRF fusion](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/fusion.py): `src/fusion.py`
- [Cross-encoder reranking](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/rerank.py): `src/rerank.py`
- [Document embeddings](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/artifacts/embeddings.npy): `artifacts/embeddings.npy`
- [Fusion weights](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/config/fusion_weights.json): `config/fusion_weights.json`

### Claim-search demo

- [Streamlit interface](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/app/app.py): `app/app.py`

### Tuning and evaluation

- [Weight tuning](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/run_tune.py): `run_tune.py`
- [Run-file utilities](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/utils.py): `src/utils.py`
- [Retrieval metrics](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/evaluate.py): `src/evaluate.py`
- [Ablation workflow](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/run_all.py): `src/run_all.py`

### Result analysis

- [Metric plots](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/plots.py): `src/plots.py`
- [Error analysis](https://github.com/kushagra-1210/scifact-hybrid-retrieval/blob/main/src/errors.py): `src/errors.py`
- [Run and analysis outputs](https://github.com/kushagra-1210/scifact-hybrid-retrieval/tree/main/results): `results`

### Other components

- **Claim-search user**
- **Embedding and rerank models**

## Connections

- Claim-search user → Streamlit interface: enters claim (evidence: `README.md`)
- Streamlit interface → SciFact loader: loads corpus (evidence: `app/app.py`)
- Streamlit interface → BM25 retrieval: scores claim (evidence: `app/app.py`)
- Streamlit interface → Dense retrieval: retrieves densely (evidence: `README.md`)
- Streamlit interface → RRF fusion: fuses rankings (evidence: `app/app.py`)
- Streamlit interface → Cross-encoder reranking: reranks optionally
- Streamlit interface → Fusion weights: reads weights (evidence: `app/app.py`)
- Dense retrieval → Document embeddings: reads or writes (evidence: `src/dense.py`)
- Dense retrieval → Embedding and rerank models: encodes queries (evidence: `src/dense.py`)
- Cross-encoder reranking → Embedding and rerank models: scores candidates (evidence: `src/rerank.py`)
- BM25 retrieval → SciFact loader: uses document text (evidence: `src/bm25.py`)
- Dense retrieval → SciFact loader: uses document text (evidence: `src/dense.py`)
- Weight tuning → SciFact loader: loads splits (evidence: `run_tune.py`)
- Weight tuning → RRF fusion: sweeps weights (evidence: `run_tune.py`)
- Weight tuning → Run-file utilities: loads and saves runs (evidence: `run_tune.py`)
- Weight tuning → Fusion weights: writes tuned config (evidence: `run_tune.py`)
- Cross-encoder reranking → SciFact loader: loads query data (evidence: `src/rerank.py`)
- Cross-encoder reranking → Run-file utilities: loads and saves runs (evidence: `src/rerank.py`)
- Ablation workflow → Retrieval metrics: evaluates runs (evidence: `README.md`)
- Ablation workflow → Run-file utilities: uses run utilities (evidence: `src/run_all.py`)
- Retrieval metrics → Run and analysis outputs: reports metrics
- Metric plots → Run and analysis outputs: creates figures (evidence: `README.md`)
- Error analysis → Run-file utilities: loads retrieval runs (evidence: `src/errors.py`)
- Error analysis → SciFact loader: loads judgments (evidence: `src/errors.py`)
- Error analysis → Run and analysis outputs: writes error analysis (evidence: `src/errors.py`)
