best_engine_ai_helper.catalog module
catalog — load and merge the bundled model catalog with the user’s cache.
The catalog lives in two layers:
The bundled seed (models.yaml in the package root). Hand-maintained, always present, never deleted by auto-refresh.
The user cache (~/.best-engine-ai-helper/catalog_cache.yaml). Written by catalog update; entries keyed by id overwrite matching seed entries. Absent on first run; load_catalog silently skips it in that case.
Keeping the seed immutable and the cache additive means offline machines always have a usable catalog and updates never lose hand-curated data.
- best_engine_ai_helper.catalog.estimate_ram(disk_gb, quant)[source]
Estimate peak inference RAM from on-disk model size.
The estimate covers the model weights plus KV cache at the default context length (4K tokens). For models with very large context windows (256K+), actual RAM may exceed this estimate significantly; treat it as a lower bound.
- Parameters:
- Returns:
Estimated peak RAM in GB.
- Return type:
Examples
>>> estimate_ram(6.1, 'Q4_K_M') 6.832 >>> estimate_ram(10.0, 'FP16') 10.5
- best_engine_ai_helper.catalog.load_catalog(catalog_path=None)[source]
Load the bundled seed catalog merged with the user’s local cache.
Cache entries whose id matches a seed entry overwrite the seed entry. New cache entries (no matching seed id) are appended. The seed is never modified on disk.
- Parameters:
catalog_path (Path or None) – Path to the seed models.yaml. Defaults to the bundled file next to pyproject.toml. Pass an explicit path in tests to use a fixture.
- Returns:
Merged model entries. Each entry is guaranteed to have at minimum:
id,kind,ram_gb,benchmarks.- Return type:
- Raises:
FileNotFoundError – If
catalog_pathis given explicitly and does not exist.
Examples
>>> entries = load_catalog() >>> len(entries) > 0 True >>> all('id' in e for e in entries) True
- best_engine_ai_helper.catalog.normalize_apxml_spec(spec, fetched_at)[source]
Map one ApXML spec dict onto a catalog entry.
The ApXML adapter (
best_engine_ai_helper.sources.apxml) yields spec and memory-fit metadata but no numeric benchmarks, so thebenchmarksblock is left null.disk_gbis estimated from the Q4 VRAM figure by dividing out the quant overhead — the inverse ofestimate_ram().- Parameters:
- Returns:
A catalog entry, or None when the spec lacks the
slugneeded to key it (such an entry could never be merged or pulled).- Return type:
- best_engine_ai_helper.catalog.normalize_apxml_specs(specs, fetched_at=None)[source]
Normalize a batch of ApXML specs into catalog entries, dropping unusable ones.
- best_engine_ai_helper.catalog.write_cache(entries, cache_path=None)[source]
Merge
entriesinto the user catalog cache byidand write it to disk.Existing cache entries are preserved; an incoming entry whose
idmatches one already cached overwrites it, so a refresh is idempotent and never loses previously cached models. The bundled seed is untouched.- Parameters:
entries (list[dict[str, Any]]) – Catalog entries to add or update, e.g. from
normalize_apxml_specs().cache_path (Path or None) – Destination cache file. Defaults to
CACHE_PATH; override in tests.
- Returns:
The path written.
- Return type:
Path