TOOL WIKI · DATA & RETRIEVAL
Sentence Transformers
Provides models and utilities for embeddings and semantic retrieval workflows.
Jump to a section 10 sections
EXAMPLE USE CASE
Find the policy closest to a return-window question
A policy assistant needs usable source text or relevant evidence before a generation model can answer a question reliably.
- Input
- Two policy/shipping sentences and a return question.
- Expected output
- An embedding-based ranking with source text, score and dimensions.
- Success check: The return-window document should rank above the shipping document for the return question.
- Try a failure: Evaluate paraphrases and unrelated questions; similarity alone does not guarantee an answer is supported.
Example scope: Actual local embedding-model inference; the first run downloads model weights.
Official reference · Sentence Transformers
Preserve provenance, input format, and access-control metadata.
Owning embedding generation in a local or hosted application pipeline. Match the embedding model, dimensions, and query conventions across the index.
processTo 03 · Prepared recordsValidate the component-specific output, including failed or empty records.
Store derived data with source version and deletion information.
Use compatible query processing and tenant-scoped filtering.
outputTo 06 · EvaluationCheck extraction quality, retrieval recall, and answer grounding separately.
Result or stopping point
Owning embedding generation in a local or hosted application pipeline. Match the embedding model, dimensions, and query conventions across the index.
When to consider it
- Owning embedding generation in a local or hosted application pipeline.
A design decision to make
- Match the embedding model, dimensions, and query conventions across the index.
Prerequisites and setup
- Python 3.11+ and a scratch directory. Use the synthetic fixture or an approved test document.
python3 -m venv .venv
source .venv/bin/activate
pip install sentence-transformersTry a small integration
embed.py
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
documents = ["Returns are accepted within 30 days.","The warehouse dispatches packed orders."]
vectors = model.encode(documents,normalize_embeddings=True)
query = model.encode(["How long do I have to return an item?"],normalize_embeddings=True)
scores = query @ vectors.T
best = int(scores[0].argmax())
print({"index":best,"document":documents[best],"score":float(scores[0,best]),"dimensions":vectors.shape[1]})Run and check the result
python embed.py- The return-window document should rank above the shipping document for the return question.
- The model downloads on first use, then inference runs locally. Keep the model/version and normalization choice with the index.
Common failures
- Different embedding models can share a dimension without sharing a vector space. Re-embed when changing models.
- A similarity score is not a calibrated probability that an answer is correct.
Production decisions
- Preserve document ID, version, page/section, access scope and parser/model configuration alongside each chunk or vector.
- Evaluate extraction and retrieval separately. Test tables, scans, empty documents, duplicates, malformed input and source deletion.
- Use query/document prompting or dedicated encode_query/encode_document paths when the selected model requires them. Benchmark language/domain coverage.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.