Skip to content

fix: avoid empty embedding decode batches - #2442

Open
remote-controlled-man wants to merge 2 commits into
abetlen:mainfrom
remote-controlled-man:codex/prflow-b198ebf8dfdf
Open

remote-controlled-man wants to merge 2 commits into
abetlen:mainfrom
remote-controlled-man:codex/prflow-b198ebf8dfdf

Conversation

@remote-controlled-man

Copy link
Copy Markdown
Contributor

Empty input lists currently reach llama_decode with no tokens and raise RuntimeError. Texts that tokenize to no tokens can also create empty sequences, so an empty string either fails decoding or produces inconsistent results depending on its position in a batch.

Skip decoding when no sequences were accumulated, and reject tokenless texts with a clear ValueError before adding them to the native batch. Empty lists return no embeddings with zero token usage. Empty strings that tokenize to special tokens remain supported.

Real-model regressions cover embed and create_embedding, pooled and unpooled empty lists, zero-token strings on their own and in either position of a mixed batch, legal empty strings with special tokens, and reuse after empty calls or errors.

Validation:

  • Original implementation with the final regressions: 12 failed, 1 passing control.
  • Fixed focused regressions: 13 passed.
  • make test: 39 passed, including all 13 new regression/control cases.
  • make lint: Ruff checks passed and all 29 Python files passed formatting checks.

Local environment: macOS arm64, Python 3.12.14, native llama.cpp f5e6915c2 built with GGML_NATIVE=OFF (CPU/Accelerate and Metal available). New regressions use CPU model layers and the existing cached Qwen3.5-0.8B and BGE-small fixtures. Other platforms and acceleration backends were not run locally.

AI assistance: Codex helped diagnose, implement, test and independently review this change.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 12:00

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

2 participants