Skip to content

Add embedding guessing game feature#35

Merged
SupraSummus merged 1 commit intomainfrom
claude/add-embedding-guessing-game-Gx2pF
Apr 12, 2026
Merged

Add embedding guessing game feature#35
SupraSummus merged 1 commit intomainfrom
claude/add-embedding-guessing-game-Gx2pF

Conversation

@SupraSummus
Copy link
Copy Markdown
Owner

Summary

This PR introduces a new embedding guessing game feature that allows players to submit phrases and see how close their embeddings are to secret target embeddings, measured by Hamming distance.

Key Changes

Models (models.py)

  • Added GuessingTarget model to represent secret embeddings that players try to match
    • Stores a phrase, its embedding, and scheduling state for embedding computation
    • Includes schedule_embedding() method to queue embedding generation via django-goals
  • Added Guess model to track player submissions
    • Links a player's query phrase to a target via foreign keys
    • Enforces uniqueness constraint on (target, query) pairs
  • Added _ensure_target_embedding() function to compute embeddings for guessing targets
    • Mirrors the existing _ensure_embedding() pattern for ExplorerQuery
    • Handles API failures with retry logic

Views (views.py)

  • Created new guessing_router sub-router under the main router
  • Implemented four view endpoints:
    • guessing_list: Shows all active guessing targets
    • guessing_detail: Displays a specific target with form and guess history
    • guessing_post: Handles form submission, creates/reuses queries and guesses
    • guess_status: HTMX endpoint for polling pending guess computations
  • Added GuessForm for phrase input with validation
  • Implemented _render_guess_row() helper to render individual guesses with either computed distance or HTMX polling state
  • Implemented _build_guessing_detail_page() to construct the game interface with sorted computed guesses and pending items

Admin (admin.py)

  • Registered GuessingTarget and Guess models in Django admin
  • Added custom admin for GuessingTarget with:
    • Display of name, active status, embedding readiness, and creation date
    • Auto-scheduling of embedding computation on save
    • Read-only fields for goal and timestamp

Tests (tests.py)

  • Added comprehensive test suite covering:
    • Model behavior (string representation, embedding scheduling, uniqueness)
    • Embedding computation with mocked API responses and error handling
    • View functionality (list, detail, form submission)
    • Distance calculation and display logic
    • HTMX polling behavior for pending computations
    • Edge cases (duplicate phrases, phrase length validation)

Database

  • Created migration 0002_guessingtarget_guess.py with models and constraints

Notable Implementation Details

  • Reuses existing ExplorerQuery model for phrase embeddings to avoid duplication
  • Uses Hamming distance (bit-level differences) to measure embedding similarity
  • Implements HTMX polling with 2-second intervals for real-time distance updates as embeddings compute
  • Separates computed guesses (sorted by distance) from pending ones in the UI
  • Follows existing patterns from the embedding explorer feature (scheduling, error handling, async computation)

https://claude.ai/code/session_01X71384QMsoYNs2yNUefF3k

@SupraSummus SupraSummus force-pushed the claude/add-embedding-guessing-game-Gx2pF branch from 9f27eaa to 8be6b21 Compare April 12, 2026 21:21
New `guessing` app lets users guess phrases whose embeddings are close
to a secret randomly-generated 2048-bit target. Key design:

- GuessingTarget holds a random BitField embedding (no phrase, no async)
- Guess links target + ExplorerQuery + user; unique per (target, query, user)
- All views require login; guesses are scoped to the requesting user
- Distance computed in DB via pgvector HammingDistance annotation;
  pending guesses (no embedding yet) use HTMX polling until ready

https://claude.ai/code/session_01X71384QMsoYNs2yNUefF3k
@SupraSummus SupraSummus force-pushed the claude/add-embedding-guessing-game-Gx2pF branch from 162988e to 342bd2c Compare April 12, 2026 21:35
@SupraSummus SupraSummus merged commit 408ba25 into main Apr 12, 2026
5 checks passed
@SupraSummus SupraSummus deleted the claude/add-embedding-guessing-game-Gx2pF branch April 12, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants