{
  "id": 693110,
  "title": "Hybrid RAG + Multi-Attempt Tool Use for AIMO Progress Prize 3",
  "content": "<p><strong>Author:</strong> Lonnie Qin<br>\n<strong>Competition:</strong> AI Mathematical Olympiad — Progress Prize 3<br>\n<strong>Public LB Score:</strong> ≈ 40 / 50 (no improvement over simpler baselines)<br>\n<strong>Status:</strong> Awaiting Private LB results (hopeful for a competitive score)</p>\n<hr>\n<h3>1. Overview</h3>\n<p>This solution implements a <strong>retrieval-augmented, multi-attempt reasoning pipeline</strong> built around a 120B-class model, a high-quality olympiad corpus, and a persistent Python sandbox for tool use.</p>\n<p><strong>Core Idea (which I still believe is strong):</strong><br>\nGive the model a rich set of similar, fully-solved competition problems (via hybrid semantic + keyword retrieval) and let it reason multiple times in parallel with tool access. Combine the attempts using entropy-weighted voting. This approach mimics how strong human contestants solve problems — by recalling analogous examples and verifying rigorously.</p>\n<p>While the public leaderboard score stabilized around <strong>40</strong>, I am optimistic that the method’s depth will translate better on the private test set.</p>\n<hr>\n<h3>2. Corpus Creation &amp; Embedding Pipeline</h3>\n<p><strong>Notebook:</strong> <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation</a></p>\n<p><strong>Datasets Used</strong></p>\n<ul>\n<li><strong>NuminaMath-1.5</strong> (<code>AI-MO/NuminaMath-1.5</code>): ~900k problems → filtered to hard competition-style only (<code>aime</code>, <code>amc_10/12</code>, <code>imo</code>, <code>usamo</code>, <code>putnam</code>, <code>hmmt</code>, etc.)</li>\n<li><strong>Hendrycks MATH</strong> (<code>hendrycks/competition_math</code>): Level 4 &amp; 5 only</li>\n</ul>\n<p><strong>Filtering &amp; Cleaning</strong></p>\n<ul>\n<li>Minimum solution length = 100 characters</li>\n<li>Problem-type filter (Number Theory, Counting &amp; Probability, Intermediate Algebra, Precalculus, Geometry, Algebra)</li>\n<li>Strict deduplication on normalized problem text</li>\n<li>Aggressive cleaning of AoPS navigation boilerplate, markdown links, ellipsis, etc.</li>\n</ul>\n<p><strong>Embedding Generation</strong></p>\n<pre><code>model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')  # 768-dim\nembeddings = model.encode(corpus_texts, normalize_embeddings=True, batch_size=32)\n</code></pre>\n<ul>\n<li>FAISS <code>IndexFlatL2</code> (exact search)</li>\n<li>Saved: <code>faiss_index.bin</code>, <code>corpus.pkl</code>, <code>embeddings.npy</code>, metadata</li>\n</ul>\n<p><strong>Final corpus size:</strong> ~120k high-quality solved problems.</p>\n<hr>\n<h3>3. Main Inference Pipeline</h3>\n<p><strong>Notebook:</strong> <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-3-solution\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-3-solution</a></p>\n<h4>3.1 Model &amp; Serving</h4>\n<ul>\n<li>Model: <code>gpt-oss-120b</code> served via vLLM</li>\n<li>Configuration: <code>fp8_e4m3</code> KV cache, 65k context, <code>gpu-memory-utilization=0.96</code>, prefix caching</li>\n</ul>\n<h4>3.2 Hybrid Similar-Problem Retriever</h4>\n<pre><code>class SimilarProblemRetriever:\n    def get_similar(self, problem: str, k: int = 5) -&gt; str:\n        # 1. Embedding retrieval (3× candidates)\n        # 2. Keyword retrieval using MATH_KEYWORDS (divisor, prime, gcd, permutation, triangle…)\n        # 3. Hybrid score = 0.6×embedding_sim + 0.4×keyword_overlap\n</code></pre>\n<p>Returns 5 reference problems with full solutions and answers — dramatically enriching the context.</p>\n<h4>3.3 System Prompt Highlights</h4>\n<ul>\n<li>Elite IMO-level identity</li>\n<li>Explicit instructions to study and adapt techniques from the retrieved examples</li>\n<li>Strict <code>\\boxed{}</code> output format (0–99999)</li>\n</ul>\n<h4>3.4 Tool Use — Persistent Jupyter Sandbox</h4>\n<ul>\n<li>16 pre-warmed kernels with <code>sympy</code>, <code>numpy</code>, <code>mpmath</code>, etc.</li>\n<li>Custom <code>python</code> tool with automatic <code>print()</code> injection</li>\n<li>State persists across reasoning turns within an attempt</li>\n</ul>\n<h4>3.5 Multi-Attempt Parallel Solving</h4>\n<ul>\n<li>8 parallel attempts per problem (different seeds)</li>\n<li>Up to 128 reasoning turns each</li>\n<li><code>temperature=1.0</code>, <code>min_p=0.02</code></li>\n<li>Early stopping when one answer reaches 4 votes</li>\n</ul>\n<h4>3.6 Answer Selection</h4>\n<ul>\n<li>Weighted voting: weight = <code>1 / max(entropy, 1e-9)</code></li>\n<li>Mean token entropy used as confidence signal</li>\n<li>Transparent vote table displayed for each problem</li>\n</ul>\n<hr>\n<h3>4. Time &amp; Resource Management</h3>\n<ul>\n<li>Global notebook timeout: 17,400 s</li>\n<li>Adaptive per-problem budget (300–900 s) with 50-problem lookahead safety</li>\n<li>Fully reliable within competition constraints</li>\n</ul>\n<hr>\n<h3>5. Prompt Logging</h3>\n<p>All prompts, retrieved examples, and final answers are logged to <code>prompt_logs.jsonl</code> for analysis.</p>\n<hr>\n<h3>6. Results &amp; Reflection</h3>\n<p><strong>Public LB:</strong> ≈ 40<br>\nThe approach did not improve the public leaderboard score relative to simpler baselines. However, the core components (high-quality corpus, hybrid retrieval, persistent tool use, and entropy-weighted ensembling) remain technically sound and closely mirror successful human problem-solving strategies.</p>\n<p>I am hopeful that the private test set will reward the method’s depth and robustness more than the public set did.</p>\n<hr>\n<h3>7. Why This Approach Still Has Strong Potential</h3>\n<table>\n<thead>\n<tr>\n<th>Component</th>\n<th>Value Even at Current Score</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Hybrid retrieval</td>\n<td>Guarantees relevant examples</td>\n</tr>\n<tr>\n<td>120B model + vLLM</td>\n<td>Raw reasoning power</td>\n</tr>\n<tr>\n<td>Persistent Python sandbox</td>\n<td>Exact verification</td>\n</tr>\n<tr>\n<td>Entropy-weighted voting</td>\n<td>Filters low-confidence outputs</td>\n</tr>\n<tr>\n<td>Multi-attempt parallelism</td>\n<td>Robustness</td>\n</tr>\n</tbody>\n</table>\n<hr>\n<h3>8. Future Improvements (if continuing)</h3>\n<ul>\n<li>Stronger reranking (cross-encoder)</li>\n<li>Difficulty-aware example selection</li>\n<li>Longer context or MoE models</li>\n<li>Self-verification / critique loops</li>\n</ul>\n<hr>\n<p><strong>Conclusion</strong><br>\nWhile the public leaderboard result was not the breakthrough I hoped for, I remain convinced that retrieval-augmented multi-attempt reasoning with tool use is a powerful direction for mathematical Olympiad AI. The private LB will be the real test.</p>\n<p><strong>Notebooks</strong>  </p>\n<ul>\n<li>Corpus creation: <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation</a></li>\n<li>Full solution:  <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-3-solution\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-3-solution</a></li>\n</ul>\n<p>Credits to notebooks:\n<a href=\"https://www.kaggle.com/code/nihilisticneuralnet/44-50-let-me-over-cook\" target=\"_blank\">https://www.kaggle.com/code/nihilisticneuralnet/44-50-let-me-over-cook</a></p>",
  "comments": [],
  "comment_count": 0,
  "messages": [
    {
      "id": 3445343,
      "postDate": "2026-04-19T15:15:43.083Z",
      "content": "<p><strong>Author:</strong> Lonnie Qin<br>\n<strong>Competition:</strong> AI Mathematical Olympiad — Progress Prize 3<br>\n<strong>Public LB Score:</strong> ≈ 40 / 50 (no improvement over simpler baselines)<br>\n<strong>Status:</strong> Awaiting Private LB results (hopeful for a competitive score)</p>\n<hr>\n<h3>1. Overview</h3>\n<p>This solution implements a <strong>retrieval-augmented, multi-attempt reasoning pipeline</strong> built around a 120B-class model, a high-quality olympiad corpus, and a persistent Python sandbox for tool use.</p>\n<p><strong>Core Idea (which I still believe is strong):</strong><br>\nGive the model a rich set of similar, fully-solved competition problems (via hybrid semantic + keyword retrieval) and let it reason multiple times in parallel with tool access. Combine the attempts using entropy-weighted voting. This approach mimics how strong human contestants solve problems — by recalling analogous examples and verifying rigorously.</p>\n<p>While the public leaderboard score stabilized around <strong>40</strong>, I am optimistic that the method’s depth will translate better on the private test set.</p>\n<hr>\n<h3>2. Corpus Creation &amp; Embedding Pipeline</h3>\n<p><strong>Notebook:</strong> <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation</a></p>\n<p><strong>Datasets Used</strong></p>\n<ul>\n<li><strong>NuminaMath-1.5</strong> (<code>AI-MO/NuminaMath-1.5</code>): ~900k problems → filtered to hard competition-style only (<code>aime</code>, <code>amc_10/12</code>, <code>imo</code>, <code>usamo</code>, <code>putnam</code>, <code>hmmt</code>, etc.)</li>\n<li><strong>Hendrycks MATH</strong> (<code>hendrycks/competition_math</code>): Level 4 &amp; 5 only</li>\n</ul>\n<p><strong>Filtering &amp; Cleaning</strong></p>\n<ul>\n<li>Minimum solution length = 100 characters</li>\n<li>Problem-type filter (Number Theory, Counting &amp; Probability, Intermediate Algebra, Precalculus, Geometry, Algebra)</li>\n<li>Strict deduplication on normalized problem text</li>\n<li>Aggressive cleaning of AoPS navigation boilerplate, markdown links, ellipsis, etc.</li>\n</ul>\n<p><strong>Embedding Generation</strong></p>\n<pre><code>model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')  # 768-dim\nembeddings = model.encode(corpus_texts, normalize_embeddings=True, batch_size=32)\n</code></pre>\n<ul>\n<li>FAISS <code>IndexFlatL2</code> (exact search)</li>\n<li>Saved: <code>faiss_index.bin</code>, <code>corpus.pkl</code>, <code>embeddings.npy</code>, metadata</li>\n</ul>\n<p><strong>Final corpus size:</strong> ~120k high-quality solved problems.</p>\n<hr>\n<h3>3. Main Inference Pipeline</h3>\n<p><strong>Notebook:</strong> <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-3-solution\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-3-solution</a></p>\n<h4>3.1 Model &amp; Serving</h4>\n<ul>\n<li>Model: <code>gpt-oss-120b</code> served via vLLM</li>\n<li>Configuration: <code>fp8_e4m3</code> KV cache, 65k context, <code>gpu-memory-utilization=0.96</code>, prefix caching</li>\n</ul>\n<h4>3.2 Hybrid Similar-Problem Retriever</h4>\n<pre><code>class SimilarProblemRetriever:\n    def get_similar(self, problem: str, k: int = 5) -&gt; str:\n        # 1. Embedding retrieval (3× candidates)\n        # 2. Keyword retrieval using MATH_KEYWORDS (divisor, prime, gcd, permutation, triangle…)\n        # 3. Hybrid score = 0.6×embedding_sim + 0.4×keyword_overlap\n</code></pre>\n<p>Returns 5 reference problems with full solutions and answers — dramatically enriching the context.</p>\n<h4>3.3 System Prompt Highlights</h4>\n<ul>\n<li>Elite IMO-level identity</li>\n<li>Explicit instructions to study and adapt techniques from the retrieved examples</li>\n<li>Strict <code>\\boxed{}</code> output format (0–99999)</li>\n</ul>\n<h4>3.4 Tool Use — Persistent Jupyter Sandbox</h4>\n<ul>\n<li>16 pre-warmed kernels with <code>sympy</code>, <code>numpy</code>, <code>mpmath</code>, etc.</li>\n<li>Custom <code>python</code> tool with automatic <code>print()</code> injection</li>\n<li>State persists across reasoning turns within an attempt</li>\n</ul>\n<h4>3.5 Multi-Attempt Parallel Solving</h4>\n<ul>\n<li>8 parallel attempts per problem (different seeds)</li>\n<li>Up to 128 reasoning turns each</li>\n<li><code>temperature=1.0</code>, <code>min_p=0.02</code></li>\n<li>Early stopping when one answer reaches 4 votes</li>\n</ul>\n<h4>3.6 Answer Selection</h4>\n<ul>\n<li>Weighted voting: weight = <code>1 / max(entropy, 1e-9)</code></li>\n<li>Mean token entropy used as confidence signal</li>\n<li>Transparent vote table displayed for each problem</li>\n</ul>\n<hr>\n<h3>4. Time &amp; Resource Management</h3>\n<ul>\n<li>Global notebook timeout: 17,400 s</li>\n<li>Adaptive per-problem budget (300–900 s) with 50-problem lookahead safety</li>\n<li>Fully reliable within competition constraints</li>\n</ul>\n<hr>\n<h3>5. Prompt Logging</h3>\n<p>All prompts, retrieved examples, and final answers are logged to <code>prompt_logs.jsonl</code> for analysis.</p>\n<hr>\n<h3>6. Results &amp; Reflection</h3>\n<p><strong>Public LB:</strong> ≈ 40<br>\nThe approach did not improve the public leaderboard score relative to simpler baselines. However, the core components (high-quality corpus, hybrid retrieval, persistent tool use, and entropy-weighted ensembling) remain technically sound and closely mirror successful human problem-solving strategies.</p>\n<p>I am hopeful that the private test set will reward the method’s depth and robustness more than the public set did.</p>\n<hr>\n<h3>7. Why This Approach Still Has Strong Potential</h3>\n<table>\n<thead>\n<tr>\n<th>Component</th>\n<th>Value Even at Current Score</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Hybrid retrieval</td>\n<td>Guarantees relevant examples</td>\n</tr>\n<tr>\n<td>120B model + vLLM</td>\n<td>Raw reasoning power</td>\n</tr>\n<tr>\n<td>Persistent Python sandbox</td>\n<td>Exact verification</td>\n</tr>\n<tr>\n<td>Entropy-weighted voting</td>\n<td>Filters low-confidence outputs</td>\n</tr>\n<tr>\n<td>Multi-attempt parallelism</td>\n<td>Robustness</td>\n</tr>\n</tbody>\n</table>\n<hr>\n<h3>8. Future Improvements (if continuing)</h3>\n<ul>\n<li>Stronger reranking (cross-encoder)</li>\n<li>Difficulty-aware example selection</li>\n<li>Longer context or MoE models</li>\n<li>Self-verification / critique loops</li>\n</ul>\n<hr>\n<p><strong>Conclusion</strong><br>\nWhile the public leaderboard result was not the breakthrough I hoped for, I remain convinced that retrieval-augmented multi-attempt reasoning with tool use is a powerful direction for mathematical Olympiad AI. The private LB will be the real test.</p>\n<p><strong>Notebooks</strong>  </p>\n<ul>\n<li>Corpus creation: <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation</a></li>\n<li>Full solution:  <a href=\"https://www.kaggle.com/code/lonnieqin/aimo-3-solution\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/aimo-3-solution</a></li>\n</ul>\n<p>Credits to notebooks:\n<a href=\"https://www.kaggle.com/code/nihilisticneuralnet/44-50-let-me-over-cook\" target=\"_blank\">https://www.kaggle.com/code/nihilisticneuralnet/44-50-let-me-over-cook</a></p>",
      "rawMarkdown": "**Author:** Lonnie Qin  \n**Competition:** AI Mathematical Olympiad — Progress Prize 3  \n**Public LB Score:** ≈ 40 / 50 (no improvement over simpler baselines)  \n**Status:** Awaiting Private LB results (hopeful for a competitive score)\n\n---\n\n### 1. Overview\n\nThis solution implements a **retrieval-augmented, multi-attempt reasoning pipeline** built around a 120B-class model, a high-quality olympiad corpus, and a persistent Python sandbox for tool use.\n\n**Core Idea (which I still believe is strong):**  \nGive the model a rich set of similar, fully-solved competition problems (via hybrid semantic + keyword retrieval) and let it reason multiple times in parallel with tool access. Combine the attempts using entropy-weighted voting. This approach mimics how strong human contestants solve problems — by recalling analogous examples and verifying rigorously.\n\nWhile the public leaderboard score stabilized around **40**, I am optimistic that the method’s depth will translate better on the private test set.\n\n---\n\n### 2. Corpus Creation & Embedding Pipeline\n\n**Notebook:** https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation\n\n**Datasets Used**\n- **NuminaMath-1.5** (`AI-MO/NuminaMath-1.5`): ~900k problems → filtered to hard competition-style only (`aime`, `amc_10/12`, `imo`, `usamo`, `putnam`, `hmmt`, etc.)\n- **Hendrycks MATH** (`hendrycks/competition_math`): Level 4 & 5 only\n\n**Filtering & Cleaning**\n- Minimum solution length = 100 characters\n- Problem-type filter (Number Theory, Counting & Probability, Intermediate Algebra, Precalculus, Geometry, Algebra)\n- Strict deduplication on normalized problem text\n- Aggressive cleaning of AoPS navigation boilerplate, markdown links, ellipsis, etc.\n\n**Embedding Generation**\n```python\nmodel = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')  # 768-dim\nembeddings = model.encode(corpus_texts, normalize_embeddings=True, batch_size=32)\n```\n- FAISS `IndexFlatL2` (exact search)\n- Saved: `faiss_index.bin`, `corpus.pkl`, `embeddings.npy`, metadata\n\n**Final corpus size:** ~120k high-quality solved problems.\n\n---\n\n### 3. Main Inference Pipeline\n\n**Notebook:** https://www.kaggle.com/code/lonnieqin/aimo-3-solution\n\n#### 3.1 Model & Serving\n- Model: `gpt-oss-120b` served via vLLM\n- Configuration: `fp8_e4m3` KV cache, 65k context, `gpu-memory-utilization=0.96`, prefix caching\n\n#### 3.2 Hybrid Similar-Problem Retriever\n```python\nclass SimilarProblemRetriever:\n    def get_similar(self, problem: str, k: int = 5) -> str:\n        # 1. Embedding retrieval (3× candidates)\n        # 2. Keyword retrieval using MATH_KEYWORDS (divisor, prime, gcd, permutation, triangle…)\n        # 3. Hybrid score = 0.6×embedding_sim + 0.4×keyword_overlap\n```\nReturns 5 reference problems with full solutions and answers — dramatically enriching the context.\n\n#### 3.3 System Prompt Highlights\n- Elite IMO-level identity\n- Explicit instructions to study and adapt techniques from the retrieved examples\n- Strict `\\boxed{}` output format (0–99999)\n\n#### 3.4 Tool Use — Persistent Jupyter Sandbox\n- 16 pre-warmed kernels with `sympy`, `numpy`, `mpmath`, etc.\n- Custom `python` tool with automatic `print()` injection\n- State persists across reasoning turns within an attempt\n\n#### 3.5 Multi-Attempt Parallel Solving\n- 8 parallel attempts per problem (different seeds)\n- Up to 128 reasoning turns each\n- `temperature=1.0`, `min_p=0.02`\n- Early stopping when one answer reaches 4 votes\n\n#### 3.6 Answer Selection\n- Weighted voting: weight = `1 / max(entropy, 1e-9)`\n- Mean token entropy used as confidence signal\n- Transparent vote table displayed for each problem\n\n---\n\n### 4. Time & Resource Management\n- Global notebook timeout: 17,400 s\n- Adaptive per-problem budget (300–900 s) with 50-problem lookahead safety\n- Fully reliable within competition constraints\n\n---\n\n### 5. Prompt Logging\nAll prompts, retrieved examples, and final answers are logged to `prompt_logs.jsonl` for analysis.\n\n---\n\n### 6. Results & Reflection\n\n**Public LB:** ≈ 40  \nThe approach did not improve the public leaderboard score relative to simpler baselines. However, the core components (high-quality corpus, hybrid retrieval, persistent tool use, and entropy-weighted ensembling) remain technically sound and closely mirror successful human problem-solving strategies.\n\nI am hopeful that the private test set will reward the method’s depth and robustness more than the public set did.\n\n---\n\n### 7. Why This Approach Still Has Strong Potential\n\n| Component                     | Value Even at Current Score |\n|-------------------------------|-----------------------------|\n| Hybrid retrieval              | Guarantees relevant examples |\n| 120B model + vLLM             | Raw reasoning power         |\n| Persistent Python sandbox     | Exact verification          |\n| Entropy-weighted voting       | Filters low-confidence outputs |\n| Multi-attempt parallelism     | Robustness                  |\n\n---\n\n### 8. Future Improvements (if continuing)\n- Stronger reranking (cross-encoder)\n- Difficulty-aware example selection\n- Longer context or MoE models\n- Self-verification / critique loops\n\n---\n\n**Conclusion**  \nWhile the public leaderboard result was not the breakthrough I hoped for, I remain convinced that retrieval-augmented multi-attempt reasoning with tool use is a powerful direction for mathematical Olympiad AI. The private LB will be the real test.\n\n**Notebooks**  \n- Corpus creation: https://www.kaggle.com/code/lonnieqin/aimo-math-corpus-creation-embedding-generation\n- Full solution:  https://www.kaggle.com/code/lonnieqin/aimo-3-solution\n\nCredits to notebooks:\nhttps://www.kaggle.com/code/nihilisticneuralnet/44-50-let-me-over-cook\n"
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-20T04:21:21Z",
  "competition_id": 118448,
  "competition_slug": "ai-mathematical-olympiad-progress-prize-3",
  "team_id": 14800917,
  "solution_url": "/competitions/ai-mathematical-olympiad-progress-prize-3/writeups/hybrid-rag-multi-attempt-reasoning-with-persistent"
}