Program Database - chunhualiao/public-docs GitHub Wiki

alphaEvolve

some type of memory storing experiences and new knowledge

Great question. The Program Database is a core component of AlphaEvolve’s evolutionary engine. It doesn't just store code—it stores evaluated, contextualized candidate programs and plays a vital role in mutation selection, prompt construction, and progress tracking.


🧠 What Is the Program Database?

It is a structured, evolving memory of:

  • Programs (code blocks, often full files)
  • Evaluation results (from running the evaluate() function)
  • Associated metadata (timestamps, source, parent lineage, diffs applied, etc.)

📦 What Does Each Entry Store?

Each record in the Program Database might include:

Field Description
program_id Unique identifier (e.g., UUID)
code_snapshot Full source code or relevant diff
parent_id Which previous program it was derived from
diff The LLM-generated changes applied
scores Output of evaluate(): could include accuracy, runtime, rank, etc.
timestamp When this version was evaluated
LLM_metadata Which LLM was used, with what prompt, and temperature
notes Optional human comments or LLM-generated insights
execution_logs stdout/stderr logs, success/failure info

Optionally, evaluation artifacts (like plots, matrices, compiled binaries, etc.) can be stored by reference.


➕ How Is a Program Added?

After each iteration:

  1. Apply the diff to the parent program.

  2. Run evaluate(), returning one or more metrics (e.g., accuracy, runtime, memory).

  3. Create a new entry:

    {
      "program_id": "abc123",
      "code_snapshot": "...",
      "parent_id": "xyz987",
      "diff": { "search": "...", "replace": "..." },
      "scores": { "accuracy": 0.91, "log_loss": 0.32 },
      "timestamp": "2025-05-15T14:10:00Z",
      "LLM_metadata": {
        "model": "Gemini-2.0-Pro",
        "prompt_hash": "efg456"
      }
    }
  4. Insert into the program database (usually a distributed key-value store or document database).


🔍 How Is It Queried and Used?

The Program Database is queried for:

1. Prompt Construction

When building a new LLM prompt, AlphaEvolve:

  • Samples top-K scoring programs as inspiration.
  • Samples diverse/novel programs for creativity.
  • Includes scores, diff lineage, and LLM commentary if available.

This gives the LLM a rich prompt like:

“Previous program achieved 87% accuracy using 3 ResNet blocks. Consider adding dropout and replacing ReLU with GELU. Here's the code...”


2. Evolutionary Selection

AlphaEvolve needs to balance:

  • Exploitation (modify the best candidates)
  • Exploration (try something different)

To do that, it queries:

  • Top-performing programs by score
  • Diverse examples across "niches" (inspired by MAP-Elites)
  • Recently added programs to encourage freshness

3. Score Tracking / Plotting / Debugging

To visualize progress:

  • Plot best score over time
  • Compare average improvements per mutation
  • Inspect diff chains and stagnation points

📈 Example: Query to Select Next Parents

# Pseudo-code
candidates = database.query(
    where="score['accuracy'] > 0.85 AND age_in_hours < 6",
    order_by="score['log_loss'] ASC",
    limit=5
)

AlphaEvolve might combine these programs’ code to build a diverse prompt, or mutate them directly.


🧬 Evolutionary Algorithm Integration

AlphaEvolve’s evolutionary controller uses the program database to:

  • Sample parent(s)
  • Record mutation lineage
  • Track multi-objective frontiers (e.g., Pareto optimality)
  • Prune or resample stale or redundant programs

The system uses MAP-Elites + island population models, so the database might be logically partitioned into "cells" (e.g., by score bands, strategies, or architecture features).


🧰 Summary

Role How the Program Database Supports It
LLM Prompting Supplies high-quality, scored code examples for inspiration
Mutation Lineage Records diffs and parent–child relationships
Diversity Sampling Enables niche-based exploration via MAP-Elites
Evaluation Tracking Centralized source for scores, logs, and trends
Debugging Allows humans or other agents to trace, reproduce, and interpret results

If you'd like, I can draw a schematic diagram of how the Program Database fits into AlphaEvolve's full loop. Would that help?

⚠️ **GitHub.com Fallback** ⚠️