Skip to main content

Embedding models using Ollama pulled models

Project description

llm-embed-ollama

PyPI Changelog Tests License

LLM plugin providing access to embedding models running on local Ollama server.

Installation

Install this plugin in the same environment as LLM.

llm install llm-embed-ollama

Background

Ollama provides Few embedding models. This plugin enables the usage of those models using llm and ollama embeddings..

To utilize these models, you need to have an instance of the Ollama server running.

See also Embeddings: What they are and why they matter for background on embeddings and an explanation of the LLM embeddings tool.

See also Ollama Embeddings Models Blog

Usage

This plugin adds support for the following embedding models available in ollama:

  • all-minilm
  • nomic-embed-text
  • mxbai-embed-large
  • bge-large: Embedding model from BAAI mapping texts to vectors.
  • bge-m3: BGE-M3 is a new model from BAAI distinguished for its versatility in Multi-Functionality, Multi-Linguality, and Multi-Granularity.

The models needs to be downloaded. Using `ollama pull the first time you try to use them.

See the LLM documentation for everything you can do.

To get started embedding a single string, run the following:

Make sure you have the appropriate ollama model.

ollama pull all-minilm
llm embed -m all-minilm -c 'Hello world'

This will output a JSON array of 384 floating point numbers to your terminal.

To calculate and store embeddings for every README in the current directory (try this somewhere with a node_modules directory to get lots of READMEs) run this:

llm embed-multi ollama-readmes \
    -m all-minilm \
    --files . '**/README.md' --store

Then you can run searches against them like this:

llm similar ollama-readmes -c 'utility functions'

Add | jq to pipe it through jq for pretty-printed output, or | jq .id to just see the matching filenames.

Prefix and suffix support

Some embedding models expect prefixed or suffixed input (for example, instruction-style or query embeddings).

This plugin supports optional embedding prefixes and suffixes provided by llm. When a prefix or suffix is set on the embedding model, it is automatically applied before generating embeddings.

Example (Python):

import llm

model = llm.get_embedding_model("all-minilm")
model.prefix = "query: "

embedding = model.embed("hello world")

This is useful for models that distinguish between query and document embeddings.

Development

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

cd llm-embed-ollama
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

llm 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_embed_ollama-0.1.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_embed_ollama-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file llm_embed_ollama-0.1.3.tar.gz.

File metadata

  • Download URL: llm_embed_ollama-0.1.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llm_embed_ollama-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ddeb62719ea69aa1e7b73fe218022c4b5d89e132aba3862692ee933f80ce3d42
MD5 8d849b05c5508c80d4a49bfa28a22fcd
BLAKE2b-256 db12ddb0b7a537ad264f92cf9013685a38c883db874616a1c23121c8a7b73ecd

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_embed_ollama-0.1.3.tar.gz:

Publisher: publish.yml on sukhbinder/llm-embed-ollama

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_embed_ollama-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_embed_ollama-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 194e7d388dc5f3db88c089436a9c85d6c7da6ff8ac2a22f5de8bee7cd68f9978
MD5 e6aa90c02bc90ba462232f8535c14da5
BLAKE2b-256 c674ce8220c4161d779394a4a76d442da159cb7808c62487bd3d249ceb5af9f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_embed_ollama-0.1.3-py3-none-any.whl:

Publisher: publish.yml on sukhbinder/llm-embed-ollama

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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