dyf fits once, and then you change the focus. A few broad groups, many narrow ones, or anything between, without fitting again. The same fit is also a search index and a partition you can keep as new data arrives.
How it works
dyf does not compare every point with every other point. It cuts the embedding space into small cells with a few yes/no questions, and then works with the cells. Step through the run you just saw.
Two things are visible in that form. Only the last two stages depend on the resolution γ, so the tree, the leaves and the graph are computed once and every level reuses them. And every stage uses nothing but inner products of unit vectors: to dyf an item is a direction, and it knows nothing else about it.
Choosing a level
A lens does not choose its own focus. We tried fourteen ways to choose the level without labels. None was reliable. What works is small: label about fifty items by hand and keep the level that agrees with them best. Click a level on the chart to see its groups.
Over time
Most clustering is run once. Real collections grow, and a fresh fit each month hands every group a new identity, so last month's group 12 is nowhere in particular this month. dyf can start a refit from the previous groups instead. The ids carry over.
We measured this on the FDA's medical device database: 4.7 million records growing to 5.3 million over 22 months, 86 groups.
Share of groups whose best match in the next quarter's fit overlaps by at least half (Jaccard ≥ 0.5). Mean of eight quarterly refits.
Range over the eight refits, 768-dimension embeddings. The nearest-neighbour graph arm ends with thousands of groups, so it is a cost comparison only.
With the warm start, all 86 ids were the same ids after 22 monthly refits, and from the fourth month on fewer than 3% of existing records changed group each month. The first three months moved 19%, 12% and 10% because the final step had not finished settling. That is a known defect, not new data.
The cells are useful on their own too. Freeze the tree, count how many new records land in each cell each month, and the counts track real change in the mix of device types as closely as a hand-assigned label does (rank correlation 0.86 to 0.91, against 0.82 for the review-panel label).
Where it loses
Every number on this page comes from a benchmark in the repository. These are the results that went against it.
Use it
pip install dyf
from dyf import build_dyf_tree, write_lazy_index, LazyIndex, louvain_cluster_leaves
tree = build_dyf_tree(embeddings, num_bits=3, max_depth=4, min_leaf_size=20)
write_lazy_index(tree, embeddings, "requests.dyf")
with LazyIndex("requests.dyf") as idx:
coarse = louvain_cluster_leaves(idx, layout_2d, embeddings, resolution=1.0)
fine = louvain_cluster_leaves(idx, layout_2d, embeddings, resolution=32.0)
print(coarse.n_groups, fine.n_groups) # 22 and 151 on 23,850 voice-assistant requests
hit = idx.search(embeddings[0], k=5, nprobe="auto") # the same file is a search index
layout_2d is any (n, 2) array, for example a UMAP layout. It is used only to name groups by position.