Skip to content

fix(python): end Harrier inputs with <eos> so semantic recall works - #708

Merged
p-diogo merged 1 commit into
mainfrom
fix/python-embedding-eos
Nov 1, 2026
Merged

p-diogo merged 1 commit into
mainfrom
fix/python-embedding-eos

Conversation

@p-diogo

@p-diogo p-diogo commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Harrier (harrier-oss-v1-270m) pools the last token, so every input must end with <eos>. The ONNX repo's tokenizer_config.json has no add_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 reads tokenizer.json directly and adds <eos>, so the TS clients were fine.

  • Loader passes add_eos_token=True to AutoTokenizer.from_pretrained.
  • get_embedding appends <eos> itself if a transformers version ignores the flag (overwrites the last token at the 512 limit).
  • Docstring explains why.

Evidence

Measured on a 13-fact vault, 12 queries (offline) and on a throwaway staging account (end-to-end):

Right fact ranked first
No <eos> (shipped) 4/12 ("vegetarian" put "User is vegetarian." 11th of 13)
With <eos> (q4, quantized, fp32 all agree) 12/12
Staging e2e, 5 phrasings of the QA's diet question 0/5 → 5/5

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.
  • Full suite: 2742 passed, 26 skipped, 1 xfailed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Bd3G1BkVMFSXkcdAQ7nFax

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
@p-diogo
p-diogo merged commit 9ed2364 into main Nov 1, 2026
12 checks passed
@p-diogo
p-diogo deleted the fix/python-embedding-eos branch November 1, 2026 23:11
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