Formats¶
siglip2_toolkit.formats ¶
Embeddings export format (v2): specification and read/write helpers.
An export file is a sequence of objects, optionally preceded by a header::
{"format": "siglip2-export", "version": 2,
"embedding_space": {"model": "...", "dimensions": 768, "normalization": "l2"},
"created_at": "2026-10-17T12:00:00+00:00"}
{"id": "/photos/a.jpg", "vector": [...], "metadata": {...}}
{"id": "/photos/b.jpg", "vector": [...]}
...
jsonl files store one object per line; pkl files store a sequence of
pickled objects. Record-only files (written before format v2) are still
readable.
A record carries its identity in id (any stable string; the exporter
uses the absolute image path). metadata is optional and free-form: store
EXIF, timestamps, tags — or nothing at all. Records without an id fall
back to metadata["path"] when read back.
This is an interchange format, not a database: consumers load the vectors with whatever tool they prefer (a vector store, numpy, another pipeline).
EmbeddingSpace
dataclass
¶
Identity of the vector space produced by an embedder.
Two vectors are only comparable when they were produced by the same model (and the same preprocessing). This manifest is stored in the export header so consumers can detect mismatches.
make_record ¶
Build an export record.
id identifies the vector (enable it for incremental updates and
deduplication); metadata is optional and may hold any
JSON-serializable data.
infer_format ¶
Infer the export format (jsonl or pkl) from a file name.
Temporary suffixes (.tmp/.part) are stripped first, so the
interrupted-run convention <export>.jsonl.tmp also resolves.
load_by_id ¶
Load an export file into a dictionary keyed by record id.
Records without an id (neither id nor a legacy metadata.path) are
skipped with a warning. Later duplicates win, matching the behaviour of
incremental runs.
write_export ¶
Write records (with a header) to a new export file.
The file is created (or fully rewritten); parent directories are created
as needed. A format header is always written; pass
embedding_space=None when the space is unknown (e.g. when merging
legacy files).
header_embedding_space ¶
Extract the embedding space manifest from a header, if present.