# promiseom/expansion-model architecture

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

- Interactive diagram: https://gitdiagram.com/promiseom/expansion-model
- Repository: https://github.com/promiseom/expansion-model

## Overview

This repository provides a query-expansion API: a client supplies a query, the Flask endpoint asks the expansion model for candidate terms, and the endpoint refines those terms before returning an expanded query (or the original query if expansion fails). The model’s sampled code retrieves Wikipedia material and uses asynchronous tasks to gather related-page data; the included WordNet and Google-search modules are distinct capabilities, but their connection to the API workflow is not established by the excerpts. Some model internals are omitted, so only evidenced relationships are shown.

Main entry points: [`qe_model.py`](https://github.com/promiseom/expansion-model/blob/master/qe_model.py) (Expansion model), [`wsgi.py`](https://github.com/promiseom/expansion-model/blob/master/wsgi.py) (Expansion endpoint), [`prd_retrieval.py`](https://github.com/promiseom/expansion-model/blob/master/prd_retrieval.py) (Wikipedia retrieval), [`custom_search.py`](https://github.com/promiseom/expansion-model/blob/master/custom_search.py) (Google custom search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API layer"]
  node_flask_api["Expansion endpoint<br/>[wsgi.py]"]
end

subgraph group_expansion["Expansion workflow"]
  node_model["Expansion model<br/>[qe_model.py]"]
  node_selector["Term refinement<br/>[term_selector.py]"]
  node_async_tasks["Async task manager<br/>[asynctask.py]"]
  node_logger["Run logging<br/>[messagelogger.py]"]
end

subgraph group_retrieval["Search and retrieval"]
  node_wiki_search["Wikipedia retrieval<br/>[prd_retrieval.py]"]
  node_google_search["Google custom search<br/>[custom_search.py]"]
end

subgraph group_support["Supporting modules"]
  node_wordnet["WordNet expansion"]
  node_wiki_links["Wiki link extractor"]
end

node_client(("API client"))
node_wikipedia(("Wikipedia API"))
node_google_service(("Google search service"))

node_client -->|"requests expansion"| node_flask_api
node_flask_api -->|"gets candidates"| node_model
node_flask_api -->|"refines terms"| node_selector
node_model -->|"runs tasks"| node_async_tasks
node_model -->|"logs progress"| node_logger
node_model -->|"cleans extracts"| node_wiki_search
node_model -->|"requests pages"| node_wikipedia
node_wiki_search -->|"searches articles"| node_wikipedia
node_google_search -->|"searches web"| node_google_service

click node_flask_api "https://github.com/promiseom/expansion-model/blob/master/wsgi.py"
click node_model "https://github.com/promiseom/expansion-model/blob/master/qe_model.py"
click node_selector "https://github.com/promiseom/expansion-model/blob/master/term_selector.py"
click node_async_tasks "https://github.com/promiseom/expansion-model/blob/master/asynctask.py"
click node_logger "https://github.com/promiseom/expansion-model/blob/master/messagelogger.py"
click node_wiki_search "https://github.com/promiseom/expansion-model/blob/master/prd_retrieval.py"
click node_google_search "https://github.com/promiseom/expansion-model/blob/master/custom_search.py"
click node_wordnet "https://github.com/promiseom/expansion-model/blob/master/wordnet_query_expansion.py"
click node_wiki_links "https://github.com/promiseom/expansion-model/blob/master/wiki_term_retrieval.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_flask_api,node_client toneBlue
class node_model,node_selector,node_async_tasks,node_logger toneAmber
class node_wiki_search,node_google_search,node_wikipedia toneMint
class node_wordnet,node_wiki_links toneRose
class node_google_service toneIndigo
```

## Components

### API layer

- [Expansion endpoint](https://github.com/promiseom/expansion-model/blob/master/wsgi.py): `wsgi.py`

### Expansion workflow

- [Expansion model](https://github.com/promiseom/expansion-model/blob/master/qe_model.py): `qe_model.py`
- [Term refinement](https://github.com/promiseom/expansion-model/blob/master/term_selector.py): `term_selector.py`
- [Async task manager](https://github.com/promiseom/expansion-model/blob/master/asynctask.py): `asynctask.py`
- [Run logging](https://github.com/promiseom/expansion-model/blob/master/messagelogger.py): `messagelogger.py`

### Search and retrieval

- [Wikipedia retrieval](https://github.com/promiseom/expansion-model/blob/master/prd_retrieval.py): `prd_retrieval.py`
- [Google custom search](https://github.com/promiseom/expansion-model/blob/master/custom_search.py): `custom_search.py`

### Supporting modules

- [WordNet expansion](https://github.com/promiseom/expansion-model/blob/master/wordnet_query_expansion.py): `wordnet_query_expansion.py`
- [Wiki link extractor](https://github.com/promiseom/expansion-model/blob/master/wiki_term_retrieval.py): `wiki_term_retrieval.py`

### Other components

- **API client**
- **Wikipedia API**
- **Google search service**

## Connections

- API client → Expansion endpoint: requests expansion (evidence: `wsgi.py`)
- Expansion endpoint → Expansion model: gets candidates (evidence: `wsgi.py`)
- Expansion endpoint → Term refinement: refines terms (evidence: `wsgi.py`)
- Expansion model → Async task manager: runs tasks (evidence: `qe_model.py`)
- Expansion model → Run logging: logs progress (evidence: `qe_model.py`)
- Expansion model → Wikipedia retrieval: cleans extracts (evidence: `qe_model.py`)
- Expansion model → Wikipedia API: requests pages (evidence: `qe_model.py`)
- Wikipedia retrieval → Wikipedia API: searches articles (evidence: `prd_retrieval.py`)
- Google custom search → Google search service: searches web (evidence: `custom_search.py`)
