labenv_embedding_cache
Shared policy and Python cache-core library for projects that reuse text embedding caches.
Files
embedding_rulebook.yaml: machine-readable cache policy (path/layout/consistency)embedding_registry.yaml: machine-readable model registry shared across projectsembedding_cache_spec.yaml: machine-readable spec for dataset key / metadata / variant tagsrc/labenv_embedding_cache/: reusable Python libraryCODEX_PROMPT.md: reusable prompt template for Codex sessions
Install library
Preferred distribution is wheel (v0.4.0).
# Internal index (recommended)
pip install "labenv-embedding-cache==0.4.0"
# Optional: explicitly point pip to internal index
# PIP_EXTRA_INDEX_URL="https://<internal-index>/simple" pip install "labenv-embedding-cache==0.4.0"
# GitHub Release wheel fallback
pip install "labenv-embedding-cache @ https://github.com/ryuuua/labenv_embedding_cache/releases/download/v0.4.0/labenv_embedding_cache-0.4.0-py3-none-any.whl"
# Local editable (maintainer workflow)
pip install -e /path/to/labenv_embedding_cache
Rollback-only legacy install (VCS pin):
pip install "git+ssh://git@github.com/ryuuua/labenv_embedding_cache.git@c0154c06ee6e41852c58ac76d6504f5b38d20168#egg=labenv-embedding-cache"
0.4.0 compatibility note
0.4.0 keeps the 0.3.x API for one compatibility release and adds the
immutable semantic artifact directory store. The legacy resolver remains available and the
0.3 generation/request types are not implicitly converted into 0.4 semantic identities. It also keeps centralized
runtime generation through ensure_embedding_cache(..., compute_runtime=True),
compute_request_embeddings, and labenv-embedding-cache generate --compute-runtime. Strict canonical verification, safe migration planning,
structured tags, generation profiles, and run records remain supported.
Existing imports from labenv_embedding_cache.resolver remain available as a
compatibility shim.
0.4 Atomic Store
The 0.4 store has only two canonical states: MISSING and READY. A producer
materializes ordered rows, compiles a semantic spec, and atomically publishes
one immutable artifact directory. Consumers only resolve and load a READY
artifact; they do not need model or Hydra dependencies.
Canonical payload members are deliberately limited to ids, embeddings, and
optional layer_embeddings. Dataset labels, splits, and provenance remain in
the immutable materialized-row bundle or a downstream manifest, so a second
repository can safely reuse the same embedding bytes even if it has different
annotations.
The following producer example uses the packaged Word2Vec recipe, so install
its runtime extra first. A consumer that only calls resolve_cache() or
load_cache() needs the base package only.
# pip install "labenv-embedding-cache[word2vec]"
from labenv_embedding_cache import ProducerConfigV1, ProducerService
config = ProducerConfigV1.model_validate(
{
"actor": "my-repo",
"cache_root": "/shared/embedding-cache",
"recipe": {"base_recipe_id": "word2vec-cbow"},
"dataset": {"dataset_id": "synthetic-local"},
}
)
outcome = ProducerService().run(
config,
rows=[{"id": "a", "text": "one two"}, {"id": "b", "text": "two one"}],
)
For a configuration-oriented producer entrypoint, install the optional
frontend. Hydra is confined to that entrypoint and its DictConfig is converted
to ProducerConfigV1 before the core service is called:
pip install "labenv-embedding-cache[producer-hydra,word2vec]"
labenv-embedding-producer actor=my-repo cache_root=/shared/embedding-cache \
+dataset.patch.locator=/path/to/rows.jsonl
ProducerService.prepare() is the handoff for repository-local DDP: the
repository owns distributed computation and rank 0 calls claim_cache(...) ...publish_precomputed(...). Ordinary consumers use resolve_cache() and
load_cache(verify="full") only.
0.2.0 compatibility note
0.2.0 is an intentional compatibility boundary for legacy fallback.
- Canonical cache files remain supported.
- Legacy tuple caches (
arr_0) remain unsupported. - Legacy index fallback now expects canonical cache metadata on the candidate cache file.
- In practice this means fallback candidates must carry
metadata_jsonwithvariant_tagand the usual identity metadata. - Header-only legacy caches that only store
ids/embeddings/shuffle_seedplus sparse top-level fields are no longer eligible fallback targets.
If a project still depends on header-only legacy caches, stay on 0.1.x or regenerate those caches into canonical format before upgrading.
Release publishing (PyPI / TestPyPI / GitHub Packages)
Tag push (v*) or manual dispatch triggers:
.github/workflows/release-wheel.yml(GitHub Release + optional internal index).github/workflows/publish-package-indexes.yml(TestPyPI / PyPI / GitHub Packages)
Before tagging a release:
python tools/check_tag_version.py v0.4.0
PYTHONPATH=src python -m pytest -q
python -m build
python -m twine check dist/labenv_embedding_cache-0.4.0*
Secrets for publish-package-indexes.yml:
TEST_PYPI_API_TOKEN(optional; if unset, TestPyPI publish is skipped)PYPI_API_TOKEN(optional; if unset, PyPI publish is skipped)GITHUB_PACKAGES_TOKEN(optional; if unset, GitHub Packages publish is skipped)GITHUB_PACKAGES_USERNAME(optional; defaults to${{ github.actor }})
Standalone run (smoke tests)
Install with optional embedding/debug extras:
pip install -e ".[embed,debug]"
Embedding generation only (no cache):
python tools/embedding_smoketest.py
Embedding + cache read/write:
python tools/embedding_cache_smoketest.py --backend dummy
# or (downloads model)
python tools/embedding_cache_smoketest.py --backend sentence-transformers --model sentence-transformers/all-MiniLM-L6-v2
Debugpy (wait for attach):
python tools/embedding_cache_smoketest.py --backend dummy --debugpy --wait-for-client
Embedding generation from conf/embedding presets (auto DDP/pipeline policy via embedding_model.md):
python tools/generate_embeddings_from_conf.py --preset conf/embedding/qwen3_embedding.yaml --strategy auto
Default is non-normalized embeddings. Use --normalize to generate L2-normalized caches.
normalize_embeddings=true is treated as a separate model variant (registry_key=...__l2) and cache variant (norm=l2).
Best practices: docs/EMBEDDING_BEST_PRACTICES.md
Policy path setup
No environment variable is required for normal use. The package resolves its
bundled embedding_rulebook.yaml automatically.
If you want to pin EMBEDDING_RULEBOOK_PATH explicitly in your shell profile:
export EMBEDDING_RULEBOOK_PATH="$(labenv-embedding-cache-path rulebook)"
Then reload shell:
source ~/.zshrc
Cache verification, canonical generation, and lock export
Build a read-only index for existing lm/** cache files:
labenv-embedding-cache index-build --cache-dir /work/$USER/data/embedding_cache
Show index stats:
labenv-embedding-cache index-stats --cache-dir /work/$USER/data/embedding_cache
Verify whether request manifests can be served without regeneration:
labenv-embedding-cache verify-requests --requests /path/to/request_manifest.jsonl --min-selected-models 2
Build request manifest rows from canonical metadata in Python:
import labenv_embedding_cache as lec
record = lec.build_request_manifest_entry(
dataset_name="ag_news",
model_id="bert",
model_name="bert-base-uncased",
expected_cache_path="/work/$USER/data/embedding_cache/lm/bert-base-uncased/ag_news__x.npz",
metadata=metadata,
)
Export a lock payload for CI/DVC (policy digest + index + optional verify report):
labenv-embedding-cache lock-export \
--cache-dir /work/$USER/data/embedding_cache \
--requests /path/to/request_manifest.jsonl \
--output /work/$USER/data/embedding_cache/.labenv/lock.json \
--min-selected-models 2
Index file location:
${EMBEDDING_CACHE_DIR}/.labenv/index_v1.jsonl
Legacy fallback policy is controlled by rulebook:
compatibility.legacy_index.enabledcompatibility.legacy_index.sunset_datecompatibility.legacy_index.require_ids_sha256_match
The core resolver keeps compatibility.legacy_index.enabled: true for the current
compatibility window. New generation workflow commands are canonical-only by
default and use fallback only for explicit diagnostics such as fallback-audit
or migration validation.
Legacy tuple caches remain outside the reusable canonical contract:
cache.compatibility.accept_legacy_npz_tuple: false
Identity expansion is controlled by spec:
identity.profiles.default.hard_fieldsidentity.profiles.default.soft_fieldsidentity.profiles.default.defaultsidentity.profiles.default.legacy_match_policy
Quick usage
from labenv_embedding_cache.api import get_or_compute_embeddings
vectors, resolution = get_or_compute_embeddings(
cfg,
texts,
ids,
labels=labels,
compute_embeddings=my_backend_compute_fn,
)
print(resolution.cache_path, resolution.was_cache_hit)
Generation control profiles
Generation host profiles are defined in generation_profiles.yaml and the
packaged policy copy. These profiles do not add public execution targets to this
repo.
env1_docker_embedding/env2_docker_embedding/env3_docker_embedding/env4_docker_embedding: Docker routes with canonical cache root/home/${USER}/data/embedding_cache.cc21_slurm_embedding: planner-first Slurm route with cache root/work/${USER}/data/embedding_cache.
For cc21, H100 and H200 are modeled as gpu_family resource attributes. Large
GPU jobs prefer H200 and fall back to H100 through planner runtime state when
H200 is temporarily unavailable.
V2 migration audit
Existing cache roots should be migrated by auditing and materializing
self-describing v2 artifacts, not by guessing identity from legacy filenames.
The read-only audit bundle writes only under
<cache-root>/.labenv/migration_audits/<run_id>/:
PYTHONPATH=src labenv-embedding-cache migrate-v2-audit \
--cache-dir /path/to/embedding_cache \
--run-id readonly-audit-YYYYMMDD
The audit summary reports v2_valid, v1_metadata_upgradeable,
metadata_gap_needs_manifest, manual_or_regenerate, and
blocked_collision. Non-dry materialization is a later phase and should use
only audit-safe copy / write_v2 rows followed by strict validation and
explicit legacy quarantine.
Live cache materialization, retirement, and quarantine are intentionally separate gates. Use read-only audits first, preserve the generated audit artifacts, and require explicit rollback evidence before any non-dry retire action.
AppConfig compatibility
- The 0.4 atomic producer accepts
ProducerConfigV1or a plain mapping. A HydraDictConfigmust be converted at the entrypoint by the optionalproducer_hydrafrontend; it is not a core contract. - Legacy v2 compatibility APIs continue to accept their pre-existing mapping and typed-dataclass inputs during the one-release compatibility window.
- To keep cache sharing stable during typed-migration, dataset fingerprinting treats these legacy-equivalent cases as identical:
- missing vs empty container:
dataset.splits,dataset.label_columns,dataset.label_map,dataset.label_remap - missing vs
false:dataset.drop_multi_label_samples,dataset.multi_label,dataset.trust_remote_code
- missing vs empty container:
Downstream compatibility
CEBRA / Arc / Larm consumers should use the package facade:
import labenv_embedding_cache as lec
The supported public surface and read-only manifest/cache contract are documented in
docs/DOWNSTREAM_COMPATIBILITY.md.
Docker / Docker Compose (env1-env4)
Compose files match the labenv_config/envkit-templates profiles (env1_a6000/env2_3090/env3_cc21_a100/env4_cc21_cpu):
- env1:
nvcr.io/nvidia/pytorch:25.09-py3(CUDA 13.0 profile; CUDA 12.8 runtime is frozen legacy) - env2:
nvcr.io/nvidia/pytorch:25.09-py3 - env3:
nvcr.io/nvidia/pytorch:23.10-py3 - env4:
python:3.11-slim
Cache roots are unified by compose profile:
env1/env2: embedding cache =/home/${USER}/data/embedding_cache(EMBEDDING_CACHE_DIR/TEXT_EMBEDDING_CACHE_DIR)env3/env4: embedding cache =/home/${USER}/data/embedding_cache(EMBEDDING_CACHE_DIR/TEXT_EMBEDDING_CACHE_DIR)env1/env2: HF cache reuse =/data/cache(HF_HOME,TRANSFORMERS_CACHE)
Host paths are bind-mounted so caches are reused across repos by default.
Examples:
docker compose -f docker/compose.env1.yaml run --rm app python tools/embedding_cache_smoketest.py --backend dummy
docker compose -f docker/compose.env4.yaml run --rm app python tools/embedding_smoketest.py --backend transformers
# debugpy (port publish requires --service-ports)
docker compose -f docker/compose.env1.yaml run --rm --service-ports app python tools/embedding_cache_smoketest.py --backend dummy --debugpy --wait-for-client
Sweep utility
Create a stable, line-based sweep list file:
python tools/make_sweep_list.py --glob "configs/sweep/*.yaml" --out sweep.txt --root .
Per-project Codex usage
In each project, paste CODEX_PROMPT.md (or add equivalent guidance in AGENTS.md) so Codex always aligns with this policy.
For cross-project rollout requests, use PROJECT_MIGRATION_PROMPT.md.
Automation runbook
- Runtime-aware automation prompt:
docs/AUTOMATION_PROMPT_RUNTIME_AWARE.md - Copy/paste execution checklist:
docs/AUTOMATION_EXECUTION_CHECKLIST.md - Pre-filled ready-to-run checklist:
docs/AUTOMATION_EXECUTION_CHECKLIST_READY.md - What to place in central/downstream/runtime repos:
docs/REPO_AUTOMATION_ASSETS.md
Architecture governance
- Current structure and dependency DAG:
docs/architecture/current-structure.md - Machine-readable module map:
docs/architecture/module-map.yaml - ML/cache contracts:
docs/ML_CONTRACTS.md - Public/internal API boundary:
docs/architecture/public-api.md
Local checks:
python tools/check_policy_bundle_sync.py
python tools/check_architecture_boundaries.py
python tools/architecture_inventory.py
python tools/dynamic_reference_inventory.py --text
Updating shared standards
- Edit
embedding_rulebook.yaml,embedding_registry.yaml, and/orembedding_cache_spec.yaml. - In each project, run its embedding-cache validation/tests.
- If schema behavior changes, bump
identity.versioninembedding_rulebook.yaml.
Metadata
Release files for labenv-embedding-cache 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| labenv_embedding_cache-0.4.0.tar.gz | 248.0 kB | Without provenance | Details for labenv_embedding_cache-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| labenv_embedding_cache-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for labenv_embedding_cache-0.4.0-py3-none-any.whl |
Total release size: 440.1 kB
Release files / labenv_embedding_cache-0.4.0.tar.gz
| Download URL | labenv_embedding_cache-0.4.0.tar.gz |
|---|---|
| Size | 248.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d480f7ab7a905e2cf4cd2a0efd4865937cd2487b012a5ac22ad89079755ea4c
|
|
BLAKE2b-256 checksum How to use checksums |
0194a819fa3603d2a647ce0e55b8df51b274922cb931f040b1be9c6b68114051
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / labenv_embedding_cache-0.4.0-py3-none-any.whl
| Download URL | labenv_embedding_cache-0.4.0-py3-none-any.whl |
|---|---|
| Size | 192.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81209f7b0ef7511792dd6a1832059967abfa51ca9f4b8236e48578593e66d7af
|
|
BLAKE2b-256 checksum How to use checksums |
b794c295ceeb4a5408594286e36fce14cdeaa41e07282cfac4491cd512f448df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Security for labenv-embedding-cache 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.