How it works#
Metric contract#
The public metric uses unit costs:
insertion 1
deletion 1
substitution 1
For two sequences a and b:
D = distance(a, b)
M = max(len(a), len(b))
similarity = M - D
normalized_distance = D / M
normalized_similarity = 1 - D / M
For two empty sequences, normalized distance is 0.0 and normalized
similarity is 1.0.
Backend selection and execution#
Automatic availability selection prefers:
bundled internal -> RapidFuzz -> pure Python
The external GPL Levenshtein package is never selected automatically.
There is an important implementation distinction:
availability fallback chooses a usable backend before computation;
runtime fallback handles an accelerator that fails while computing.
Each distance(), rank() or closest() call uses one execution plan.
When the chosen accelerator fails at runtime, the plan warns once, stops using
it for the rest of the call and tries the next available safe backend
(internal, then rapidfuzz), with pure Python last. This resolved
maintenance finding LV-001, which recorded that a runtime failure used to
jump straight to pure Python.
Provenance#
Ranking results store the backend that actually computed each match:
from scikitplot.levenshtein import rank
item = rank("kitten", ["sitting"], backend="python")[0]
assert item.backend == "python"
The Corpus bridge preserves the same provenance in retrieval metadata.