Research log Small Model Experimentation
GitHub

Qwen3.5-4B Verified Algorithm Retrieval Adaptation

Reusing solved code rescues a few stuck problems

The one idea you need

A programmer keeps a cookbook of solutions that provably worked on past problems. Stuck on a new one, they pull the closest-matching entry and tweak it to fit. Here a small coding model does exactly that with a library of its own verified solutions.

The question

When a small coding model keeps failing certain problems, does handing it a similar problem it already solved and letting it adapt that code help it finally pass?

What we found

Yes, but modestly. Fetching the most similar already-solved problem and adapting its code cracked 3 of the 8 problems that repeated tries kept missing, lifting overall success from 67% to 79%. Matching by meaning clearly beat fetching random code (rescued none) and mislabeled code (rescued one). But only 2 wins truly needed smart matching, and most adaptations that passed the shown tests still failed the hidden ones.

Why it matters

When a small model plateaus, a searchable library of its own verified solutions plus adaptation is a cheap way to claw back a few failures. But pair it with a stronger checker: thin public tests wave wrong answers through.

Problems solved, before to after adding retrieval67% → 79%of 24 new coding tasks
Stuck problems rescued by meaning-matched code3 of 8none rescued by random code
Wins that truly needed smart matching2 of 3one was also fixed by blind copy-and-rename
Adaptations that looked right but were wrongabout 4 in 7passed shown tests yet failed hidden ones, best variant
On this page
  1. Results at a glance
  2. Overview
  3. Report
    1. Question
    2. Setup
    3. Retrieval-Only Results
    4. Combined With Direct Sampling
    5. Recovered Tasks
    6. Gate Readout
    7. Interpretation
  4. Experiment log
  5. Figures
  6. Data files
  7. Reproduce
  8. Related

Results at a glance 3

Share of problems solved: trying harder alone vs adding matched solutions

How to read

Five bars, each a different pool of candidate solutions; bar height is the share of 24 new problems solved, so taller is better. The leftmost is trying many times alone; the rest add retrieved solutions of differing relevance.

0%20%40%60%80%direct sampling onlydirect sampling only66.7%+ copy/rename retrieval+ copy/rename retrieval70.8%+ semantic retrieval+ semantic retrieval79.2%+ random retrieval+ random retrieval66.7%+ shuffled retrieval+ shuffled retrieval70.8%

Takeaway → The meaning-matched bar rises highest, 67% to 79%, while the random-retrieval bar stays flat at 67%, so the content of the retrieved solution, not just having one, does the work.

Data table
candidate poolcoverage (24 held-out tasks)
direct sampling only66.7%
+ copy/rename retrieval70.8%
+ semantic retrieval79.2%
+ random retrieval66.7%
+ shuffled retrieval70.8%

Numbers from reports/report_summary.json (combined)

Technical framing

Held-out coverage: direct sampling alone vs plus retrieval adaptation — Adapting semantically retrieved verified algorithms lifts coverage from 66.7% to 79.2%; random retrieval adds nothing.

Stuck problems newly cracked by each type of retrieved solution

How to read

Four bars, one per type of retrieved solution; height is how many of the 8 stubborn problems that repeated tries kept missing were newly solved, so taller is better.

0123semanticsemantic3shuffledshuffled1copy/renamecopy/rename1randomrandom0

Takeaway → Meaning-matched code cracks 3 problems versus 0 for random and 1 each for mislabeled or blind-copied code, showing the match earns most of the gain.

Data table
retrieval armmisses recovered
semantic3
shuffled1
copy/rename1
random0

Numbers from reports/report_summary.json (retrieval_rows zero_to_one)

Technical framing

Direct-sampling misses recovered by each retrieval arm (of 8 misses) — Semantic matching recovers 3 misses vs 0 for random and 1 for shuffled, so the retrieved algorithm content matters.

Answers that looked right on shown tests but failed hidden checks

How to read

Four bars, one per type of retrieved solution; height is the share of answers that passed the shown example tests yet still failed the hidden checks, so lower is better.

0%25%50%75%100%semanticsemantic57.1%copy/renamecopy/rename66.7%shuffledshuffled85.7%randomrandom100%

Takeaway → Every bar is tall, from about 4 in 7 up to all of them, meaning passing the shown examples alone is not safe enough to trust an answer.

Data table
retrieval armvisible-pass hidden-wrong rate
semantic57.1%
copy/rename66.7%
shuffled85.7%
random100%

Numbers from reports/report_summary.json (retrieval_rows visible_hidden_wrong_rate)

Technical framing

Failure mode: visible-pass candidates that fail hidden tests — Public tests are too thin: 57-100% of adaptations that pass visible tests still fail hidden tests, motivating a verifier before commit.

In the author’s words from the Report · “Interpretation”

Semantic retrieval adaptation passes the primary pilot gate: it recovers three direct-sampling misses, compared with zero for random retrieval and one for shuffled retrieval. Combined with the direct sample-more pool, coverage rises from 66.7% to 79.2% on this 24-task slice at an additional 7,699 forward tokens. The control read is important. Copy/rename and shuffled retrieval both recover task 20, so that task is not strong evidence for semantic matching. The stronger semantic-specific lift is tasks 15 and 25, where matched retrieved algorithms map cleanly onto the target operation family. The main failure mode is also clear: visible-pass hidden-wrong rates are high for all retrieval arms. … Read the full result →

Overview

Standalone experiment package for testing verified algorithm retrieval plus Qwen3.5-4B adaptation on MBPP-style code tasks.

The experiment builds a verified algorithm library from training tasks, retrieves nearest algorithms for held-out tasks, asks Qwen to adapt retrieved code to the target function and public tests, and evaluates whether this recovers tasks missed by direct sampling.

Large artifacts, if any are added later, should be stored outside this directory under:

/workspace/large_artifacts/qwen35_4b_verified_algorithm_retrieval_adaptation

Final report: reports/final_report.md

Report

Rendered from reports/final_report.md

Question

Can verified algorithm retrieval plus Qwen adaptation recover held-out tasks that direct sampling missed?

The experiment builds a verified algorithm library from training tasks, retrieves top-k candidate algorithms for each held-out miss, adapts them to the target task with Qwen, and evaluates hidden tests only after candidate generation.

Setup

  • Verified library entries: 364
  • Eval baseline tasks: 24
  • Direct sample-more coverage: 66.7%
  • Direct sample-more misses: [15, 16, 20, 21, 24, 25, 26, 31]
  • Retrieval top-k: 3

Retrieval-Only Results

armretrieval coveragezero-to-onevisible-pass hidden-wrongparse/tasktokens
retrieval_copy_rename_top312.5%1 (12.5%)2/3 (66.7%)3.000
retrieval_adapt_semantic_top337.5%3 (37.5%)4/7 (57.1%)2.627699
retrieval_adapt_random_top30.0%0 (0.0%)5/5 (100.0%)2.757982
retrieval_adapt_shuffled_top312.5%1 (12.5%)6/7 (85.7%)2.887881

retrieval rates

Combined With Direct Sampling

combined armcoveragezero-to-one tasksforward tokens
base_sample_more66.7%[]45406
base_plus_retrieval_copy_rename_top370.8%[20]45406
base_plus_retrieval_adapt_semantic_top379.2%[15, 20, 25]53105
base_plus_retrieval_adapt_random_top366.7%[]53388
base_plus_retrieval_adapt_shuffled_top370.8%[20]53287

combined pareto

Recovered Tasks

armrecovered tasktaskwinner sources
retrieval_copy_rename_top320Write a function to check if the given number is woodball or not.['retrieval_copy_rename_top3_semantic_r0']
retrieval_adapt_semantic_top315Write a function to split a string at lowercase letters.['retrieval_adapt_semantic_top3_semantic_r0_s0']
retrieval_adapt_semantic_top320Write a function to check if the given number is woodball or not.['retrieval_adapt_semantic_top3_semantic_r0_s0']
retrieval_adapt_semantic_top325Write a python function to find the product of non-repeated elements in a given array.['retrieval_adapt_semantic_top3_semantic_r0_s0']
retrieval_adapt_shuffled_top320Write a function to check if the given number is woodball or not.['retrieval_adapt_shuffled_top3_shuffled_r0_s0']

Gate Readout

Semantic retrieval adaptation recovered 3 direct-sampling misses. Random retrieval adaptation recovered 0. Shuffled retrieval adaptation recovered 1.

Interpretation

Semantic retrieval adaptation passes the primary pilot gate: it recovers three direct-sampling misses, compared with zero for random retrieval and one for shuffled retrieval. Combined with the direct sample-more pool, coverage rises from 66.7% to 79.2% on this 24-task slice at an additional 7,699 forward tokens.

The control read is important. Copy/rename and shuffled retrieval both recover task 20, so that task is not strong evidence for semantic matching. The stronger semantic-specific lift is tasks 15 and 25, where matched retrieved algorithms map cleanly onto the target operation family.

The main failure mode is also clear: visible-pass hidden-wrong rates are high for all retrieval arms. Retrieval gives Qwen useful external algorithmic memory, but public tests are too thin to safely commit every visible-passing adaptation. The next iteration should scale this to a larger held-out slice and add a retrieval-candidate verifier/reranker or generated counterexample tests before commit.

Experiment log 5

Show the running log (5 entries, 2026-06-26)

2026-06-26

  • Created standalone verified algorithm retrieval + adaptation experiment package.
  • Primary question: can retrieval of verified training algorithms plus Qwen adaptation recover held-out tasks missed by direct sampling?
  • Primary metric: zero-to-one lift on tasks where direct K=8 sampling has no hidden-correct candidate.
  • Planned arms:

    • direct base sampling baseline;
    • literal retrieved-code copy/rename baseline;
    • semantic retrieval adaptation;
    • random retrieval adaptation control;
    • shuffled retrieval adaptation control;
    • oracle over generated retrieval candidates as headroom.
  • Guardrails:

    • hidden tests are evaluation only;
    • public tests are the only deployable evidence given to adaptation prompts;
    • random and shuffled retrieval controls must underperform semantic retrieval for a positive read.

Setup

  • Added local direct-sampling baseline pool: data/base_sample_more_k8_records.jsonl.
  • Built verified algorithm library from MBPP train references:

    • loaded 374 train records;
    • kept 364 verified algorithms;
    • dropped 10 unverified references.
  • Built retrieval plan for the eight direct-sampling misses:

    • tasks 15, 16, 20, 21, 24, 25, 26, 31;
    • top-k semantic retrieval = 3;
    • random and shuffled controls matched at top-k = 3.

Iteration Notes

  • First ran copy_semantic, a no-model literal copy/rename baseline.
  • The first copy/rename attempt exposed a regex escaping bug in copy_rename_code; patched and reran.
  • Then ran three Qwen adaptation arms in one model-load session:

    • semantic retrieval adaptation;
    • random retrieval adaptation;
    • shuffled retrieval adaptation.

Results

armretrieval coveragezero-to-onevisible-pass hidden-wrongparse/tasktokens
retrieval_copy_rename_top312.5%1/82/33.000
retrieval_adapt_semantic_top337.5%3/84/72.627699
retrieval_adapt_random_top30.0%0/85/52.757982
retrieval_adapt_shuffled_top312.5%1/86/72.887881

Combined with direct sample-more:

armcombined coveragerecovered tasksforward tokens
base_sample_more66.7%[]45406
base_plus_retrieval_copy_rename_top370.8%[20]45406
base_plus_retrieval_adapt_semantic_top379.2%[15, 20, 25]53105
base_plus_retrieval_adapt_random_top366.7%[]53388
base_plus_retrieval_adapt_shuffled_top370.8%[20]53287

Readout

  • Semantic retrieval adaptation passes the pilot gate: 3/8 direct misses recovered versus 0/8 random and 1/8 shuffled.
  • Task 20 is not strong semantic evidence because copy/rename and shuffled retrieval also recovered it.
  • Tasks 15 and 25 are the semantic-specific lift.
  • Main failure mode: high visible-pass hidden-wrong rate, so retrieval adaptation needs a verifier/reranker or counterexample generation before commit.

Figures 2

combined pareto
combined pareto · reports/figures/
retrieval rates
retrieval rates · reports/figures/

Data files 3

Result tables and metrics copied from the experiment folder — preview inline or open the raw file.

Reproduce

Run steps are documented inside the experiment folder (README and scripts).

Browse the experiment folder on GitHub ↗