Solving NYT Connections with DsPy
In this tutorial, you'll build an AI system that solves NYT Connections puzzles using DsPy for structured reasoning and Dagster for pipeline orchestration. DsPy is a framework for building modular AI software that can be compiled into effective prompts and optimized automatically.
This example demonstrates how to:
- Load and process Connections puzzle data
- Build a DsPy solver module with game logic
- Optimize the solver using MIPROv2 automatic optimization
- Evaluate puzzle-solving performance with custom metrics
- Deploy and monitor AI systems in production
Prerequisites
To follow the steps in this guide, you'll need:
- Basic Python knowledge
- Python 3.9+ installed on your system. Refer to the Installation guide for information.
- Understanding of language models and AI pipelines
- A Google Gemini API key (get one at Google AI Studio)
- Familiarity with puzzle-solving and game logic
- Basic knowledge of the NYT Connections puzzle format
Step 1: Set up your Dagster environment
First, set up a new Dagster project with DsPy dependencies.
-
Clone the Dagster repo and navigate to the project:
cd examples/docs_projects/project_dspy
-
Install the required dependencies with
uv
:uv sync
-
Activate the virtual environment:
- MacOS
- Windows
source .venv/bin/activate
.venv\Scripts\activate
-
Set up your environment variables by copying the template:
cp .env.example .env
Then populate the required fields:
GEMINI_API_KEY
: Your Google Gemini API key for language model accessGEMINI_MODEL
: The Gemini model to use (default: gemini-2.0-flash-exp)DAGSTER_CLOUD_API_TOKEN
: (Optional) For Dagster Cloud deployment
Step 2: Launch the Dagster webserver
To make sure Dagster and its dependencies were installed correctly, navigate to the project root directory and start the Dagster webserver:
dg dev
Navigate to http://127.0.0.1:3000 to view the Dagster UI.
Architecture overview
The DsPy pipeline consists of several key components:
Next steps
- Continue this tutorial with puzzle data ingestion