Skip to main content

Use sentence-transformers for embeddings with LLM

Project description

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

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 -m sentence-transformers/all-mpnet-base-v2 \
  -c "Hello world"

Or use its alias:

llm -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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm-sentence-transformers-0.1.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file llm-sentence-transformers-0.1.1.tar.gz.

File metadata

File hashes

Hashes for llm-sentence-transformers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 57b0ce967c0a2ad273c027cac755d80a5fced07d31bbaa560634269c3f32dca4
MD5 09ba4db959fa49235b5abbee9da27858
BLAKE2b-256 f869e00349ca4e92ecfd0cfad7996e0676bfd8a2fc5c38b121717d8f289d5e3a

See more details on using hashes here.

File details

Details for the file llm_sentence_transformers-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_sentence_transformers-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c075cb2c9824a1cdcc997eaf866b4cc072412d08fb99506a4f820199dcc95e5
MD5 24b6777ed93d32a2caa9fef7315e98d4
BLAKE2b-256 c78149e9b8f59024216a03820c5c7c69ad6aa37c779286f863f5da6623d7d222

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page