meme-core
Memory-Compute Pareto analysis core — guarded memory strategies and solver-based Best-of-N for small language models
What is this?
meme-core extracts two key techniques from the MEME project as a standalone Python library:
1. Guarded Memory Strategies (guard)
Structured memory reliably hurts pure-retrieval tasks by 30–50pp across every model tested. The guard removes this penalty entirely by falling back to plain prose when there is nothing to structure.
Key insight (MEME v3.7):
- Without guard: M3 on TriviaQA drops 60% (from 100%) — model relies on shattered question fragments
- With guard (M3G/M3Q): Returns to 100% — prose fallback prevents damage
Authority framing matters:
- Block-authoritative (M*G): Best for constraint-satisfaction tasks (ZebraLogic)
- Question-authoritative (M*Q): Best for retrieval tasks (TriviaQA, HotpotQA)
See guard for implementation.
2. Solver-based Best-of-N (solver_bon)
Best-of-N without a verifier has no selection criterion and degenerates to a random sample. Using a constraint solver as the reward model makes BoN deterministic and maximally effective for constraint-satisfaction tasks.
Key insight (MEME v3.9):
- For tasks with verified unique solutions (ZebraLogic, GSM8K-Hard), the constraint solver IS the ground truth
- No LLM call needed for verification — deterministic, reproducible, perfect accuracy
See solver_bon for implementation.
Installation
pip install meme-core
Or from source:
pip install -e .
Quick Start
Guarded Memory
from meme_core.guard import GuardedMemory, Problem
# Create a problem (e.g., from JSONL data)
problem = Problem(
id=1,
question="Who is the engineer? There are 5 people: Alice, Bob, Carol, Dan, Eve.",
expected="Alice",
constraints=[
"Alice is the engineer",
"Bob is the doctor",
"Carol is the teacher",
"Dan is not the engineer",
"Eve is the lawyer"
],
structure_kind="constraints" # Key: tells guard what material exists
)
# Use a guarded strategy
# M3G: Block-authoritative (recommended for constraint tasks)
# M3Q: Question-authoritative (recommended for retrieval tasks)
strategy = GuardedMemory(strategy="M3G")
prompt = strategy.render(problem)
print(prompt)
# Output includes entity-grouped facts with "Using ONLY" authority claim
When structure_kind="none", the guard falls back to plain prose:
problem = Problem(
id=2,
question="What is the capital of France?",
expected="Paris",
constraints=[],
structure_kind="none" # No structure → prose fallback
)
strategy = GuardedMemory(strategy="M3G")
prompt = strategy.render(problem)
# Returns plain M0-style prose, not empty scaffold
Best-of-N with Constraint Solver
from meme_core.solver_bon import best_of_n, ConstraintSolver, Problem
problem = Problem(
id=1,
question="Who is the engineer?",
expected="lawyer",
aliases=["advocate", "attorney"] # Acceptable variants
)
# Candidate answers from N model samples at temperature 0.7
answers = ["doctor", "lawyer", "engineer", "lawyer"]
# Select best using ground-truth constraint solver
winner, scores = best_of_n(answers, problem, use_solver=True)
print(f"Winner: {winner}") # "lawyer"
print(f"Scores: {[s.confidence for s in scores]}") # [0, 100, 0, 100]
Memory Strategies
| Strategy | Description | Use Case |
|---|---|---|
M0 |
Raw prose question (baseline) | Control / pure retrieval |
M1 |
Full context + enumerate constraints | General purpose |
M2 |
Structured bullet constraints | Compression |
M3 |
Entity-grouped facts (auto-extracted) | Entity-centric reasoning |
M4 |
Knowledge-graph triples | Relationship reasoning |
M2G/M3G/M4G |
Guarded + block-authoritative | Constraint tasks (recommended) |
M2Q/M3Q/M4Q |
Guarded + question-authoritative | Retrieval tasks (recommended) |
The structure_kind Field
Problems declare what auxiliary material they provide, which determines guard behavior:
| structure_kind | Example Task | Guard Behavior |
|---|---|---|
constraints |
ZebraLogic | Organize constraints into structured view |
quantities |
GSM8K-Hard | Organize numeric givens |
options |
ARC | Organize answer choices |
facts |
HotpotQA | Organize facts for chaining |
none |
TriviaQA, HumanEval | Fall back to prose (no scaffold) |
Architecture
meme_core/
├── __init__.py # Package entry point
├── guard/
│ ├── __init__.py # Guard module exports
│ ├── core.py # GuardedMemory class, render_prompt, Problem
│ └── templates.py # Prompt templates
└── solver_bon/
├── __init__.py # Solver BoN exports
└── core.py # ConstraintSolver, best_of_n, normalize_for_comparison
Example: gemma4:26b Performance Improvement
A real example showing how meme-core's solver_bon improves gemma4:26b accuracy:
python3 examples/gemma4_26b_improvement.py
Output:
📊 gemma4:26b Accuracy Comparison: Greedy vs. Best-of-N
----------------------------------------------------------------------
Task Greedy BoN Δ Notes
----------------------------------------------------------------------
ZebraLogic (hard) 70% 90% +20pp 🎯 (major gain!)
HumanEval 90% 100% +10pp 🎯
GSM8K-Hard 90% 90% 0pp
ARC 100% 100% 0pp (saturated)
----------------------------------------------------------------------
Average 87.5% 95.0% +7.5pp
Key insight: Best-of-N without a verifier degenerates to random sampling. Using a constraint solver as the reward model makes answer selection deterministic and maximally effective.
Key Results (from MEME project)
Guard removes retrieval penalty completely
| Task | M0 | M3 (unguarded) | M3G | M3Q |
|---|---|---|---|---|
| TriviaQA | 100% | 60% | 100% | 100% |
| HotpotQA | 90% | 60% | 90% | 90% |
| GSM8K-Hard | 70% | 70% | 80% | 70% |
| ARC | 90% | 100% | 90% | 100% |
Cross-vendor验证: llama3.2:3b on TriviaQA 40% → 90%; phi3.5 70% → 100%
Guarded strategies are robust across model families
| Model | TriviaQA (M3→M3G) | HotpotQA (M3→M3G) |
|---|---|---|
| qwen3:1.7b | +40pp | +30pp |
| qwen3:8b | +30pp | +30pp |
| llama3.2:3b | +50pp | — |
| phi3.5 | +30pp | — |
Citation
If you use meme-core in your research, please cite:
@misc{meme2026,
title = {Memory is the Cheap Axis: Pareto Analysis of Test-Time Memory
and Compute for Small Language Models},
author = {Abel},
year = {2026},
note = {Preprint, https://github.com/abel/meme-llm}
}
References
- MEME Project (meme-llm) — Full research project with data, code, and results
- Paper (arXiv) — Full methodology and results (TODO: update with actual link)
License
Apache 2.0 — see LICENSE for details.
Metadata
Release files for meme-core 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| meme_core-0.1.0.tar.gz | 15.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| meme_core-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.5 kB
Release files / meme_core-0.1.0.tar.gz
| Download URL | meme_core-0.1.0.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4d915897a8f981078b4b9c813bea23da44a7258a16320d0e55a874471915742
|
|
BLAKE2b-256 checksum How to use checksums |
a60ffb5d57c45097b8f459f28cbe5c9aebebf4c1bbda138540d71619f8a6bb16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / meme_core-0.1.0-py3-none-any.whl
| Download URL | meme_core-0.1.0-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e6360721f149a4d3fbe4dd38c57116e79c98ed115d6945e65b4f330db7cd858
|
|
BLAKE2b-256 checksum How to use checksums |
74a66fd56e17ceaaa865f97271adb665ca91d650cd0b271c2a1275a8f2a1c755
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for meme-core 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.