TOOL WIKI · DATA & RETRIEVAL

Sentence Transformers

Provides models and utilities for embeddings and semantic retrieval workflows.

Download example files Code + setup + checks in a ZIP
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

WHAT IT ISEmbedding library
WHERE IT FITSData & retrieval
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
inputprocessresultcheckoutputSource materialFiles or textSentence TransformersEmbedding libraryPrepared recordsText, chunks, or vectorsRetrieval storageIndex + metadataQuery pipelineScoped evidence lookupEvaluationInspect source fidelity
  1. Preserve provenance, input format, and access-control metadata.

  2. Owning embedding generation in a local or hosted application pipeline. Match the embedding model, dimensions, and query conventions across the index.

  3. Validate the component-specific output, including failed or empty records.

  4. Store derived data with source version and deletion information.

  5. Use compatible query processing and tenant-scoped filtering.

  6. Check extraction quality, retrieval recall, and answer grounding separately.

    Result or stopping point
Sentence Transformers

Owning embedding generation in a local or hosted application pipeline. Match the embedding model, dimensions, and query conventions across the index.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

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.
Shell
python3 -m venv .venv
source .venv/bin/activate
pip install sentence-transformers

Try a small integration

embed.py

Python · 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

Shell
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

Retrieval that can ask a better questionA context pipeline for a long-running agent

Explore the same layer

UnstructuredDoclingLlamaParseCohere Rerank

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.