# dj-22/csd358-hackathon architecture

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

- Interactive diagram: https://gitdiagram.com/dj-22/csd358-hackathon
- Repository: https://github.com/dj-22/csd358-hackathon

## Overview

BridgeHop is a multi-hop retrieval system for HotpotQA paragraphs. Its principal workflow parses a question, retrieves first-hop documents, derives and ranks bridge entities (or comparison slots), searches a second hop, scores reasoning chains, and returns ranked documents with a trace. The graph also preserves the documented single-shot, pseudo-relevance-feedback, sparse/dense, and result-fusion capabilities. Pipeline calls are visible in `agent/pipeline.py`; other relationships rely on README statements. Unread source is represented only where documented, so some internal wiring is omitted.

Main entry points: [`demo.py`](https://github.com/dj-22/csd358-hackathon/blob/main/demo.py) (Demo interface), [`agent/parser.py`](https://github.com/dj-22/csd358-hackathon/blob/main/agent/parser.py) (Question parser), [`agent/bridge.py`](https://github.com/dj-22/csd358-hackathon/blob/main/agent/bridge.py) (Bridge candidates), [`agent/hop2.py`](https://github.com/dj-22/csd358-hackathon/blob/main/agent/hop2.py) (Second-hop retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Question entry"]
  node_demo["Demo interface<br/>[demo.py]"]
  node_results["Ranked results and trace<br/>[demo.py]"]
end

subgraph group_index["Index and retrieval"]
  node_indexbuild["Index builder<br/>[build_index.py]"]
  node_indexstore[("Positional index<br/>[inverted_index.py]")]
  node_boolean["Boolean retrieval<br/>[boolean.py]"]
  node_bm25["BM25 retrieval<br/>[bm25.py]"]
  node_cosine["Cosine retrieval<br/>[cosine.py]"]
  node_prf["Pseudo-feedback<br/>[prf.py]"]
  node_embed["Dense embeddings<br/>[embed.py]"]
end

subgraph group_agent["Multi-hop reasoning"]
  node_parser["Question parser<br/>[parser.py]"]
  node_state["Research state<br/>[state.py]"]
  node_bridge["Bridge candidates<br/>[bridge.py]"]
  node_entities["Entity linking<br/>[entities.py]"]
  node_ranker["Learned bridge ranker<br/>[bridge_ranker.py]"]
  node_features["Ranker features<br/>[features.py]"]
  node_hop2["Second-hop retrieval<br/>[hop2.py]"]
end

subgraph group_ranking["Ranking and output"]
  node_chains["Chain scoring<br/>[chains.py]"]
  node_fusion["List fusion<br/>[fusion.py]"]
end

subgraph group_infra["Resources"]
  node_resources["Loaded resources<br/>[resources.py]"]
end

node_user(("Questioner"))
node_encoder["MiniLM encoder"]

node_user -->|"asks"| node_demo
node_demo -->|"runs system"| node_parser
node_parser -->|"initializes"| node_state
node_parser -->|"analyzes terms"| node_indexstore
node_indexbuild -->|"builds"| node_indexstore
node_parser -->|"filters hop one"| node_boolean
node_parser -->|"retrieves hop one"| node_bm25
node_parser -->|"scores baseline"| node_cosine
node_demo -->|"optionally expands"| node_prf
node_demo -->|"selects bridges"| node_bridge
node_bridge -.->|"uses linked entities"| node_entities
node_bridge -->|"optionally ranks"| node_ranker
node_ranker -.->|"scores features"| node_features
node_demo -->|"retrieves second hop"| node_hop2
node_hop2 -->|"uses sparse scoring"| node_bm25
node_hop2 -->|"uses dense scoring"| node_embed
node_embed -->|"encodes text"| node_encoder
node_demo -->|"scores chains"| node_chains
node_chains -.->|"supports list fusion"| node_fusion
node_demo -->|"loads resources"| node_resources
node_resources -.->|"provides index"| node_indexstore
node_demo -->|"returns and traces"| node_results

click node_demo "https://github.com/dj-22/csd358-hackathon/blob/main/demo.py"
click node_parser "https://github.com/dj-22/csd358-hackathon/blob/main/agent/parser.py"
click node_state "https://github.com/dj-22/csd358-hackathon/blob/main/agent/state.py"
click node_indexbuild "https://github.com/dj-22/csd358-hackathon/blob/main/index/build_index.py"
click node_indexstore "https://github.com/dj-22/csd358-hackathon/blob/main/index/inverted_index.py"
click node_boolean "https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/boolean.py"
click node_bm25 "https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/bm25.py"
click node_cosine "https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/cosine.py"
click node_prf "https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/prf.py"
click node_bridge "https://github.com/dj-22/csd358-hackathon/blob/main/agent/bridge.py"
click node_entities "https://github.com/dj-22/csd358-hackathon/blob/main/agent/entities.py"
click node_ranker "https://github.com/dj-22/csd358-hackathon/blob/main/agent/bridge_ranker.py"
click node_features "https://github.com/dj-22/csd358-hackathon/blob/main/agent/features.py"
click node_hop2 "https://github.com/dj-22/csd358-hackathon/blob/main/agent/hop2.py"
click node_chains "https://github.com/dj-22/csd358-hackathon/blob/main/agent/chains.py"
click node_fusion "https://github.com/dj-22/csd358-hackathon/blob/main/agent/fusion.py"
click node_resources "https://github.com/dj-22/csd358-hackathon/blob/main/agent/resources.py"
click node_embed "https://github.com/dj-22/csd358-hackathon/blob/main/index/embed.py"
click node_results "https://github.com/dj-22/csd358-hackathon/blob/main/demo.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_demo,node_results toneBlue
class node_indexbuild,node_indexstore,node_boolean,node_bm25,node_cosine,node_prf,node_embed toneAmber
class node_parser,node_state,node_bridge,node_entities,node_ranker,node_features,node_hop2 toneMint
class node_chains,node_fusion toneRose
class node_resources,node_user,node_encoder toneIndigo
```

## Components

### Question entry

- [Demo interface](https://github.com/dj-22/csd358-hackathon/blob/main/demo.py): `demo.py`
- [Ranked results and trace](https://github.com/dj-22/csd358-hackathon/blob/main/demo.py): `demo.py`

### Index and retrieval

- [Index builder](https://github.com/dj-22/csd358-hackathon/blob/main/index/build_index.py): `index/build_index.py`
- [Positional index](https://github.com/dj-22/csd358-hackathon/blob/main/index/inverted_index.py): `index/inverted_index.py`
- [Boolean retrieval](https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/boolean.py): `retrieval/boolean.py`
- [BM25 retrieval](https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/bm25.py): `retrieval/bm25.py`
- [Cosine retrieval](https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/cosine.py): `retrieval/cosine.py`
- [Pseudo-feedback](https://github.com/dj-22/csd358-hackathon/blob/main/retrieval/prf.py): `retrieval/prf.py`
- [Dense embeddings](https://github.com/dj-22/csd358-hackathon/blob/main/index/embed.py): `index/embed.py`

### Multi-hop reasoning

- [Question parser](https://github.com/dj-22/csd358-hackathon/blob/main/agent/parser.py): `agent/parser.py`
- [Research state](https://github.com/dj-22/csd358-hackathon/blob/main/agent/state.py): `agent/state.py`
- [Bridge candidates](https://github.com/dj-22/csd358-hackathon/blob/main/agent/bridge.py): `agent/bridge.py`
- [Entity linking](https://github.com/dj-22/csd358-hackathon/blob/main/agent/entities.py): `agent/entities.py`
- [Learned bridge ranker](https://github.com/dj-22/csd358-hackathon/blob/main/agent/bridge_ranker.py): `agent/bridge_ranker.py`
- [Ranker features](https://github.com/dj-22/csd358-hackathon/blob/main/agent/features.py): `agent/features.py`
- [Second-hop retrieval](https://github.com/dj-22/csd358-hackathon/blob/main/agent/hop2.py): `agent/hop2.py`

### Ranking and output

- [Chain scoring](https://github.com/dj-22/csd358-hackathon/blob/main/agent/chains.py): `agent/chains.py`
- [List fusion](https://github.com/dj-22/csd358-hackathon/blob/main/agent/fusion.py): `agent/fusion.py`

### Resources

- [Loaded resources](https://github.com/dj-22/csd358-hackathon/blob/main/agent/resources.py): `agent/resources.py`

### Other components

- **Questioner**
- **MiniLM encoder**

## Connections

- Questioner → Demo interface: asks (evidence: `demo.py`)
- Demo interface → Question parser: runs system
- Question parser → Research state: initializes (evidence: `agent/pipeline.py`)
- Question parser → Positional index: analyzes terms (evidence: `README.md`)
- Index builder → Positional index: builds (evidence: `README.md`)
- Question parser → Boolean retrieval: filters hop one (evidence: `README.md`)
- Question parser → BM25 retrieval: retrieves hop one (evidence: `agent/pipeline.py`)
- Question parser → Cosine retrieval: scores baseline (evidence: `agent/pipeline.py`)
- Demo interface → Pseudo-feedback: optionally expands
- Demo interface → Bridge candidates: selects bridges
- Bridge candidates → Entity linking: uses linked entities
- Bridge candidates → Learned bridge ranker: optionally ranks (evidence: `agent/pipeline.py`)
- Learned bridge ranker → Ranker features: scores features
- Demo interface → Second-hop retrieval: retrieves second hop (evidence: `demo.py`)
- Second-hop retrieval → BM25 retrieval: uses sparse scoring (evidence: `README.md`)
- Second-hop retrieval → Dense embeddings: uses dense scoring (evidence: `README.md`)
- Dense embeddings → MiniLM encoder: encodes text (evidence: `index/embed.py`)
- Demo interface → Chain scoring: scores chains
- Chain scoring → List fusion: supports list fusion
- Demo interface → Loaded resources: loads resources (evidence: `demo.py`)
- Loaded resources → Positional index: provides index
- Demo interface → Ranked results and trace: returns and traces (evidence: `README.md`)
