Skip to content

fix(client): keep embedding type when updating the current generation - #2147

Open
caiotheodoro wants to merge 1 commit into
langfuse:mainfrom
caiotheodoro:fix/update-current-generation-embedding-type
Open

caiotheodoro wants to merge 1 commit into
langfuse:mainfrom
caiotheodoro:fix/update-current-generation-embedding-type

Conversation

@caiotheodoro

@caiotheodoro caiotheodoro commented Nov 22, 2026 •

Copy link
Copy Markdown

What does this PR do?

update_current_generation() always wraps the current span in LangfuseGeneration, whose constructor sets the observation type to "generation". Inside an as_type="embedding" observation, that turns the embedding into a generation unless a later update writes the type again. You see it with start_as_current_observation(as_type="embedding") or @observe(as_type="embedding", capture_output=False).

Generation-like types (generation, embedding) now keep their class, which is what update_current_span() has done since #1705. Other types still become "generation".

Fixes langfuse/langfuse#11187

Type of change

  • Bug fix

Verification

  • A new test in tests/unit/test_observe.py fails on main ('generation' == 'embedding') and passes here.
  • uv run --frozen pytest -n auto tests/unit: 1038 passed. test_prompt.py needs the LANGFUSE_* env vars, same as on main.
  • ruff check, ruff format --check and mypy langfuse are clean.

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I did not hand-edit generated files.
  • I did not commit secrets or credentials.

Drafted with Devin (Claude Opus 5.5, SWE-2).

update_current_generation() wrapped the active span in LangfuseGeneration,
whose constructor writes langfuse.observation.type = "generation". Inside an
embedding observation that overwrote "embedding" with "generation" whenever no
later update re-set the type, e.g. start_as_current_observation(
as_type="embedding") or @observe(as_type="embedding", capture_output=False).

Generation-like types now keep their wrapper class, as update_current_span()
already does since langfuse#1705. Other types still become "generation", so model and
usage keep being recorded there.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

This branch has not been deployed

No deployments
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.

feat(sdk-python): add update_current_embedding func

1 participant