Vectors and Routing
Matheel supports three public vector backends:
sentence_transformersmodel2vecpylate
You can also use vector_backend=auto and let Matheel route based on Hugging Face metadata and tags.
Parameters
vector_backendmax_token_lengthsimilarity_functionnormalize_semantic_scorespooling_methodstatic_vector_dimstatic_vector_lowercasemultivector_bidirectionaldevice
Backends
sentence_transformers
Dense single-vector embeddings through Sentence Transformers.
Best when:
- you want a widely supported default path
- you want dense semantic similarity
- you want to control
similarity_functionandpooling_method
model2vec
Learned static single-vector embeddings via model2vec.
Best when:
- you want a true static embedding model
- you want lighter-weight inference than dense transformer pooling in some setups
- your selected Hugging Face model is explicitly a
model2vecmodel
pylate
Multivector late-interaction scoring via PyLate/ColBERT-style models.
Best when:
- you want token- or chunk-level late interaction
- you want higher-fidelity multivector matching
- your selected Hugging Face model is tagged for
PyLateorColBERT
Auto Routing
vector_backend=auto checks model metadata and tags and prefers:
- Sentence Transformers for dense models
- model2vec for static models
- PyLate for multivector models
If metadata is unavailable, Matheel falls back to simple name/tag heuristics and finally defaults to Sentence Transformers.
Max Token Length
Use max_token_length to cap the sequence length used by the selected model.
Noneor0keeps the model default- a positive integer applies a shorter cap
- values above the detected model limit are clamped to that detected limit
The helper inspect_model_settings(...) returns both:
detected_max_token_lengthconfigured_max_token_length
That is the API the Gradio model picker can use to show a safe token-length control after model selection.
Similarity Functions
These apply to single-vector backends:
cosinedoteuclideanmanhattan
Notes:
cosineanddotare the most common similarity choices.- Raw
cosinescores are bounded from -1 to 1. - Raw
dotscores are unbounded. - Raw
euclideanandmanhattanscores are negative distances. Identical vectors score0.0; farther vectors become more negative. normalize_semantic_scores=Truemaps single-vector semantic scores to the 0-1 range before weighting. Distance scores use1 / (1 + distance), so identical vectors score1.0and farther vectors approach0.0.- Keep normalization as an option when you need raw distance or dot values for analysis. Enable it before combining
dot,euclidean, ormanhattansemantic scores with lexical or code-metric weights.
Pooling Methods
These apply to Sentence Transformers single-vector scoring:
meanmaxclslasttokenmean_sqrt_len_tokensweightedmean
pooling_method is ignored by model2vec and pylate.
Backend-Specific Parameters
static_vector_dimCompatibility fallback dimension used by internal local static-vector fallback paths.static_vector_lowercaseWhether local static-token preprocessing lowercases tokens.multivector_bidirectionalIf enabled, late interaction averages both scoring directions.deviceRuntime device such asauto,cpu,mps, orcudawhen supported.
Python Example
from matheel.similarity import calculate_similarity
score = calculate_similarity(
"def add(a, b): return a + b",
"def add(x, y): return x + y",
model_name="huggingface/CodeBERTa-small-v1",
vector_backend="sentence_transformers",
max_token_length=256,
similarity_function="dot",
normalize_semantic_scores=True,
pooling_method="max",
feature_weights={"semantic": 1.0},
)
print(score)