Skip to content

[Feature Request]: Enable parallel processing for SentenceTransformerEmbeddingFunction #6903

@Ashish-Abraham

Description

@Ashish-Abraham

Describe the problem

SentenceTransformerEmbeddingFunction does not expose any of the parallelism parameters that sentence-transformers natively supports. The __call__ method hard-codes only two arguments:

embeddings = self._model.encode(
    list(input),
    convert_to_numpy=True,
    normalize_embeddings=self.normalize_embeddings,
)

This means batch_size, pool, and multi-device encoding are silently unavailable. When embedding large document sets locally, this forces users to either subclass the wrapper themselves or pre-compute embeddings outside Chroma entirely — defeating the purpose of the built-in embedding function.

Describe the proposed solution

Add two optional parameters to SentenceTransformerEmbeddingFunction:

batch_size: int = 32 — passed directly to .encode(). Controls how many documents are processed per forward pass. No behaviour change for existing users.
multiprocess_devices: list[str] | None = None — when provided, starts a persistent sentence-transformers multi-process pool across the given devices (e.g. ["cuda:0", "cuda:1"] or ["cpu", "cpu", "cpu", "cpu"]). Pool is created once in __init__ and reused across every __call__ to avoid process-spawn overhead per batch.

Both parameters default to existing behaviour, so the change is fully backward compatible.

Alternatives considered

  • Using FastEmbedEmbeddingFunction — FastEmbed does expose batch_size and parallel ([ENH]: FastEmbed embedding function support #1986), but it is a different library with a different model registry. It is not a drop-in replacement for users already on sentence-transformers models.
  • Pre-computing embeddings outside Chroma — users can pass pre-computed embeddings directly to .add(), but this breaks the collection-level embedding function contract and requires managing embedding logic outside Chroma.

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions