Skip to content

Serf framework long-shot plan#14

Draft
rjurney wants to merge 3 commits intomainfrom
cursor/serf-framework-long-shot-plan-2439
Draft

Serf framework long-shot plan#14
rjurney wants to merge 3 commits intomainfrom
cursor/serf-framework-long-shot-plan-2439

Conversation

@rjurney
Copy link
Contributor

@rjurney rjurney commented Mar 8, 2026

Update branch to origin/rjurney/v0.1 to incorporate latest changes for BAML and Gemini API limitations.

This update ensures the research phase and subsequent implementation are based on the most current codebase, as requested by the user.


Open in Web Open in Cursor 

rjurney added 2 commits March 7, 2026 19:24
Gemini 2.0 Flash only for all ER pipeline operations. Gemini 2.5 Pro
allowed only for validation data generation with < 2K API calls.
Do not reuse Abzu's BAML-generated types. Build fresh domain-agnostic
Pydantic classes for DSPy signatures. Add auto-generation of entity
types from PySpark DataFrame schemas via type_generator module. Add
Spark-to-Python type mapping and DatasetProfile-driven field descriptions.
@cursor
Copy link

cursor bot commented Mar 8, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the long-term plan document for the SERF framework, incorporating crucial architectural decisions regarding its type system and external API usage. The changes detail a shift towards a more flexible, domain-agnostic Pydantic type system with automated generation capabilities, and establish clear budget constraints for Gemini API consumption, ensuring the project's development aligns with current best practices and resource management.

Highlights

  • Type System Redesign: The plan for the SERF framework's type system has been significantly revised to explicitly avoid reusing BAML-generated types from Abzu. Instead, it now emphasizes creating fresh, domain-agnostic Pydantic types specifically for DSPy signatures and introduces a mechanism for auto-generating entity types directly from PySpark DataFrames.
  • New File Introductions: The plan now includes the creation of src/serf/dspy/type_generator.py to handle the automatic generation of Pydantic entity types from DataFrame schemas, along with its corresponding unit test file, tests/test_type_generator.py.
  • Gemini API Budget Constraints: A new section has been added outlining a hard budget of $100 for Gemini API spend during overnight builds, specifying the exclusive use of Gemini 2.0 Flash for pipeline operations and limited use of Gemini 2.5 Pro for validation data generation.
  • SparkDantic Schema Bridge Enhancement: The description of the SparkDantic schema bridge has been updated to clarify its bidirectional functionality, supporting both Pydantic-to-Spark for writing and Spark-to-Pydantic for auto-generating entity types from input DataFrames.
Changelog
  • docs/SERF_LONG_SHOT_PLAN.md
    • Updated the description of the SparkDantic schema bridge to include bidirectional Pydantic-to-Spark and Spark-to-Pydantic type generation.
    • Revised the 'Patterns to Evolve in SERF' section, explicitly stating that Abzu's BAML-generated types should not be reused and adding a new pattern for auto-generating entity types from DataFrames.
    • Modified the file structure section to reflect that types.py will be rewritten and type_generator.py will be a new file.
    • Added test_type_generator.py to the list of planned test files.
    • Inserted an important note emphasizing that SERF will not reuse Abzu's BAML-generated types and will build fresh Pydantic types for DSPy.
    • Expanded the docstring for the Entity base class to clarify the placement of domain-specific fields and fixed ER metadata fields.
    • Clarified that specialized entity types are examples and users can define their own or use auto-generated ones.
    • Introduced a new sub-section '5.1.1 Auto-Generating Entity Types from DataFrames', detailing the process and providing a function signature and type mapping table.
    • Updated the description for 'Phase 2: Schema Alignment + Matching + Merging' to mention that schema_info is auto-generated from Pydantic entity types.
    • Refined the schema_info field description within the BlockMatch DSPy signature to specify its auto-generated nature.
    • Added a new section '9.6 Overnight Build Budget Constraint' outlining Gemini API usage rules and cost limits.
    • Adjusted the estimated time for 'Step 2: Core Type System' in the implementation plan from 1 hour to 1.5 hours.
    • Updated the details for 'Step 2: Core Type System' to include rewriting types.py from scratch, creating type_generator.py, and expanding unit tests to cover the new type generator.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the SERF_LONG_SHOT_PLAN.md document to refine the implementation plan. Key changes include clarifying the move from BAML to fresh DSPy Pydantic types, introducing a feature to auto-generate entity types from DataFrames, and adding a detailed section on budget constraints for Gemini API usage. The changes make the plan more specific and actionable. My review focuses on a potential issue in the new budget constraint section, where non-standard Gemini model names are used. I've suggested correcting these to align with publicly available models to prevent confusion during implementation. Overall, the updates are a significant improvement to the plan.

Note: Security Review has been skipped due to the limited scope of the PR.

Comment on lines +854 to +866
1. **Use Gemini 2.0 Flash exclusively** for all ER pipeline operations (blocking analysis, matching, merging, edge resolution). At $0.10/$0.40 per 1M input/output tokens, this allows ~160M+ input tokens -- more than enough for iterative ER across all three benchmark datasets.

2. **Gemini 2.5 Pro is allowed ONLY for generating validation data** -- high-quality labeled match/non-match pairs and few-shot examples that will be used to evaluate and optimize the pipeline. Limit Gemini 2.5 Pro to **fewer than 2,000 API calls** total. At ~2,500 tokens per call with $1.25/$10.00 per 1M input/output tokens, 2K calls costs roughly $50 -- leaving ample headroom for Flash usage.

3. **Never use Claude, GPT-4o, or any non-Gemini model** for pipeline operations during the build. The DSPy signatures and pipeline code should be model-agnostic, but all actual LLM calls during this build session must go through Gemini.

4. **Track token usage** by logging input/output token counts from API responses. If cumulative spend approaches $80, stop making Gemini 2.5 Pro calls and finish remaining work with Flash only.

| Use Case | Model | Max Calls | Est. Cost |
| ------------------------------ | ---------------- | ------------------------- | ---------- |
| ER pipeline (match/merge/edge) | Gemini 2.0 Flash | Unlimited (within budget) | ~$10-30 |
| Validation data generation | Gemini 2.5 Pro | < 2,000 | ~$50 |
| **Total** | | | **< $100** |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The model names "Gemini 2.0 Flash" and "Gemini 2.5 Pro" used in this section do not seem to correspond to publicly available Google models. This is likely a typo for "Gemini 1.5 Flash" and "Gemini 1.5 Pro", respectively. Using incorrect model names could cause errors during implementation when the agent attempts to make API calls.

Additionally, the pricing mentioned for these models seems to be custom or not aligned with current public pricing. For the budget constraints to be effective, it's crucial to use the correct model names and their corresponding up-to-date pricing.

Please consider updating the model names and verifying the pricing information throughout this section.

Suggested change
1. **Use Gemini 2.0 Flash exclusively** for all ER pipeline operations (blocking analysis, matching, merging, edge resolution). At $0.10/$0.40 per 1M input/output tokens, this allows ~160M+ input tokens -- more than enough for iterative ER across all three benchmark datasets.
2. **Gemini 2.5 Pro is allowed ONLY for generating validation data** -- high-quality labeled match/non-match pairs and few-shot examples that will be used to evaluate and optimize the pipeline. Limit Gemini 2.5 Pro to **fewer than 2,000 API calls** total. At ~2,500 tokens per call with $1.25/$10.00 per 1M input/output tokens, 2K calls costs roughly $50 -- leaving ample headroom for Flash usage.
3. **Never use Claude, GPT-4o, or any non-Gemini model** for pipeline operations during the build. The DSPy signatures and pipeline code should be model-agnostic, but all actual LLM calls during this build session must go through Gemini.
4. **Track token usage** by logging input/output token counts from API responses. If cumulative spend approaches $80, stop making Gemini 2.5 Pro calls and finish remaining work with Flash only.
| Use Case | Model | Max Calls | Est. Cost |
| ------------------------------ | ---------------- | ------------------------- | ---------- |
| ER pipeline (match/merge/edge) | Gemini 2.0 Flash | Unlimited (within budget) | ~$10-30 |
| Validation data generation | Gemini 2.5 Pro | < 2,000 | ~$50 |
| **Total** | | | **< $100** |
1. **Use Gemini 1.5 Flash exclusively** for all ER pipeline operations (blocking analysis, matching, merging, edge resolution). At $0.10/$0.40 per 1M input/output tokens, this allows ~160M+ input tokens -- more than enough for iterative ER across all three benchmark datasets.
2. **Gemini 1.5 Pro is allowed ONLY for generating validation data** -- high-quality labeled match/non-match pairs and few-shot examples that will be used to evaluate and optimize the pipeline. Limit Gemini 1.5 Pro to **fewer than 2,000 API calls** total. At ~2,500 tokens per call with $1.25/$10.00 per 1M input/output tokens, 2K calls costs roughly $50 -- leaving ample headroom for Flash usage.
3. **Never use Claude, GPT-4o, or any non-Gemini model** for pipeline operations during the build. The DSPy signatures and pipeline code should be model-agnostic, but all actual LLM calls during this build session must go through Gemini.
4. **Track token usage** by logging input/output token counts from API responses. If cumulative spend approaches $80, stop making Gemini 1.5 Pro calls and finish remaining work with Flash only.
| Use Case | Model | Max Calls | Est. Cost |
| ------------------------------ | ---------------- | ------------------------- | ---------- |
| ER pipeline (match/merge/edge) | Gemini 1.5 Flash | Unlimited (within budget) | ~$10-30 |
| Validation data generation | Gemini 1.5 Pro | < 2,000 | ~$50 |
| **Total** | | | **< $100** |

Co-authored-by: Russell Jurney <rjurney@users.noreply.github.com>
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