Metadata-Version: 2.5
Name: langchain-hobbylm
Version: 0.1.1
Summary: LangChain integration for HobbyLM-Embed, a local English embedding model from Fuel Labs
Project-URL: Homepage, https://huggingface.co/harims95/hobbylm-embed-140m
Author: Fuel Labs
License: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: langchain-core<2.0.0,>=1.0.0
Requires-Dist: sentence-transformers>=3.0.0
Provides-Extra: test
Requires-Dist: pytest>=8.0.0; extra == 'test'
Description-Content-Type: text/markdown

# langchain-hobbylm

LangChain wrapper for [HobbyLM-Embed](https://huggingface.co/harims95/hobbylm-embed-140m),
a local English embedding model from Fuel Labs.

The model has 140M total parameters and 36M active (8 of 32 experts per token),
produces 512-dimensional vectors, and reads 512 tokens by default (up to 2,048 if you raise the limit). License:
Apache-2.0. It scored 62.33 on MTEB(eng, v2), submitted to the official
leaderboard.

Training compute was provided by Jarvis Labs.

This package is a draft until it is published to PyPI. Do not `pip install
langchain-hobbylm` from PyPI until Fuel Labs has published it. [TO CONFIRM]
repo and PyPI ownership.

## Install

```bash
pip install langchain-hobbylm
```

Until the package is on PyPI, install from the local checkout:

```bash
pip install -e .
```

You also need a working `sentence-transformers` install. Hari tested the model
with sentence-transformers 6.3.0 and transformers 5.23.0.

## Use it

```python
from langchain_hobbylm import HobbyLMEmbeddings

embeddings = HobbyLMEmbeddings()

query_vector = embeddings.embed_query("How do I load HobbyLM-Embed?")
doc_vectors = embeddings.embed_documents(
    ["HobbyLM-Embed runs locally on your machine."]
)
print(len(query_vector), len(doc_vectors[0]))
# 512 512
```

512 tokens by default; for long documents use HobbyLMEmbeddings(model_kwargs={"tokenizer_kwargs": {"model_max_length": 2048}})

Pinned to revision ea708cee (full sha `ea708cee107818fa0c1871eebd26d82a1e3fb1aa`) by default; pass `revision=` to change it.

`embed_query` calls `encode` with `prompt_name="query"` and
`embed_documents` uses `prompt_name="passage"`. The model adds `query: ` or
`passage: ` itself. Pass raw text. Do not also type the prefixes.

`trust_remote_code=True` is required and is the default. The model uses
custom mixture-of-experts code.

Extra normalisation is not applied by default. The model already outputs
unit-length vectors (norm 1.0), so cosine equals the dot product.
`normalize_embeddings=True` is harmless if you want to set it.

For classification, clustering or similarity, do not use this wrapper's
query/document methods. Encode plain text with Sentence Transformers and no
`prompt_name`:

```python
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("harims95/hobbylm-embed-140m", trust_remote_code=True)
emb = model.encode(["what is an embedding?"])
print(emb.shape)
# (1, 512)
```

That canonical load snippet was tested by Hari. `encode_query` and
`encode_document` also work.

## Day-one alternative

You do not need this package to use the model in LangChain. The generic
route is `HuggingFaceEmbeddings` from `langchain-huggingface`:

```bash
pip install langchain-huggingface
```

```python
from langchain_huggingface import HuggingFaceEmbeddings

embeddings = HuggingFaceEmbeddings(
    model_name="harims95/hobbylm-embed-140m",
    model_kwargs={"trust_remote_code": True},
    encode_kwargs={"prompt_name": "passage"},
    query_encode_kwargs={"prompt_name": "query"},
)
```

See the official
[Sentence Transformers page](https://python.langchain.com/docs/integrations/text_embedding/sentence_transformers/).

## Model

- Hugging Face: https://huggingface.co/harims95/hobbylm-embed-140m
- GitHub: https://github.com/fuellabs-ai/hobbylm-embed-140m
- Architecture: sparse mixture of experts, 12 layers, 8 of 32 experts per token
- Language: English
- License: Apache-2.0

## License

This package is Apache-2.0, matching the model.
