Repository navigation
Add the text deriver, which embeds a segment's text without its trailing whitespace, as the default - #1857
Draft
edwinyyyu wants to merge 4 commits into
Draft
Add the text deriver, which embeds a segment's text without its trailing whitespace, as the default#1857edwinyyyu wants to merge 4 commits into
edwinyyyu wants to merge 4 commits into
Conversation
…xt deriver WholeTextDeriver embedded a segment's text exactly as stored, so the whitespace at its ends went into the quoted text the embedder reads. json.dumps writes a newline as the two characters \n, so a message ending in a newline was embedded with \n inside its quotes. Embed the text without the whitespace at its ends, and give a segment of whitespace alone no derivative. The name changes with the behavior: WholeTextDeriver becomes TrimmedTextDeriver, configured as `trimmed_text`, and it stays the default. `whole_text` is no longer a deriver type. The sentence deriver already strips each sentence and is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Renaming the whole-text deriver broke every configuration that names `whole_text`, and whether to drop it is a separate decision. Restore WholeTextDeriver and `whole_text` unchanged, embedding a segment's text exactly as stored. Add the stripping deriver beside it as TextDeriver, configured as `text`. The name matches the text segmenter and says what the deriver reads, not how it prepares the text, so it stays true if that preparation changes. It embeds a segment's text without the whitespace at its ends and gives a segment of whitespace alone no derivative. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
An event backend that names no deriver now embeds each segment's text without the whitespace at its ends. A configuration that names `whole_text` keeps embedding the text exactly as stored. The sample configurations name the new default and list both alternatives. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
edwinyyyu
marked this pull request as ready for review
October 23, 2026 21:17
Contributor
Author
|
This should have a couple of benefits:
Drawbacks:
|
A segment's leading whitespace is the indentation of its first line, and embedders read indentation in code. On a code retrieval set, removing it lowered retrieval with text-embedding-3-small at the default segment length and with Qwen3-Embedding at every length tested, while removing the whitespace at the end lowered retrieval with no embedder tested. Embed the text without the whitespace at its end only. A segment of whitespace alone still has no derivative. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edwinyyyu
marked this pull request as draft
October 30, 2026 22:58
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose of the change
The default deriver embeds a segment's text exactly as stored, including the whitespace at its end. That whitespace carries no content, and because the text is embedded as a JSON string, a trailing newline reaches the embedder as the two characters
\ninside the quotes. This change adds a deriver that embeds the text without the whitespace at its end and makes it the default. The whitespace at a segment's start stays: it is the indentation of the segment's first line, which embedders use in code. The existing deriver stays, so configurations that name it keep working.Description
TextDeriver, configured astext, embedstext.rstrip(), keeping leading and inner whitespace, and gives a segment of whitespace alone no derivative. The name matchesTextSegmenter(type: text) and says what the deriver reads, not how it prepares the text, so it stays true if that preparation changes.textbecomes the event backend's default deriver, in its own commit.WholeTextDeriver(whole_text) is unchanged and still embeds the text exactly as stored. Whether to remove it is a separate decision.SentenceTextDeriveris unchanged; it already strips each sentence.Embedded text. Changes for a configuration that names no deriver, wherever a message has whitespace at its end, for example a trailing newline: its derivative now ends at the last non-whitespace character. A message of whitespace alone no longer gets a derivative. Messages without trailing whitespace embed exactly as before, and a configuration that names
whole_textis unaffected.Fixes/Closes
No issue filed.
Type of change
How Has This Been Tested?
Unit Test
test_text_deriver.py:TextDeriverembeds no trailing whitespace, keeps leading and inner whitespace, gives a whitespace-only segment no derivative, and keeps the segment's properties;WholeTextDeriverkeeps edge whitespace.test_configuration.py: the default deriver istext, andtype: textloads.test_service_locator.py: each deriver configuration builds its deriver.Test Results:
uv run --frozen ruff check packages/serveranduv run --frozen ruff format --check packages/server: clean.uv run --frozen --all-extras ty check --project packages/server: clean.uv run --frozen --all-extras pytest -q -p no:cacheprovideron the three test files above: 58 passed (Python 3.14, macOS).Checklist
Maintainer Checklist
Screenshots/Gifs
N/A
Further comments
🤖 Generated with Claude Code