Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Caching and runs

CyteOnto saves what it gets from the models, so that it asks for each description and embedding only once. It keeps two kinds of caches:

Run IDs

The run_id of compare() names the caches of a comparison and fills the run_id column of the results.

In file paths, / and : in run IDs and algorithm names become -, and spaces and . become _: liver.v1 is stored as liver_v1. The algorithm name author is reserved for the author labels.

What is reused

CacheReused
How labels were splitPer label, for all the labels of the run, author and algorithm alike
Label descriptionsPer label, separately for the authors and for each algorithm
Label embeddingsWhen the authors’ or algorithm’s distinct labels are exactly those of the saved file, in the same order, and all have descriptions
Ontology descriptionsPer term: only the terms without a description are described
Ontology embeddingsWhen the file exists and every term already has a description; otherwise all 2,902 terms are embedded again

So when you add a label to a run, only the new label is split and described, but all the labels of that side are embedded again. Labels are lowercased first, so Plasma cell and plasma cell share their cache entries.

A label that the LLM could not describe after all retries is not cached: its embedding is made from the label text, and the next call with the run tries to describe it again. The same holds for ontology terms in from_config(), and for labels whose split failed, except a split that exceeds the usage limits: that label stays whole, and this is cached, since another try would exceed the limits again.

When labels or terms get new descriptions, the embedding files made before are stale, for every embedding model: CyteOnto embeds the descriptions again instead of reusing those files. A stale file stays on disk until a new one replaces it.

Regenerate caches

Inspect and delete run caches

cache_stats() summarizes the label embedding files of all runs, or of one run:

cyto.cache_stats(run_id="quickstart")

It returns a dict with root, the directory it searched, total_files and total_size_mb, the number and size of the embedding files, and stale_files, the files that cannot be loaded.

clear_run() deletes the descriptions and embeddings of a run and returns the number of files deleted:

# Everything of the run.
cyto.clear_run("quickstart")

# Only the author labels, or only the algorithms.
cyto.clear_run("quickstart", kind="author")
cyto.clear_run("quickstart", kind="algorithm")

# One algorithm, for the model pair of this instance.
cyto.clear_run("quickstart", kind="algorithm", identifier="method_a")

clear_run() keeps how the labels were split. Delete <user_dir>/decompositions/<run_id>/ to remove those too.

purge_stale() deletes the label embedding files that cannot be loaded, such as files written by older versions of CyteOnto without the labels inside, from all runs or from one run:

cyto.purge_stale(run_id="quickstart")

Choose where the caches go

data_dir defaults to the data directory inside the installed package and user_dir to <data_dir>/user_files. Pass both to keep the ontology files in one place and the run caches of a project in another:

from pathlib import Path

cyto = await CyteOnto.from_config(
    agent=agent,
    embedding=embedding,
    llm=llm,
    data_dir=Path.home() / "cyteonto-data",
    user_dir=Path("cyteonto-runs"),
)

data_dir must contain the files that python -m cyteonto.setup --data-dir downloads. Data files and formats shows the layout of both directories and the formats of the files.