api.services.catalog_index¶
In-memory index of the Airtable catalog (brands, equipment types, Models with their dimensions, Variations with how many units they have) to rank which existing Référence variant a received item most likely is, before any AI is involved; the AI then decides within that shortlist.
Loaded once and refreshed in the background when older than
INDEX_TTL_SECONDS (about 40 Airtable pages); invalidate() after
creating records.
Attributes¶
Classes¶
Functions¶
|
Lowercase, no accents nor punctuation: "Mikro 220 R" ~ "mikro-220r". |
|
|
|
0-1 between two normalized strings; containment counts a lot. |
|
|
|
The index; loaded on first use, refreshed in the background when stale. |
|
After creating records: next use reloads in the background. |
|
Tests. |
Module Contents¶
- api.services.catalog_index.logger¶
- api.services.catalog_index.INDEX_TTL_SECONDS = 900¶
- api.services.catalog_index.BRAND_TABLE = 'Marque'¶
- api.services.catalog_index.FAMILLE_TABLE = 'Familles'¶
- api.services.catalog_index.WEIGHTS¶
- api.services.catalog_index.normalize(text: str | None) str¶
Lowercase, no accents nor punctuation: “Mikro 220 R” ~ “mikro-220r”.
- api.services.catalog_index.words(text: str | None) set[str]¶
- api.services.catalog_index.similarity(a: str, b: str) float¶
0-1 between two normalized strings; containment counts a lot.
- class api.services.catalog_index.Model¶
- id: str¶
- modele: str¶
- brand_id: str | None¶
- brand_name: str | None¶
- type_id: str | None¶
- type_name: str | None¶
- dims: dict[str, float | None]¶
- variation_ids: list[str] = []¶
- property key: str¶
- class api.services.catalog_index.Variation¶
- id: str¶
- name: str¶
- model_id: str | None¶
- is_variant: bool¶
- variant_value: str | None¶
- status: str | None¶
- units: int¶
- sale_price: float | None = None¶
- buy_price: float | None = None¶
- class api.services.catalog_index.CatalogIndex¶
- brands: dict[str, str]¶
- types: dict[str, dict[str, Any]]¶
- familles: dict[str, str]¶
- rank_variations(identity: dict[str, Any], limit: int = 12) list[dict[str, Any]]¶
Existing Variations scored against what is known of the item: brand, model reference, label text, product name, popularity.
- rank_brands(*names: str | None, text: str = '', limit: int = 3) list[dict]¶
- rank_models(reference: str | None, brand_ids: list[str] | None = None, limit: int = 3) list[dict]¶
- rank_types(*names: str | None, limit: int = 3) list[dict]¶
- candidate(model: Model, variation_ids: list[str] | None = None) dict[str, Any]¶
A Model with its Variations, as the app’s search lists them.
- search_models(query: str, limit: int = 10) list[dict[str, Any]]¶
Models matching a free-text search over brand, reference, equipment type and variation names: every word must match (whole word, start of a word, inside a word, or a close spelling), in any order; the most relevant first (“Rotor”, “2424” and “rotor 2424” all find Rotor 2424).
- suggest_models(identity: dict[str, Any], limit: int = 3) list[dict[str, Any]]¶
Suggestions from what is known of the item (no query): its best ranked Variations, each shown as its Model with that Variation.
- model_prices(model_ids: list[str]) dict[str, dict[str, Any]]¶
Per known Model: its name and the mean of its Variations’ sale and advised buy prices (None when no Variation has one).
- brand_by_name(name: str | None) tuple[str, str] | None¶
- type_by_name(name: str | None) tuple[str, dict[str, Any]] | None¶
- api.services.catalog_index.load_index(fetch: collections.abc.Callable[..., list[dict[str, Any]]] = airtable.list_records) CatalogIndex¶
- api.services.catalog_index.get_index() CatalogIndex¶
The index; loaded on first use, refreshed in the background when stale.
- api.services.catalog_index.invalidate() None¶
After creating records: next use reloads in the background.
- api.services.catalog_index.set_index(index: CatalogIndex | None) None¶
Tests.