Skip to content

Never send empty text to the embedder - #1

Merged
sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/empty-side-embeddings
Aug 23, 2026
Merged

sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/empty-side-embeddings

Conversation

@sujal-maheshwari2004

Copy link
Copy Markdown
Contributor

A pure insert has no old text and a pure delete has no new text, and deltaText handed that empty string to the embedder. Real endpoints reject it — TEI answers 413 \inputs` cannot be empty` — so every insert- or delete-shaped hunk failed as soon as a real model was configured. Adding or removing a line is the common edit, so in practice the semantic diff was broken for most changes against a real endpoint.

It went unnoticed because the offline LexicalEmbedder happily embeds "" and returns a zero vector. The fallback masked it completely — and the fallback is what every test until now had run under.

An empty side is a total shift at that point by definition, so it returns 1 directly and makes no embed call.

Measured against BAAI/bge-small-en-v1.5 via TEI, before → after:

edit before after
insert a line mid-prompt Internal: diff failed S2 1.000 → localized tweak
delete a line Internal: diff failed S2 1.000 → structural

Tests use a stub embedder that refuses empty input the way TEI does — the lexical embedder cannot catch this class of bug, which is the whole point.

A pure insert has no old text and a pure delete has no new text, and deltaText
was handing that empty string to the embedder. Real embedding endpoints reject
it — TEI answers "413 `inputs` cannot be empty" — so every insert- or
delete-shaped hunk failed the moment a real model was configured. Adding or
removing a line is the common edit, so in practice the semantic diff was broken
for most changes against a real endpoint.

It went unnoticed because the offline LexicalEmbedder happily embeds "" and
returns a zero vector. The fallback masked it completely, and the fallback is
what every test until now had run under.

An empty side is a total shift at that point by definition — content appeared or
vanished — so it returns 1 directly and makes no embed call at all.

Tests use a stub embedder that refuses empty input the way TEI does, covering
insert, delete, append, delete-at-end and delete-everything. The lexical
embedder cannot catch this class of bug, so the stub is the point.

Measured against BAAI/bge-small-en-v1.5 via TEI, before and after: inserting a
line mid-prompt and deleting a line both went from "Internal: diff failed" to a
verdict.
@sujal-maheshwari2004
sujal-maheshwari2004 merged commit dd0f724 into main Aug 23, 2026
1 check passed
@sujal-maheshwari2004
sujal-maheshwari2004 deleted the fix/empty-side-embeddings branch August 23, 2026 20:24
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.

1 participant