DevTools Logo

Few-Shot Example Selector

Few-Shot Example Selector

Rank, diversify and pack demonstrations into a prompt budget — entirely offline.

Runs in your browser
Try an example

Task query

1 line · 33 chars

Example pool

4 pairs · jsonl

Selected examples

3/4 · ≈74 tokens
{"input":"How do I reset my password?","output":"Open Settings and choose Reset password."}
{"input":"Where can I see my invoices?","output":"Billing → Invoices lists every invoice."}
{"input":"How do I cancel my plan?","output":"Go to Billing → Plan and choose Cancel."}
#InputBM25TokensState
3How do I cancel my plan?2.314≈24selected
2Where can I see my invoices?1.634≈25selected
1How do I reset my password?1.133≈25selected
4Why was I charged twice?0.112≈32excluded

≈74 of 200 tokens used; 126 left. Estimates use the chars/4 heuristic, not a tokenizer.

Details

Paste a query and a pool of input/output pairs; the selector scores every pair with BM25 over an inverted index, normalizes relevance, applies greedy MMR diversity, and packs the winners under a token budget. Scores, matched terms and per-example estimates stay visible so you can audit why each demonstration was chosen. Everything runs locally: no embeddings, network calls or persisted prompt data.

More examples

JSONL pool

Each line becomes a candidate demonstration scored against the task query.

Separator format

Blocks separated by --- are parsed as input/output pairs when JSON is inconvenient.

Prompt block

The prompt serializer numbers examples and leaves a final query slot for the model.

Examples

JSONL pool

Input
{"input":"How do I reset my password?","output":"Open Settings and choose Reset password."}
{"input":"Where are my invoices?","output":"Billing → Invoices."}

Each line becomes a candidate demonstration scored against the task query.

Separator format

Input
Summarize the release
Short summary text
---
Translate the welcome email
Translated email text

Blocks separated by --- are parsed as input/output pairs when JSON is inconvenient.

Prompt block

Input
Example 1:
Input: How do I reset my password?
Output: Open Settings and choose Reset password.

Input: <your query>
Output:

The prompt serializer numbers examples and leaves a final query slot for the model.

About this tool

Paste a query and a pool of input/output pairs; the selector scores every pair with BM25 over an inverted index, normalizes relevance, applies greedy MMR diversity, and packs the winners under a token budget. Scores, matched terms and per-example estimates stay visible so you can audit why each demonstration was chosen. Everything runs locally: no embeddings, network calls or persisted prompt data.

What this tool does not do

  • Processes only the inputs provided in this session without connecting to external accounts or background servers.
  • Runs entirely in the current browser tab; nothing is synced across devices or backed up to a server.

How to use this tool

  1. Paste candidate example pairs

    Provide input/output demonstrations as JSONL or --- separated blocks.

  2. Enter query, MMR, and token cap

    Tune diversity vs BM25 relevance and set your maximum prompt token budget.

  3. Copy packed shots

    Export selected demonstrations as formatted prompt text or JSONL.

Use cases

JSONL pool

Each line becomes a candidate demonstration scored against the task query.

Separator format

Blocks separated by --- are parsed as input/output pairs when JSON is inconvenient.

Prompt block

The prompt serializer numbers examples and leaves a final query slot for the model.

Common mistakes

Mistake:What does the MMR (Maximal Marginal Relevance) slider control?

Fix:Pure relevance can pick three nearly identical examples; MMR penalizes candidates that overlap heavily with already-selected shots, balancing query relevance against coverage diversity.

Mistake:How accurate is the token budget cap?

Fix:Packing uses a fast deterministic character-to-token heuristic so you stay comfortably within prompt budgets offline; leave a small margin if your target model uses dense non-Latin scripts.

Frequently asked questions

How does BM25 select few-shot examples without calling an embedding API?

It tokenizes your candidate pool into an in-memory inverted index and scores term overlap weighted by inverse document frequency and length normalization, finding lexically similar demonstrations in milliseconds.

What does the MMR (Maximal Marginal Relevance) slider control?

Pure relevance can pick three nearly identical examples; MMR penalizes candidates that overlap heavily with already-selected shots, balancing query relevance against coverage diversity.

How accurate is the token budget cap?

Packing uses a fast deterministic character-to-token heuristic so you stay comfortably within prompt budgets offline; leave a small margin if your target model uses dense non-Latin scripts.

Are my prompt pools uploaded or cached on a server?

No. Indexing, ranking, and JSONL/prompt formatting run locally in your browser.