Skip to main content

Embeddings interface for Ollama

Project description

Ellama

Embeddings library

ollama unsloth faiss langchain

pca t-sne umap matplotlib

test

Unlike the overwhelming majority of alternatives:

  • handles long inputs without truncation even if the underlying model has a small context window
  • minimal config
  • 100% human-written (thus sane & clean) codebase

[!TIP] Please open an issue if you know of any better alternatives. I would love to archive this repo.

from ellama import EllamaDB, Document

db = EllamaDB("test")
db.add_documents([
    Document("hello world", id="salutation"),
    Document("goodbye and goodnight", id="farewell")])
docs = db.similarity_search("Greetings, Earth!", k=1)
assert len(docs) == 1
assert docs[0].id == "salutation"

plot

Embedding database visualisation:

import matplotlib.pyplot as plt
from ellama import EllamaDB, Document
from sklearn.datasets import fetch_20newsgroups

raw = fetch_20newsgroups(data_home='.cache')
db = EllamaDB("20newsgroups")
db.add_documents([
    Document(raw.data[i], id=str(i), metadata={'name': raw.target_names[raw.target[i]]})
    for i in range(200)])

for group in ['alt.atheism', 'comp', 'misc.forsale', 'rec', 'rec.sport', 'sci',
              'soc.religion', 'talk.politics', 'talk.religion']:
    db.plot('t-SNE', label=group,
            filter=lambda metadata: metadata['name'].startswith(f'{group}.'))

plt.title(f"Newsgroup {db.embeddings.model} embeddings t-SNE")
plt.legend()
plt.show()

fine-tune

Low-rank adaptation (LoRA) re-using the newsgroups database created above:

from ellama import EllamaDB
db = EllamaDB("20newsgroups")
db.lora(['name'], "ellama-lora:news", epochs=600)
# ollama create ellama-lora:news -f .cache/20newsgroups/lora/ellama-lora-news/Modelfile

# create new database using the new model
db_lora = EllamaDB("20newsgroups_lora", "ellama-lora:news", pull=False)
db_lora.add_documents(db.get_docs({}))

install

pip (CPU)

pip install "ellama[cpu]"           # basic
pip install "ellama[cpu,plot]"      # plot('PCA' or 't-SNE')
pip install "ellama[cpu,plot,umap]" # plot('UMAP')
pip install "ellama[lora]"          # fine-tuning

conda (GPU)

name: ellama
channels: [pytorch, nvidia, conda-forge]
dependencies:
- langchain 1.*
- langchain-community
- faiss-gpu
- requests
- tqdm
#- matplotlib   # ellama plot()
#- scikit-learn # ellama plot()
#- umap-learn   # ellama plot('UMAP')
#- unsloth      # ellama lora()
- pip
- pip:
  - ellama

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

ellama-0.4.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

ellama-0.4.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file ellama-0.4.0.tar.gz.

File metadata

  • Download URL: ellama-0.4.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for ellama-0.4.0.tar.gz
Algorithm Hash digest
SHA256 edaa10b360ce8a1bc496233ca501ff7617c9a943683bd6ab32370ac93d2c42fa
MD5 477a4693699a8f95e272b66334f0d186
BLAKE2b-256 ddba5ef39b542fc1530aa8ab60481c73ef5195d41542c1c0b2285e7c520aa65c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ellama-0.4.0.tar.gz:

Publisher: test.yml on casperdcl/ellama

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

File details

Details for the file ellama-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: ellama-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for ellama-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2b30fcc802fe66bae2988aa9654531ec4eb247e9101bda845c96d1e6b0f12b8
MD5 5814f0da817b38a2030b9cb1862dda63
BLAKE2b-256 c378e07b8de2bc8e7bab058768ff5635bac28964f81eeac2941243435fb61875

See more details on using hashes here.

Provenance

The following attestation bundles were made for ellama-0.4.0-py3-none-any.whl:

Publisher: test.yml on casperdcl/ellama

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