sentence-transformers

A Python library for computing state-of-the-art sentence, text, and image embeddings, rerankers, and sparse and multi-vector representations.

Library
PyPI
v6.0.1
19,074stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
92/100Excellent
Development Activity96
Maintenance96
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
87/100Excellent
Architecture87
Code Quality90
Innovation87
Learning Curve85

Sentence Transformers (also known as SBERT) is a Python framework built on PyTorch and Hugging Face Transformers for computing dense embeddings and reranking scores from text and other modalities. It exposes a small set of model classes — SentenceTransformer, CrossEncoder, SparseEncoder, and MultiVectorEncoder — each wrapping a different retrieval paradigm behind a nearly identical encode()/similarity()/rank() API, so switching between bi-encoder, cross-encoder, sparse, and late-interaction (ColBERT-style) retrieval is a matter of swapping the class, not relearning the library.

The project maintains direct access to over 15,000 pretrained models hosted on the Hugging Face Hub, spanning general-purpose embeddings, domain-specific rerankers, and multilingual models drawn from the MTEB leaderboard, alongside a full training stack — 20+ loss functions for embedding models, additional losses for rerankers and sparse encoders, and a trainer built around the Hugging Face Trainer conventions — for teams that need to fine-tune rather than consume off-the-shelf checkpoints. It is the de facto standard dependency behind most Python semantic-search, RAG, clustering, and paraphrase-mining pipelines.

What You Get

  • A SentenceTransformer class for computing dense embeddings from text, with .encode() and .similarity() covering the common bi-encoder workflow in two calls
  • A CrossEncoder class for reranking (query, passage) pairs with .predict() and .rank(), used as the second stage of retrieve-and-rerank pipelines
  • A SparseEncoder class producing SPLADE-style sparse embeddings, plus sparsity statistics via SparseEncoder.sparsity()
  • A MultiVectorEncoder class for ColBERT-style late-interaction retrieval, encoding queries and documents into per-token vector sequences scored with MaxSim
  • Direct integration with 15,000+ pretrained models on the Hugging Face Hub, loaded by name with no separate download step
  • A full training stack (trainer.py, fit_mixin.py) with 20+ embedding losses and dedicated losses for rerankers and sparse encoders, for fine-tuning custom models
  • Embedding quantization utilities (quantize_embeddings) supporting int8, uint8, and binary precisions to cut storage and search costs
  • Composable neural network modules (Pooling, Dense, CNN, LSTM, WeightedLayerPooling, StaticEmbedding) for assembling custom encoder architectures from scratch

Common Use Cases

  • Building semantic search over a document or product corpus using dense embeddings and cosine similarity
  • Adding a reranking stage to a retrieval pipeline with CrossEncoder to improve top-k precision after an initial dense retrieval pass
  • Clustering or deduplicating large text collections by embedding similarity instead of exact-match heuristics
  • Mining paraphrases or near-duplicate sentences across large corpora
  • Powering the retrieval component of a RAG (retrieval-augmented generation) pipeline
  • Fine-tuning a domain-specific embedding or reranker model on labeled or weakly-labeled pairs using the built-in trainer and loss functions

Under The Hood

Architecture The library is organized around a BaseModel shared by four public model classes (SentenceTransformer, CrossEncoder, SparseEncoder, MultiVectorEncoder), each living in its own top-level package (sentence_transformer/, cross_encoder/, sparse_encoder/, multi_vector_encoder/) alongside a shared base/ package for common modality and module abstractions. SentenceTransformer itself (in sentence_transformer/model.py) composes multiple inheritance from BaseModel and a separate FitMixin (fit_mixin.py) to keep training logic out of the core inference class, while a standalone trainer.py and training_args.py hold the newer Hugging-Face-Trainer-style fine-tuning path. Model internals are built from composable nn.Module layers under sentence_transformer/modules/ (Pooling, Dense-equivalents, CNN, LSTM, WeightedLayerPooling, StaticEmbedding) chained sequentially, so a full model is just an ordered list of these modules plus a Transformer backbone from base/modules.py — changing the pooling or backbone module is a drop-in swap rather than a rewrite of the encoding pipeline.

Tech Stack Built on PyTorch (torch>=2.2) and Hugging Face transformers (pinned to the 5.x line) with huggingface-hub for model download/caching, tokenizers, scikit-learn, and scipy as core dependencies. Optional extras cover vision/audio/video modalities (delegated to transformers[vision|audio|video]), training (datasets, accelerate), and inference acceleration (optimum-onnx, optimum-intel[openvino], plus faiss-cpu/usearch for approximate nearest-neighbor search in the dev extras). The package builds with setuptools, ships a py.typed marker for type-checker consumers, and uses ruff for linting/import-sorting.

Code Quality The repository ships 109 test files under tests/, mirroring the four model packages plus backend/, base/, and util/ test suites, run with pytest (pytest-cov, pytest-xdist, pytest-subtests) and marker-gated slow/custom test tiers so CI can skip expensive model-download tests by default. Three separate GitHub Actions workflows (tests.yml, quality.yml, min-versions.yml) run the suite, lint with ruff/pre-commit, and verify compatibility against the package’s minimum supported dependency versions. Docstrings throughout model.py and related modules are extensive and Napoleon/Sphinx-formatted, and the codebase is typed enough to opt into static type checking (tool.ty.rules config) with only narrow, documented exceptions.

API Design The standout design choice is a nearly identical encode()/similarity()/rank() surface shared across all four retrieval paradigms (dense, cross-encoder, sparse, multi-vector), so switching retrieval strategy is a class swap rather than a new API to learn. Getting started requires two lines — load a model by Hub name, call .encode() — with prompt templates, quantization, and multi-process encoding available as opt-in kwargs rather than required configuration, keeping the common path minimal while still exposing the full training and customization surface for advanced users.

Used by 19 apps in this directory

Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,098

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
61
Dependency
Built with
Python59%
Jupyter Notebook21%
Updated 1 weeks ago
Python
100%
Apache 2.0

ClearML

Devops · Automation

6,858

Auto-magical MLOps platform that tracks experiments, versions data, orchestrates pipelines, and serves models with just two lines of code.

View details
95
Repo Health
79
Technical
67
Dependency
Built with
Python100%
Updated yesterday
Rust
52%
Apache 2.0

cocoindex

Data Engineering · AI Development

11,496

An incremental data indexing engine that keeps AI agent context perpetually fresh by reprocessing only what changed.

View details
86
Repo Health
85
Technical
64
Dependency
Built with
Rust52%
Python48%
Updated 2 days ago
TypeScript
51%
AGPL 3.0

Glean

Knowledge Management · Bookmarks Archiving

857

Self-hosted RSS reader and personal knowledge management tool with MCP server integration for AI assistant connectivity.

View details
78
Repo Health
75
Technical
69
Dependency
Built with
TypeScript51%
Python45%
Updated 4 days ago
Python
81%
Apache 2.0

headroom

AI Development · Developer Tools

69,144

Compress everything your AI agent reads — tool outputs, logs, RAG chunks, and files — before it reaches the LLM, achieving 60–95% fewer tokens with the same answers.

View details
84
Repo Health
86
Technical
72
Dependency
Built with
Python81%
Rust13%
Updated yesterday
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,160

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
75
Repo Health
82
Technical
69
Dependency
Built with
Python51%
TypeScript36%
Updated 1 months ago
TypeScript
84%
Apache 2.0

ktx

Data Engineering · Analytics · AI Development

1,577

ktx builds a self-improving context layer over your data warehouse so AI agents like Claude Code and Codex query it with approved metric definitions instead of reinventing SQL logic from scratch.

View details
76
Repo Health
85
Technical
72
Dependency
Built with
TypeScript84%
Updated 4 days ago
Rust
40%
Apache 2.0

LanceDB

Databases · AI Development

11,366

Open-source, embedded vector database built on the Lance columnar format for fast multimodal search across billions of vectors, backed by Y Combinator (W23).

View details
90
Repo Health
86
Technical
72
Dependency
Built with
Rust40%
HTML26%
Python26%
Updated yesterday
Python
68%
MIT

Langflow

AI Agents · AI Development

154,349

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
65
Dependency
Built with
Python68%
TypeScript23%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search