Use sentence-transformers for embeddings with LLM
Project description
llm-sentence-transformers
LLM plugin for embedding models using sentence-transformers
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.
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
Built Distribution
File details
Details for the file llm-sentence-transformers-0.1.tar.gz
.
File metadata
- Download URL: llm-sentence-transformers-0.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d74f5b0079ef58956c79acfcbb39f61f4c2975d0e50e17f1124cc45dbf5b8a8 |
|
MD5 | 4719c2d22619d5553bdfdcb53ee5cdda |
|
BLAKE2b-256 | e45b76f4397d6a0ef309965fd6665967d3eb40d0b0f70e0ccd88a08a69267a87 |
File details
Details for the file llm_sentence_transformers-0.1-py3-none-any.whl
.
File metadata
- Download URL: llm_sentence_transformers-0.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 702061408e53b5406322f820c864dfe0bce46cf805cc4a9fa4b01d7da7caf66c |
|
MD5 | 47b5b0c8db417e22b7f6801555b5f7e5 |
|
BLAKE2b-256 | ae832efa6a743f2b9940f5aef31f8e243cf7df03c85a50eb12f8ffcc1ecbc71f |