Code and dense tables are folded away. Open any of them on demand.
At a glance: Laya vs Embeddings + kNN
Showing 11 of 11 rows.
| Feature | Laya (via Laya Studio) | Embeddings + kNN |
|---|---|---|
| What it computes | A probability for each option, read jointly with the state | Vector similarity between the input and stored examples or label texts |
| Needs labelled examples | EdgeNo; options are defined by descriptions at request time | Yes for kNN; label-description matching works without examples, but is weaker |
| Label count | Best under ~20 options per choice (shared 192/256-token option budget) | Scales to thousands of labels with a vector index |
| Answer types | choice, score (ordinal) and noul (yes/no probability) | Nearest label or vote; ordinal and yes/no questions need extra modelling |
| Probabilities | Softmax over options, trained with proper scoring rules; refit temperature for calibration | Vote fractions or cosine scores; not probabilities unless you calibrate them |
| Instructions | Each question has natural-language instructions | No instruction channel; similarity is task-agnostic |
| Negation and conditions | Reads option text against the state in one encoder pass | Pooled vectors often blur negation and conditions |
| Latency | 32.8–39.5 ms per question on a T4 (model card) | One embedding + index lookup; typically cheaper per item |
| Updating labels | Edit the criteria in the request | Add or remove examples in the index |
| Multilingual | Automatic routing to mmBERT-base checkpoint | Depends on the embedding model chosen |
| Explainability | Full probability vector per option; routing reason | Nearest neighbours can be shown as evidence |
marks a row with a clear edge (yes vs no, an explicit weakness, or a much lower latency). Other rows are a trade-off: read both cells.
The verdict
Use embeddings plus kNN when you have hundreds of labels and plenty of labelled examples. Use Laya when labels are defined by descriptions, answers must be typed and calibrated, or you need score and yes/no decisions. For more than 20 labels, shortlist with embeddings and let Laya make the final choice.
What is the difference between Laya and embeddings + kNN?
Embeddings + kNN labels new text by turning it into a vector and copying the label of its nearest stored examples. Laya is a decision model that reads the text together with your question and options, and scores each option directly with a probability. Embeddings compare by similarity; Laya decides with the question in view.
An embedding classifier has two parts. An encoder maps text to a fixed vector, and a rule turns vectors into labels. The common rules are:
- k-nearest neighbours (kNN): embed a labelled training set once, and at query time find the k closest examples and take a (possibly weighted) vote.
- Nearest centroid: average the example vectors per label and pick the closest average.
- Label-description matching: embed a sentence describing each label, and pick the label whose description is most similar to the input. This is zero-shot, but usually the weakest variant.
Sentence-embedding models such as Sentence-BERT made this practical. Vector libraries such as FAISS make it scale to millions of vectors.
Laya is a different kind of model, a cross-encoder-style decision model. The state, the question's instructions and every option go into one sequence. Each option sits behind its own [MASK] marker, and a bidirectional encoder (ModernBERT-large or mmBERT-base) reads everything together. A small head scores each marker, and a softmax gives the answer distribution. The label set is part of the input, so it can change on every request. See option-marker scoring.
The core difference: an embedding compresses the input before it knows the question. Laya reads the input with the question and options in view.
When are embeddings + kNN the better choice?
Be clear about when you should not use Laya.
- Very large label spaces. A vector index handles 5,000 product categories without trouble. Laya's options share a fixed budget of 192 tokens (English) or 256 tokens (multilingual). The model card shows the cost: on Banking77, with 77 labels, Laya scores 0.425, because each label gets about 3–4 tokens. The card's advice is to keep choice questions under about 20 options.
- Plenty of labelled history. If you already have 50,000 tickets labelled by your team, kNN uses them directly and reflects your own labelling conventions, including the idiosyncratic ones. Laya uses your labels only if you fine-tune it.
- Lowest cost per item. Embedding one short text and querying an index is a single encoder pass plus a lookup, and the example vectors are computed once. Laya encodes the state once per question, because each question is its own sequence in the batch.
- Deduplication, search and clustering. These are similarity problems, not decisions, and embeddings are the right primitive for them.
- Evidence you can show. "This ticket looks like these five past tickets" is an explanation many reviewers find persuasive.
When is Laya the better choice?
- No labelled data yet. You write the options as descriptions (
"billing": "invoices, payments, refunds") and get answers on day one. kNN with no examples falls back to label-description matching. - Instructions matter. The same email can be asked "which team should handle this?" and "is the sender threatening to cancel?". An embedding of the email is the same vector for both. Laya conditions each answer on the question.
- Typed answers other than a label. Laya's
scorereturns an expected value over ordered levels plus a distribution, andnoulreturns the probability that a statement holds. Doing these with kNN means building a separate regressor or a binary index per question. - Negation and fine conditions. "I do not want a refund, just an explanation" sits close to refund requests in many embedding spaces. A model that reads the option text against the full input has a better chance of catching the negation. It is still not guaranteed, so test it on your own data.
- Probabilities you can act on. kNN vote fractions (3 of 5 neighbours) are coarse and uncalibrated. Laya is trained against strictly proper scoring rules, so its outputs are meant to be probabilities. After refitting temperatures on held-out data, the model card reports mean ECE falling from 0.466 to 0.081. See calibrated probabilities.
- Many questions in one call. Laya answers all questions in one request, and batching makes each additional question cheaper: 10 questions take 72.3 ms on the multilingual checkpoint, against 32.8 ms for one.
Are kNN scores probabilities? Calibration compared
With kNN at k = 5, a label that wins 4 of 5 votes is often reported as "0.8 confidence". Several things are wrong with that number:
- It can take only six values (0, 0.2, 0.4, 0.6, 0.8, 1.0).
- It depends on k and on how dense each class is in the training set. A large class wins more votes simply by being large.
- Nothing trained it to match observed accuracy.
Cosine similarity has the same problem. A score of 0.82 means different things in different embedding models and for different labels.
You can calibrate kNN, for example with Platt scaling or isotonic regression on held-out predictions. Many teams skip that step. Laya's training objective optimises calibration directly: the reward is log score plus spherical score (and ranked probability score for ordinal questions). The model is still shipped over-confident, and the Laya authors say so. Fitting one temperature per (question type, option-count bucket) is the fix, and it takes minutes on a few hundred labelled answers. See temperature scaling and expected calibration error.
| Signal | kNN / cosine | Laya |
|---|---|---|
| Output | vote fraction or cosine score | softmax probability per option |
| Trained for calibration | no | yes (proper scoring rules) |
| Out-of-the-box calibration | usually poor | over-confident as shipped (ECE 0.466 on laya) |
| After a cheap refit | better with isotonic/Platt | ECE 0.081 on laya after temperature refit |
| Confidence field | you compute it | confidence = 1 − H(p)/log k, returned per answer |
Can you use both? Shortlist with embeddings, decide with Laya
The laya package ships this pattern as predict_shortlist in laya.shortlist. For each choice question with more than k options (default 20), it:
- embeds the state and every option with an
embed_fnyou supply; - keeps the top k options by cosine similarity;
- runs one Laya forward pass over the reduced option set.
Show technical detailsHide technical details· python sample
Non-choice questions pass through unchanged. A choice question with k or fewer labels skips the embedding step. The probabilities on a shortlisted question cover the kept labels only. The package docstring is careful about evidence: the coarse-to-fine pattern comes from a community report (issue #102), and "this module does not measure" the Banking77 figures in that report. Measure the shortlist's recall on your own labels before you trust it. If the right label is not in the top 20, Laya cannot pick it.
If you only have the Laya checkpoint in memory, embed_fn_from_agent(agent) mean-pools Laya's own encoder. The docstring notes that "a dedicated bi-encoder passed as embed_fn will usually shortlist better".
With Laya Studio
Do the shortlist on your side and send only the top 20 labels:
Show technical detailsHide technical details· ts sample
That is billed per input token read, once per question. The embedding lookup runs in your own infrastructure.
Which is cheaper and faster in practice?
For a fixed label set and heavy traffic, embeddings are hard to beat on cost. You embed each input once, and index lookups are cheap. Laya's cost scales with the number of questions, since each question is a separate row in one batched forward pass:
| Questions per call | laya | laya-multilingual |
|---|---|---|
| 1 | 39.5 ms | 32.8 ms |
| 10 | 158.6 ms | 72.3 ms |
| 50 | 771 ms | 337 ms |
These are T4 GPU timings from the Laya model card, measured in-process. Over HTTP to Laya Studio, add your network round trip. Billing is per input token (1 credit = 1 input token), 30% below Jev's list price, with 5 free runs; see /pricing.
Rules of thumb:
- If you ask one question over a fixed set of hundreds of labels at very high volume, use embeddings.
- If you ask several different questions per item, such as a team, an urgency score and three yes/no flags, Laya answers all of them in one call. You would otherwise build and maintain several separate kNN setups.
- If you need both, shortlist then decide. The embedding step bounds the label count, and Laya handles the final call and the typed questions.
What are the limitations of each?
Embeddings + kNN
- Quality depends on the training set. Mislabelled or stale examples are copied into predictions.
- There is no instruction channel, so each question needs its own index, examples or rules.
- Similarity is not entailment. Topically close texts can need different labels.
- Scores are not probabilities without calibration.
Laya
- Large label spaces need a shortlist or a hierarchy (Banking77: 0.425 at 77 labels).
- Context per question is 512 tokens (English) or 1,024 (multilingual), so long states are truncated.
- Base checkpoints are near chance on the complex typed-decisions workflows zero-shot (0.362). That benchmark needed fine-tuning to reach 0.766.
scorequestions are the weakest primitive (SST-5 0.372).action.act_probabilitycarries no usable signal yet.- The model ships over-confident. Refit temperatures before you gate on probabilities.
Try both on a sample of your own traffic. A new Laya Studio workspace gets 5 free runs; after that a test set costs its input tokens at a list price 30% below Jev's. The request format is in the docs.
Frequently asked questions
Is Laya just an embedding model?
Can I use Laya with 500 labels?
Are kNN vote fractions calibrated probabilities?
Which is cheaper?
Do I need training data for Laya?
Can I explain Laya decisions the way I can with nearest neighbours?
What is kNN text classification?
When should I use embeddings instead of a decision model?
Sources
Last updated . Laya Studio is an independent hosted service for the open-source Laya model (Apache-2.0, © Convai Innovations) and is not affiliated with Convai Innovations or TypeSafe.