Repository navigation
fix(python): end Harrier inputs with <eos> so semantic recall works - #708
Merged
Merged
Conversation
Harrier pools the last token. The ONNX repo's tokenizer config omits add_eos_token and transformers' Gemma tokenizer then drops <eos>, so every Python embedding was the last word's state: recall ranked the right fact first for 4 of 12 test questions. The TS clients already appended <eos>. Python output now matches theirs (cosine 1.0000). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bd3G1BkVMFSXkcdAQ7nFax
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.
Summary
Harrier (
harrier-oss-v1-270m) pools the last token, so every input must end with<eos>. The ONNX repo'stokenizer_config.jsonhas noadd_eos_token, and transformers' Gemma tokenizer rebuilds its post-processor from that flag, so the Python client tokenized"hello world"as[2, 23391, 1902]. The vector was effectively the last word's hidden state. transformers.js readstokenizer.jsondirectly and adds<eos>, so the TS clients were fine.add_eos_token=TruetoAutoTokenizer.from_pretrained.get_embeddingappends<eos>itself if a transformers version ignores the flag (overwrites the last token at the 512 limit).Evidence
Measured on a 13-fact vault, 12 queries (offline) and on a throwaway staging account (end-to-end):
<eos>(shipped)<eos>(q4, quantized, fp32 all agree)Also affects near-duplicate and contradiction checks, which use the same embeddings.
Tests
tests/test_embedding_eos.py(new, runs in CI, no model): appends EOS when dropped, leaves it when present, full-length input, loader passes the flag. 3 of 4 fail on the old code.tests/test_embedding.py::TestRetrievalQuality(model-dependent, skipped in CI): passed on a machine with the model.🤖 Generated with Claude Code
https://claude.ai/code/session_01Bd3G1BkVMFSXkcdAQ7nFax