MetaMixin#
- class scikitplot.annoy.MetaMixin[source]#
Mixin that exports and restores index metadata.
The concrete class (or its backend) must implement:
get_params(deep: bool = ...) -> Mapping[str, Any]set_params(**params) -> Self
Optional backend methods:
info() -> Mapping[str, Any] | None
The concrete class must define:
_META_SCHEMA_VERSION(int)
Notes
from_metadata(..., load=True)optionallyloads the on-disk index when theparamsmapping containson_disk_path. This is a deterministic behavior controlled only by explicit fields.- classmethod from_metadata(metadata, *, load=True)[source]#
Construct an index from a metadata payload.
- Parameters:
- metadataMapping[str, Any]
Payload as produced by
to_metadata.- loadbool, default=True
If True and
params['on_disk_path']is present, attempt to load the index into the returned object via backendload.
- Returns:
- indexSelf
Newly constructed index.
- Raises:
- TypeError
If input types are invalid.
- ValueError
If required fields are missing or invalid.
- AttributeError
If backend
set_params/loadare missing when required.
- Parameters:
- Return type:
- classmethod from_yaml(path, *, load=True)[source]#
Load metadata from YAML and construct an index (requires PyYAML).
- to_json(path=None, *, indent=2, sort_keys=True, ensure_ascii=False, include_info=True, strict=True)[source]#
Serialize
to_metadatato JSON.- Parameters:
- path
If provided, write the JSON to this path atomically.
- indent
Indentation level passed to
json.dumps.- sort_keys
If True, sort keys for stable output.
- ensure_ascii
If True, escape non-ASCII characters.
- include_info, strict
Forwarded to
to_metadata.
- Returns:
- json_str
JSON representation of the metadata.
- Parameters:
- Return type:
See also
- to_metadata(*, include_info=True, strict=True)[source]#
Export a serializable metadata payload.
- Parameters:
- include_info
If True, include a backend-provided
info()mapping when available.- strict
If True, backend failures in optional
info()propagation raise.
- Returns:
- metadata
A JSON/YAML-serializable mapping containing configuration parameters and optional info.
- Raises:
- RuntimeError
If
_META_SCHEMA_VERSIONis missing on the concrete class.- TypeError
If backend
get_paramsdoes not return a mapping.- AttributeError
If the backend does not implement
get_params.
- Parameters:
- Return type:
IndexMetadata