Conversation
… for ChromaDB 1.5.x compatibility ChromaDB 1.5.x calls embedding_function.embed_query(input=...) via keyword argument during collection.query(). EmbeddinggemmaONNX lacked both embed_query and embed_documents methods, causing: TypeError: embed_query() got an unexpected keyword argument 'input' whenever semantic search was triggered. This patch adds the two methods required by the ChromaDB EF protocol, using (the ChromaDB kwarg name, noqa A002) so that palace search works correctly with the embeddinggemma model. Also downloads the companion ONNX file alongside the main model to prevent runtime InferenceSession failures. Fixes silent search failures when is set to embeddinggemma.
There was a problem hiding this comment.
Code Review
This pull request updates mempalace/embedding.py to download the ONNX model data file during lazy loading and adds embed_query and embed_documents methods to support the ChromaDB embedding function protocol. A critical issue was identified in embed_query: if it is called with a single string (as is common in integrations like LangChain), it will iterate over individual characters instead of treating the string as a single input. A suggestion was provided to handle both string and list inputs correctly.
| def embed_query(self, input: list[str]) -> list[list[float]]: # noqa: A002 — ChromaDB EF protocol | ||
| """Embed query documents (ChromaDB EF protocol).""" | ||
| return self(input) |
There was a problem hiding this comment.
If embed_query is called with a single string (which is the standard signature for embed_query in LangChain and other common integrations), input will be a str instead of a list[str].
Since EmbeddinggemmaONNX.__call__ expects an iterable of strings, passing a single string will cause Python to iterate over its individual characters.
| def embed_query(self, input: list[str]) -> list[list[float]]: # noqa: A002 — ChromaDB EF protocol | |
| """Embed query documents (ChromaDB EF protocol).""" | |
| return self(input) | |
| def embed_query(self, input: str | list[str]) -> list[float] | list[list[float]]: # noqa: A002 — ChromaDB EF protocol | |
| """Embed query documents (ChromaDB EF protocol).""" | |
| if isinstance(input, str): | |
| return self([input])[0] | |
| return self(input) |
…eights + tokenizer) The EmbeddinggemmaONNX lazy-load now fetches the ONNX external-weights file (model.onnx_data) in addition to the model graph and tokenizer, so a single warm-up issues 3 downloads, not 2. The lazy-load-once invariant is unchanged (InferenceSession and Tokenizer.from_file are still each built exactly once).
|
Maintainer push: added one commit ( |
Bug
ChromaDB 1.5.x calls
embedding_function.embed_query(input=...)via keyword argument duringcollection.query().EmbeddinggemmaONNXlacked bothembed_queryandembed_documentsmethods, causing:whenever semantic search was triggered.
Fix
This PR adds the two methods required by the ChromaDB EF protocol, using
input(the ChromaDB kwarg name, noqa A002) so that palace search works correctly with theembeddinggemmamodel.Also downloads the companion
_dataONNX file alongside the main model to prevent runtime InferenceSession failures.Related
Fixes silent search failures when
embedding_modelis set to"embeddinggemma".