Transformers
Question Answering
Extractive question answering from a given context.
Extract answers directly from a context passage. The model finds the span of text that best answers the question — no generation needed.
For full API reference (answerQuestion(), answerQuestionMany(), options, result types, and custom providers), see the Core Question Answering guide.
See it in action
Try QA Bot for a working demo.
Recommended Models
| Model | Size | Speed | Use Case |
|---|---|---|---|
Xenova/distilbert-base-cased-distilled-squad | ~100MB | ⚡⚡⚡ | Fast extractive QA |
Xenova/distilbert-base-uncased-distilled-squad | ~100MB | ⚡⚡⚡ | Case-insensitive QA |
QA Bot Example
Based on the QA Bot showcase app:
import { transformers } from '@localmode/transformers';
import { answerQuestion } from '@localmode/core';
const model = transformers.questionAnswering(
'Xenova/distilbert-base-cased-distilled-squad'
);
async function askQuestion(question: string, context: string) {
const { answer, score } = await answerQuestion({
model,
question,
context,
abortSignal: controller.signal,
});
return {
answer,
confidence: score,
isReliable: score > 0.5,
};
}Best Practices
QA Tips
- Provide focused context — Shorter, relevant context gives better answers
- Check the score — Low scores mean the model is uncertain
- Extractive only — Answers are always spans from the context, not generated text
- Combine with search — Use semantic search to find relevant context first