Repository navigation
Description
LanceDB version
0.40.0(also reproduced againstmain` @ 0aa842b by reading the code)
What happened?
retry_with_exponential_backoff (python/python/lancedb/embeddings/utils.py) has two problems:
delay *= exponential_base * (1 + jitter * random.random())multiplies the delay by 2-4x on every retry,
and there is no maximum delay._is_non_retryable_erroronly skipsAuthenticationErrorand HTTP 401/403, so permanent client errors
(400 bad request, 404 model not found, 422) are retried the fullmax_retries(default 7,
embeddings/base.py).
So a typo'd model name looks like a hang. With a 404 and 200 random seeds the total sleep before giving up was
min 14 min, median 50 min, max 2.5 h (sleeps like [3.7, 13, 37, 93, 280, 788, 2811] s). With the real OpenAI
client against a local server that returns HTTP 404 "model does not exist": table.add() made 8 requests and
would sleep 29 min, and table.search() made 8 requests and would sleep 71 min.
Expected: permanent errors fail on the first attempt with the provider's message; transient errors are retried
with a bounded backoff.
Also, from table.add() the final error is the confusing
RuntimeError: Arrow error: C Data interface error: Unknown error: ('Maximum number of retries ..., because
the exception is raised inside the reader generator.
Are there known steps to reproduce?
# time.sleep is patched so this runs in seconds and reports the time that would be spent
import random, tempfile
from unittest import mock
import lancedb
from lancedb.embeddings import TextEmbeddingFunction, register
from lancedb.pydantic import LanceModel, Vector
attempts = []
class NotFoundError(Exception): # same shape as openai.NotFoundError
status_code = 404
@register("always-404")
class Always404(TextEmbeddingFunction): # default max_retries=7
def ndims(self):
return 4
def generate_embeddings(self, texts):
attempts.append(1)
raise NotFoundError("The model `typo-embed` does not exist")
func = Always404.create()
class Doc(LanceModel):
text: str = func.SourceField()
vector: Vector(4) = func.VectorField()
table = lancedb.connect(tempfile.mkdtemp()).create_table("t", schema=Doc)
for label, op in [
("table.add", lambda: table.add([{"text": "hello"}])),
("table.search", lambda: table.search("hello").limit(1).to_list()),
]:
random.seed(0)
attempts.clear()
sleeps = []
with mock.patch("time.sleep", sleeps.append):
try:
op()
except Exception as e:
err = e
print(f"{label}: attempts={len(attempts)} sleeps={[round(s) for s in sleeps]} "
f"total={sum(sleeps) / 60:.1f} min\n error: {str(err)[:110]}")
# main: attempts=8 sleeps=[4, 13, 37, 93, 280, 788, 2811] total=67.1 min
Activity
fix(python): stop retrying permanent embedding errors and cap the bac…