Alex Meta/prompt-ranking-lab Public

Prompt Ranking Lab - A minimal Python server with SQLite and vanilla HTML/CSS/JS for ranking prompts

1 branch
prompt-ranking-lab
README

Prompt Ranking Lab

Repository: prompt-ranking-lab | Default branch: main

A private, local browser app for learning how a small model can rank candidate prompt suggestions by context. It trains its own weights with CPU-only sparse logistic regression. It does not call an AI provider or use pretrained model weights.

The project now has two isolated experiments:

  • CodePinion context workbench: a structured simulator for the prompt cards in CodePinion's AI chat, using page, repository, workspace, active file, task/sprint, branch, changed-file, conflict, and terminal/build context. The eligibility rules only show suggestions whose required context exists; a small learned model orders them. Human-authored starter labels are demonstrations, not real CodePinion usage. Helpful/not-useful corrections are stored locally and included on the next training run.
  • MIMICS research benchmark: Microsoft's MIMICS-ClickExplore engagement labels and optional MIMICS-Manual quality ratings. This is a search-clarification domain, not CodePinion data.

Each experiment has separate training data and model weights. Nothing here reads CodePinion accounts, connects to its app, or changes CodePinion code. The CodePinion mode is an offline prototype that can help develop and evaluate a later adapter; it is not ready to deploy based on synthetic starter judgments alone.

Start the lab

Requires Python 3.10 or newer. The server, ranker, and interface use the Python standard library; there are no package installs.

cd "LLM Models/prompt-suggestion-ranker"
python3 -m promptlab

Open http://127.0.0.1:8765. Stop the server with Ctrl+C. It only binds to localhost. The application does not make remote requests or send analytics, uploaded data, or ranking requests off this computer.

Start with CodePinion-shaped examples

The Train tab includes hand-authored preference examples for realistic CodePinion contexts. Choose CodePinion starter judgments + my feedback, train, then open CodePinion context. Load a sample state or edit the fields to represent a current page, file, task, workspace, branch, changed files, conflicts, or build failure. The model ranks only eligible prompt cards. Expand a card's learned features to inspect its score, then mark suggestions useful or not useful. The next training run includes your latest correction for each context/prompt pair.

The CodePinion context schema follows the assistant's current frontend and read-only workspace-tool contract, including the PageContext page label and workspace facts such as active task, branch, dirty files, and conflicts. It deliberately doesn't accept code content, credentials, account IDs, or private chat history. Contexts are held in browser memory; only context/prompt pairs you explicitly rate are saved to local SQLite. Metrics on starter examples measure agreement with authored labels, not real-world usefulness. Collect consented, representative CodePinion feedback before treating the model as a product signal.

Get MIMICS data

The UI accepts the official tab-separated files directly. Download them from Microsoft’s MIMICS data folder, then import ClickExplore in the Train tab. Manual labels are optional and used as an independent quality check.

If the machine running the app has internet access, the project also includes a streaming downloader:

python3 scripts/fetch_mimics.py all

In this environment, outbound DNS resolution is unavailable, so the downloader cannot be exercised here. The UI upload path works without the server having network access. Raw data is stored under data/raw/ and ignored by Git. The MIMICS repository includes its data terms and citation; review them before using any research output outside this learning project.

Train and inspect the MIMICS experiment

  1. Import MIMICS-ClickExplore.tsv.
  2. Optionally import MIMICS-Manual.tsv.
  3. Select Train ranker. The trainer learns a bounded vocabulary from the training partition, makes sparse TF-IDF context/candidate features, and fits a binary logistic model using stochastic gradient descent.
  4. Read the test metrics in Data & evaluation. The split is deterministic and query-grouped, so variants of a single query cannot leak into multiple partitions.
  5. Use Free-form lab to enter a context and candidate prompts. The MIMICS model scores every candidate and orders them from highest to lowest estimated engagement.

The target for ClickExplore is whether a clarification pane received any engagement (engagement_level > 0). Scores are learned estimates, not calibrated truth. Test ranking is compared with token-overlap scoring using top-1 positive rate, nDCG@3, and pairwise accuracy. Manual question labels are also reported when available.

Memory, weights, and failure handling

  • TSV imports stream in 1,000-row batches into SQLite rather than loading the full file into RAM.
  • Training keeps examples in SQLite and uses sparse rows; the vocabulary is capped at 20,000 features and model weights use compact single-precision arrays.
  • Training runs in a background thread. The previous model stays active until a new run is validated and saved.
  • CodePinion and MIMICS models are stored and loaded separately. CodePinion preference corrections are deduplicated by context/prompt and capped at 20,000 rows.
  • The compressed JSON artifact is written to a temporary file and atomically replaced. It contains model metadata, vocabulary, IDF values, weights, and held-out metrics. JSON is used instead of pickle so loading does not execute serialized Python objects.
  • Dataset/model files are local runtime state and are ignored by Git. Use Refresh to inspect current local state.

Project structure

promptlab/       SQLite data pipeline, CodePinion context adapter, sparse feature encoder, ranker, local HTTP server
promptlab/static Browser interface
scripts/         Official MIMICS downloader
tests/           Standard-library unit and integration tests
data/raw/        Downloaded source TSVs (ignored)
data/processed/  SQLite database (ignored)
artifacts/       Separate compressed model weights for each experiment (ignored)

Sync with the CodePinion repository

The repository uses CodePinion's SSH host on port 2223. Set the remote from the project root:

git remote set-url origin ssh://git@codepinion.co.ke:2223/alexmeta517-754a34e3/prompt-ranking-lab.git

To fetch and merge the remote main branch into your current branch:

git pull --no-rebase origin main

Resolve any marked conflicts, then commit the resolution. To publish local commits:

git push -u origin main

If SSH cannot resolve codepinion.co.ke, the machine cannot reach the repository host through DNS. Restore host/network connectivity before retrying; Git credentials are not checked until the host is reachable.

Checks

python3 -m unittest discover -s tests -v

Training and public data are not included in tests. Tests use tiny in-memory TSV fixtures only to verify parsing, split integrity, sparse model training, artifact round trips, endpoint validation, and local UI delivery.

About

Prompt Ranking Lab - A minimal Python server with SQLite and vanilla HTML/CSS/JS for ranking prompts

1 branch
MIT
Updated about 12 hours ago
Contributors

Languages

Python62.3%
JavaScript15.5%
CSS11.8%
HTML10.4%

Clone

https://api.codepinion.co.ke/git/alexmeta517-754a34e3/prompt-ranking-lab.git
git clone https://api.codepinion.co.ke/git/alexmeta517-754a34e3/prompt-ranking-lab.git