PM-301b · Module 3
Dynamic Example Selection
5 min read
Static example sets fail when the input distribution is too varied for any fixed set to cover adequately. Dynamic selection solves this by choosing examples at runtime based on the incoming input — selecting the examples most similar to the current request from a larger library.
- Similarity-Based Retrieval Embed inputs and examples. At runtime, embed the incoming input and retrieve the k nearest neighbors from the example library by cosine similarity. These retrieved examples are the most semantically similar to the input — the model has seen the closest available analog to the current request.
- Category Matching Tag examples by input category. Classify the incoming input (rules-based or via a fast classifier call). Select examples from the matching category. Simpler than embedding-based retrieval, sufficient when input categories are well-defined and stable.
- Difficulty Matching Estimate input difficulty (length, ambiguity, number of constraints). Select examples of matched difficulty. Prevents the model from being anchored to easy examples when facing a complex input — or overwhelmed by complex examples when handling a simple request.
# Architecture: dynamic few-shot selection
EXAMPLE LIBRARY (stored separately):
- 50-200 curated input-output pairs
- Each tagged: category, difficulty, input_embedding
- Versioned: library_v1, library_v2, etc.
SELECTION LOGIC (at request time):
1. Embed incoming input
2. Retrieve top-3 by cosine similarity from library
3. Filter: exclude examples with same input as request (avoid circular)
4. Inject retrieved examples into prompt template
PROMPT TEMPLATE:
"Here are examples similar to your request:
[RETRIEVED EXAMPLE 1]
[RETRIEVED EXAMPLE 2]
[RETRIEVED EXAMPLE 3]
Now handle:
Input: {{USER_INPUT}}
Output:"
MONITORING:
- Log which examples are retrieved for each request
- Track quality scores by example — low-quality examples should be removed or replaced
- Re-embed library whenever examples are added or modified