Skip to content

docs: dspy integration blog#34

Merged
ajbozarth merged 14 commits intogenerative-computing:mainfrom
akihikokuroda:dspy
May 6, 2026
Merged

docs: dspy integration blog#34
ajbozarth merged 14 commits intogenerative-computing:mainfrom
akihikokuroda:dspy

Conversation

@akihikokuroda
Copy link
Copy Markdown
Member

@akihikokuroda akihikokuroda commented May 1, 2026

dspy integration blog

/schedule 2026-05-06

Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
@akihikokuroda akihikokuroda requested review from a team and ajbozarth as code owners May 1, 2026 20:09
@akihikokuroda akihikokuroda requested a review from planetf1 May 1, 2026 20:09
@akihikokuroda akihikokuroda marked this pull request as draft May 1, 2026 20:09
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Copy link
Copy Markdown
Contributor

@ajbozarth ajbozarth left a comment

Choose a reason for hiding this comment

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

Great start, here's a few items to address:

There's a typo in the file name: dspy-inegration.md -> dspy-integration.md

Comment thread content/blogs/dspy-inegration.md Outdated
Comment thread content/blogs/dspy-inegration.md Outdated
Comment thread content/blogs/dspy-inegration.md Outdated
Comment thread content/blogs/dspy-inegration.md Outdated
Copy link
Copy Markdown
Contributor

@ajbozarth ajbozarth left a comment

Choose a reason for hiding this comment

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

I ran the code snippets as well and got the following additional notes:

Comment thread content/blogs/dspy-inegration.md Outdated
Comment thread content/blogs/dspy-inegration.md
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Comment thread content/blogs/dspy-integration.md Outdated
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
@akihikokuroda akihikokuroda marked this pull request as ready for review May 4, 2026 12:38
Copy link
Copy Markdown
Contributor

@ajbozarth ajbozarth left a comment

Choose a reason for hiding this comment

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

model="mellea-ollama" appears in 12 of the 15 code examples. Per the source, this parameter is metadata only — it doesn't select the Ollama backend; the actual model comes from start_session() configuration. Suggest dropping it from all examples (the default "mellea" is fine) to avoid implying it matters.

Comment thread content/blogs/dspy-integration.md Outdated
Comment thread content/blogs/dspy-integration.md Outdated
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Copy link
Copy Markdown
Contributor

@ajbozarth ajbozarth left a comment

Choose a reason for hiding this comment

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

This LGTM, if #35 is merged we can add /schedule 2026-05-06 to the description to let this auto-merge on Wednesday.

Copy link
Copy Markdown
Collaborator

@planetf1 planetf1 left a comment

Choose a reason for hiding this comment

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

Tested with mellea_dspy==0.1.0 and dspy on Python 3.12. Five findings below — two code-correctness items (A, B) and three reader-experience gaps (C–E). None repeats prior comments.

Comment thread content/blogs/dspy-integration.md
Comment thread content/blogs/dspy-integration.md Outdated
Comment thread content/blogs/dspy-integration.md
Comment thread content/blogs/dspy-integration.md
Comment thread content/blogs/dspy-integration.md
Copy link
Copy Markdown
Collaborator

@planetf1 planetf1 left a comment

Choose a reason for hiding this comment

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

Narrative nit — a short 'which to pick' paragraph at the end of the feature tour.

Comment thread content/blogs/dspy-integration.md
@ajbozarth ajbozarth self-requested a review May 5, 2026 16:32
Copy link
Copy Markdown
Contributor

@ajbozarth ajbozarth left a comment

Choose a reason for hiding this comment

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

removing my approval for now, at least until @planetf1 's blocker is addressed

Copy link
Copy Markdown
Collaborator

@planetf1 planetf1 left a comment

Choose a reason for hiding this comment

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

Just the one blocker with the sample code that should be addressed - otherwise just nits/style comments

Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Comment thread content/blogs/dspy-integration.md
@ajbozarth
Copy link
Copy Markdown
Contributor

@akihikokuroda a couple follow ups, but otherwise all of @planetf1 review items have been addressed

Comment thread content/blogs/dspy-integration.md Outdated
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Comment thread content/blogs/dspy-integration.md Outdated
akihikokuroda and others added 2 commits May 5, 2026 14:58
Co-authored-by: Alex Bozarth <ajbozart@us.ibm.com>
Co-authored-by: Alex Bozarth <ajbozart@us.ibm.com>
@planetf1
Copy link
Copy Markdown
Collaborator

planetf1 commented May 5, 2026

Thanks @ajbozarth for the response above -- I think there's still a remaining issue.

MelleaBestOfN / MelleaRefine use verification.py in mellea_dspy which is rule based. So only requirements that match explicit patterns are enforced - for example:

  - "Must be under X words" / "at least X" / "between X and Y" / "under X characters"
  - "Must mention X" / "Must include X" / "Must not mention X"
  - "Must be in bullet points" / "numbered list" / "valid JSON"
  - "Must be concise" / "detailed" / "professional"

there's a default case of _create_default_reward which does a substring match

In our BestOfN example, two phrases are used : Must be one word and Must be a proper noun. These aren't rule-matched by the list above - so fall through the default case - so the threshold check is pointless. I think this is only working because the model happens to be answering tersely - it is not a reproducible pattern which we need in an example?

There's also the Refine example which uses Must be under 50 words -- that works great as there's a _create_max_words_reward, but then we have Must mention AI and validation which extracts as ai and validation with a substring match - ie doesn't.

So this is about a concern there are silient errors and/or not showing fully how the requirement works -- even though running it, it looks as if it might work

@planetf1
Copy link
Copy Markdown
Collaborator

planetf1 commented May 5, 2026

This could work for BestOfN

Complete fixed BestOfN snippet — combining the session-state restore with handled requirement patterns:

import dspy
from mellea import start_session
from mellea_dspy import MelleaLM, MelleaBestOfN

m = start_session()
dspy.configure(lm=MelleaLM(mellea_session=m))  # neutral global LM, no inherited requirements

qa = dspy.ChainOfThought("question -> answer")

best_of_5 = MelleaBestOfN(
    module=qa,
    N=5,
    requirements=[
        "Must be under 3 words",      # routes to _create_max_words_reward
        "Must be professional",       # routes to _create_professional_reward
    ],
    threshold=0.8,
)

result = best_of_5(question="What is the capital of Belgium?")
print(result.answer)
# Brussels

Maybe also add an explanation of BestForN about the fact we're just pattern checking (in verification.py)

For the Refine example, we just need to correct the phrase

requirements=[
    "Must be under 50 words",
    "Must mention AI",              # single term — extracts "ai", substring match
],

Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Copy link
Copy Markdown
Collaborator

@planetf1 planetf1 left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the last batch of fixes - tested code execution and it's working as described!

@github-actions github-actions Bot added this pull request to the merge queue May 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Scheduled merge for 2026-05-06 — added to the merge queue.

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks May 6, 2026
@ajbozarth ajbozarth added this pull request to the merge queue May 6, 2026
Merged via the queue into generative-computing:main with commit dd28699 May 6, 2026
6 checks passed
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.

3 participants