fix(cross_ontology_search): embed cache, strict cosine, early qv=None return, hardware comment#561
Merged
Merged
Conversation
… strict cosine, early return on qv=None
Copilot
AI
changed the title
[WIP] Fix typo in GPU designation comment
fix(cross_ontology_search): embed cache, strict cosine, early qv=None return, hardware comment
Jun 29, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves metpo/pipeline/cross_ontology_search.py by reducing redundant embedding calls, tightening cosine similarity correctness, and improving behavior when embedding is unavailable, while also clarifying a hardware-related comment.
Changes:
- Add an in-process embedding cache to deduplicate repeated Ollama
/api/embeddingsrequests within a run. - Make
cosine()strict about vector dimension mismatches (explicit check +zip(..., strict=True)). - If the query embedding fails (
qv is None), immediately fall back to lexical ranking instead of embedding every candidate and assigning misleading0.0similarities.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Four independent improvements to
metpo/pipeline/cross_ontology_search.pyaddressing correctness, performance, and clarity.Changes
Comment — replace
"M5 GPU"with"CPU/GPU-capable hardware"; the original reference was ambiguous/non-standardEmbedding cache — add module-level
_EMBED_CACHEand_get_cached_embedding()to deduplicate Ollama API calls within a run; previously the same text (e.g. a label shared across multiple terms) would trigger a fresh HTTP round-trip each timeStrict
cosine()— explicit dimension-mismatch check raisesValueErrorbefore the dot product;zip()upgraded tostrict=Trueas a belt-and-suspenders guard; mismatched vectors were previously silently truncatedEarly return on
qv = Noneinrank_candidates()** — when the query embedding fails, fall back immediately to lexical ranking instead of looping over all candidates, callingembed()for each, and assigning misleading0.0scores; also drops the now-redundantqv andfrom the per-candidate guardOriginal prompt