Skip to content

fix: guard non-causal embeddings against oversized batches - #678

Open
AvrovaDonz2026 wants to merge 1 commit into
withcatai:masterfrom
AvrovaDonz2026:fix/embedding-batch-size-guard
Open

AvrovaDonz2026 wants to merge 1 commit into
withcatai:masterfrom
AvrovaDonz2026:fix/embedding-batch-size-guard

Conversation

@AvrovaDonz2026

Copy link
Copy Markdown

Description of change

For non-causal embedding models, getEmbeddingFor() now rejects inputs whose tokenized
length exceeds the context batchSize before evaluation. Non-causal attention cannot
produce a whole-input embedding when the input is split across decode batches; the
previous behavior silently returned divergent vectors. Causal models keep their existing
behavior.

Fixes #674

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply eslint formatting
  • npm run test passes with this change (the full model-dependent suite was not run)
  • This pull request links relevant issues as Fixes #674
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change (N/A: the error is actionable)
  • The new commits and pull request title follow conventions explained in pull request guidelines

Verification

  • npm run build
  • npm run test:typescript
  • npm run lint:eslint
  • npx vitest run ./test/modelDependent/nomicEmbedText/embedding.test.ts (5/5 passed)
  • npx vitest run ./test/standalone/gguf/ggufStandaloneParser.test.ts --testTimeout=60000 (3/3 passed)

Reject inputs longer than the context batch size before evaluation when the model uses non-causal attention. This avoids returning divergent embeddings for inputs that fit in the context but cannot be evaluated in one batch.

Add a Nomic embedding regression test covering the default batch size.

Closes: withcatai#674

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.

bug: Embeddings from non-causal models silently diverge when the input is longer than the context's batch size

1 participant