Skip to main content

llm-sentence-transformers

PyPI Changelog Tests License

LLM plugin for embedding models using sentence-transformers

Further reading:

Installation

Install this plugin in the same environment as LLM.

llm install llm-sentence-transformers

Configuration

After installing the plugin you need to register one or more models in order to use it. The all-MiniLM-L6-v2 model is registered by default, and will be downloaded the first time you use it.

You can try that model out like this:

llm embed -m mini-l6 -c 'hello'

This will return a JSON array of floating point numbers.

You can add more models using the llm sentence-transformers register command. Here is a list of available models.

Two good models to start experimenting with are all-MiniLM-L12-v2 - a 120MB download - and all-mpnet-base-v2, which is 420MB.

To install that all-mpnet-base-v2 model, run:

llm sentence-transformers register \
  all-mpnet-base-v2 \
  --alias mpnet

Some models may also require you to pass the --trust-remote-code flag when registering them. The model documentation will usually mention that in the Python example code on Hugging Face.

The --alias is optional, but can be used to configure one or more shorter aliases for the model.

You can run llm aliases to confirm which aliases you have configured, and llm aliases set to configure further aliases.

Usage

Once you have installed an embedding model you can use it like this:

llm embed -m sentence-transformers/all-mpnet-base-v2 \
  -c "Hello world"

Or use its alias:

llm embed -m mpnet -c "Hello world"

Embeddings are more useful if you store them in a database - see the LLM documentation for instructions on doing that.

Be sure to review the documentation for the model you are using. Many models will silently truncate content beyond a certain number of tokens. all-mpnet-base-v2 says that "input text longer than 384 word pieces is truncated", for example.

Removing models

Models are stored in the Hugging Face cache directory, which can usually be found in ~/.cache/huggingface/hub.

To remove a model, first delete the directory for that model from the cache directory, then manually remove the model from the sentence-transformers.json file in the LLM configuration directory. The location of this directory can be found by running llm logs path:

llm logs path

Example output:

/Users/simon/Library/Application Support/io.datasette.llm/logs.db

In this case, sentence-transformers.json would be located at:

/Users/simon/Library/Application Support/io.datasette.llm/sentence-transformers.json

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd llm-sentence-transformers
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Release files for llm-sentence-transformers 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-sentence-transformers 0.3.2
File Size Uploaded
llm_sentence_transformers-0.3.2.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-sentence-transformers 0.3.2
File Interpreter ABI Platform
llm_sentence_transformers-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / llm_sentence_transformers-0.3.2.tar.gz

Download URL llm_sentence_transformers-0.3.2.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a39e4d3584d672d006d11873be6f902f564ce17f5174fddb50109d276000680f
BLAKE2b-256 checksum
How to use checksums
1d76ed7ebc9ce28210ae1946175551d7180749e3c83291e35430ea5afda151aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 23, 2025.

Transparency log

Release files / llm_sentence_transformers-0.3.2-py3-none-any.whl

Download URL llm_sentence_transformers-0.3.2-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ba8a21906820f4b165913b66a3d4446fb932f47c6364e74e9470298770594e6
BLAKE2b-256 checksum
How to use checksums
f9f825db7460099d1491d73cf0b0633e5ffc44a244d2858d35d1ebbd4fc12edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 23, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page