Skip to main content

Endee Model

A Python library for generating sparse text embeddings using the BM25 algorithm. Designed for integration with vector databases to enable efficient keyword-based search alongside dense embeddings.

Installation

pip install endee-model

Quick Start

from endee_model import SparseModel

model = SparseModel(model_name="endee/bm25")

documents = [
    "The quick brown fox jumps over the lazy dog",
    "Machine learning enables computers to learn from data",
]

for embedding in model.embed(documents):
    print(embedding.as_dict())  # {token_id: weight, ...}

Usage

Embed Documents

from endee_model import SparseModel

model = SparseModel(model_name="endee/bm25")

documents = ["first document text", "second document text"]

# Returns a generator — iterate to get SparseEmbedding objects
for embedding in model.embed(documents, batch_size=256):
    sparse_dict = embedding.as_dict()       # {int: float}
    sparse_obj  = embedding.as_object()     # {'indices': array, 'values': array}

Embed Queries

query = "search query text"

for embedding in model.query_embed(query):
    print(embedding.as_dict())

Count Tokens

count = model.token_count("some text here")
print(f"Token count: {count}")

Work with SparseEmbedding Directly

from endee_model import SparseEmbedding

# Create from a {token_id: weight} dictionary
embedding = SparseEmbedding.from_dict({100: 0.5, 200: 0.8, 300: 1.2})

embedding.as_dict()    # {100: 0.5, 200: 0.8, 300: 1.2}
embedding.as_object()  # {'indices': array([100, 200, 300]), 'values': array([0.5, 0.8, 1.2])}

Configuration

SparseModel Parameters

Parameter Default Description
model_name required Model identifier (use "endee/bm25")
cache_dir None Custom cache directory (see Cache)
k 1.2 BM25 saturation parameter — controls term frequency saturation
b 0.75 Length normalization factor (0 = none, 1 = full)
language "english" Language for Snowball stemmer
max_token_len 40 Tokens longer than this are discarded
disable_stemmer False Skip stemming (enables more languages via NLTK stopwords only)
model = SparseModel(
    model_name="endee/bm25",
    k=1.5,
    b=0.8,
    language="english",
)

Available Languages

from endee_model.sparse.bm25 import bm25_languages

print(bm25_languages())  # List of supported Snowball stemmer languages

Cache

NLTK resources and model files are cached locally. The cache location is resolved in this order:

  1. cache_dir argument passed to SparseModel
  2. ENDEE_CACHE_PATH environment variable
  3. Default: {system_tmp}/endee_cache
export ENDEE_CACHE_PATH=/path/to/custom/cache

Requirements

  • Python >= 3.6
  • numpy >= 1.26.0, < 2.3
  • mmh3 >= 4.0.0
  • nltk >= 3.8.0

How It Works

  1. Normalization — punctuation is stripped, stopwords removed, oversized tokens discarded

  2. Stemming — tokens are reduced to stems using the Snowball stemmer (optional)

  3. BM25 weights — term-frequency weights are computed using the BM25 TF formula:

    tf_weight = tf * (k + 1) / (tf + k * (1 - b + b * (doc_len / avg_len)))
    

Note: BM25 IDF weighting must be applied on the vector index side. This library outputs TF weights only.

License

MIT License

Metadata

Release files for endee-model 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for endee-model 0.1.0
File Size Uploaded Provenance Actions
endee_model-0.1.0.tar.gz 8.6 kB Without provenance Details for endee_model-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for endee-model 0.1.0
File Interpreter ABI Platform Actions
endee_model-0.1.0-py3-none-any.whl Python 3 none any Details for endee_model-0.1.0-py3-none-any.whl

Total release size: 18.1 kB

Release files / endee_model-0.1.0.tar.gz

Download URL endee_model-0.1.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
13da94dfb4568f73c528e29cde8cb2e489d4931214b49efe05e241f0b3e822ed
BLAKE2b-256 checksum
How to use checksums
0b926ecf8bf6bfa5f71089979b45f7d08a22da7bcb8b53a044436ed3257ff768
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / endee_model-0.1.0-py3-none-any.whl

Download URL endee_model-0.1.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67d4d5c419163f2b117b5781ed32fe0b4728f9c7af4e65994d3490c0e38f9f5f
BLAKE2b-256 checksum
How to use checksums
c6b75b85ae56fe6b268bdc86a8529ebf6b23611301213c4b709f8c34b241f536
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Security for endee-model 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page