paper_firehose.core.model_manager

Model management utilities for Sentence-Transformers models.

Handles vendoring (downloading and caching) of transformer models locally to avoid runtime network dependencies in production environments.

Functions

ensure_local_model(model_spec)

Ensure a local model directory exists for the given spec and return the path or original spec.

has_model_files(path)

Heuristic check that a local Sentence-Transformers model folder is valid.

paper_firehose.core.model_manager.ensure_local_model(model_spec)[source]

Ensure a local model directory exists for the given spec and return the path or original spec.

Behavior: - If spec is the default alias ‘all-MiniLM-L6-v2’:

Use ‘models/all-MiniLM-L6-v2’. If missing or empty, download ‘sentence-transformers/all-MiniLM-L6-v2’ into that folder.

  • If spec looks like a repo id (e.g., ‘sentence-transformers/x’ or ‘intfloat/e5-small’):

    Vendor to ‘models/<last-segment>’ when not present or empty.

  • If spec is a local path and valid, return it. If it exists but appears empty, try to infer repo id from the folder name and download into it.

  • On any failure (e.g., no network), return the original spec and let STRanker handle it.

Parameters:

model_spec (str) – Model specification (repo ID, alias, or local path)

Return type:

str

Returns:

Local path to model directory, or original spec if vendoring failed

paper_firehose.core.model_manager.has_model_files(path)[source]

Heuristic check that a local Sentence-Transformers model folder is valid.

Parameters:

path (str) – Path to model directory

Return type:

bool

Returns:

True if the directory appears to contain a valid model