docs(embedding): warn custom-EF authors about chromadb 1.5+ embed_query requirement#80
Merged
Merged
Conversation
3 tasks
…ry requirement Defensive doc comment in ``mempalace/embedding.py`` flagging the chromadb 1.5+ ``EmbeddingFunction.embed_query`` requirement for any custom encoder. ``Collection.upsert`` works via ``__call__``; ``Collection.query(query_texts=...)`` requires ``embed_query``. Without inheritance from ``chromadb.api.types.EmbeddingFunction``, queries raise ``AttributeError`` and mempalace's searcher silently falls back to BM25 — invisible failure mode. Diagnosed against a SentenceTransformer adaptmem FT-Code wrapper that produced byte-identical ranks across two different fine-tuned checkpoints (BM25 fallback). Fix: subclass ``EmbeddingFunction``. See MemPalace#1384 for the encoder-axis discussion that surfaced this. Our internal ``_MempalaceONNX`` (already subclasses ONNXMiniLM_L6_V2 which has both methods) is unaffected; the comment is for downstream users who want to drop in a SentenceTransformer or similar without going through ONNXMiniLM_L6_V2. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
caa8eb9 to
35a625b
Compare
This was referenced May 27, 2026
perf(search): make graph-expand cypher directional in hybrid candidate strategy — ~100× speedup
#291
Closed
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
Adds a defensive doc comment in `mempalace/embedding.py` flagging a chromadb 1.5+ EF-protocol gotcha that's easy to fall into when implementing a custom embedding function.
The trap, condensed
Fix (one base class)
`EmbeddingFunction` provides a default `embed_query` that delegates to `call`, which is the right thing for most custom encoders. Override for asymmetric query/document encoders.
How we found this
Cross-encoder fusion verifier (techempower-org/mempalace#77) produced byte-identical per-probe ranks across two genuinely different SentenceTransformer fine-tunes. Direct `.encode()` on the models showed they were distinct; the EF-wrapped version showed they weren't. Root cause was the silent BM25 fallback above.
This affects anyone who builds a custom `EmbeddingFunction` against mempalace without inheriting from the chromadb base — a common case for SentenceTransformer wrappers (cf. @nakata-app's adaptmem work in MemPalace/mempalace#1384).
What this PR does
Test plan
🤖 Generated with Claude Code