aeat.application.corpus_search._query_embed module¶
Runtime query embedder (the live-query half of the R3 semantic stack).
The corpus vectors are precomputed at build time and ship as data
(_embed_build); the model is needed at
runtime ONLY to embed the operator’s live query into the same vector space so a
cosine search can run.
This module owns that one live use of model2vec, behind the capability-
gated aeat-cli[search] extra: absent the extra, search_extra_available()
reports False and the retrieval layer degrades to lexical-only, while
constructing/using a QueryEmbedder refuses with the install hint.
The model download is app-controlled: the cache directory is rooted under the
Settings aeat_local_storage_root (<root>/search-models) rather than the
user’s global Hugging Face cache, so a bundled Desktop Extension keeps its model
state inside the one app state root. The model is loaded lazily on first embed
and cached for the embedder’s lifetime, so repeated queries pay the load once.
- search_extra_available()[source]¶
Return whether the semantic
searchextra (model2vec) is importable.The retrieval layer calls this to decide between hybrid and lexical-only degraded mode WITHOUT triggering a model load or download.
- Return type:
- search_model_cache_dir(settings=None)[source]¶
Return the app-controlled model cache directory under the storage root.
- Return type:
Path- Parameters:
settings (Settings | None)
- class QueryEmbedder(*, model_id='minishlab/potion-multilingual-128M', revision='73908c3438cf03b6a01bcb9611d62b23d0726f08', cache_dir=None, settings=None)[source]¶
Bases:
objectEmbed live queries with the pinned potion static model.
Construction records the model id, pinned revision, and app-controlled cache directory but does NOT load the model; the first
embed_query()loads it (refusing with the install hint when the extra is absent) and caches it for reuse.- embed_query(text)[source]¶
Embed one query string into a 1-D float32 vector.
- Parameters:
text (
str) – The free-text query.- Return type:
ndarray- Returns:
A 1-D float32 numpy vector in the corpus embedding space.
- Raises:
CorpusSearchInputError – If
textis blank.CorpusSearchDependencyError – If the
searchextra is absent.