Embedding Python APIs silently return without processing input when batch_size is zero
On commit 764dc386c58b625f3ad9d203e699715ad208455f (0.36), passing batch_size=0 to EmbeddingModel.embed_multi() or Collection.embed_multi() returns without embedding anything and without raising an error. The metadata variant has the same behavior.
Minimal reproduction, requiring no external model service:
import llm
class DemoModel(llm.EmbeddingModel):
model_id = "local-demo"
def embed_batch(self, items, *, key=None):
for item in items:
yield [float(len(item))]
model = DemoModel()
print(list(model.embed_multi(["hello"], batch_size=0))) # []
collection = llm.Collection("demo", model=model)
collection.embed_multi([("1", "hello")], batch_size=0)
print(collection.count()) # 0, no exceptionExpected: reject a nonpositive batch size with a clear ValueError, before consuming input or calling the model.
The zero-size batch produces an empty islice(), which is interpreted as the end of the input. A negative size currently raises an implementation-level islice() error instead. A model whose default batch_size is zero also silently returns no results from EmbeddingModel.embed_multi().
This report concerns the Python APIs. The CLI currently treats --batch-size 0 as an omitted option and is outside this proposed change.
Source: simonw/llm