mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
feat(functions): expose retry policies in Python and Rust (#4873)
Expose `FunctionRetryPolicy` on Function declarations and refresh overrides, together with `error_policy` and recorded attempt counts. Python uses the Rust validation rules before sending a request; local refreshes reject these Enterprise options. The policy bounds calls and backoff, supports class/message/provider-code matching, and can disable retries with `max_attempts=1`. Batch retry and skip operate on the whole failed call. Requires Enterprise server support for the new policy. Validation: rebuilt the Python extension; 47 targeted Python tests and 10 Rust tests passed. Python `make check`, Rust formatting, and `cargo clippy --features remote --tests --examples -- -D warnings` passed. The additional repository-root Ruff sweep reports existing errors under `docs/web-tests`; the Python workspace checks pass. Draft user guidance covers the supporting server requirement, safe repetition of partial work and whole-batch exhaustion. The guide sections stay hidden until release. Vale 3.24.0 passed for the added draft prose; no paired deployed SDK/server retry acceptance was run. Companion server: https://github.com/lancedb/sophon/pull/9812. BREAKING CHANGE: Rust callers constructing `FunctionRegistrationRequest` or `FunctionErrorRecord` with struct literals must supply the new `retry_policy` or `attempts` field, respectively.
This commit is contained in:
@@ -159,6 +159,34 @@ def test_function_execution_controls_apply_to_vectorized_functions():
|
||||
assert request["row_timeout_seconds"] == 1.25
|
||||
|
||||
|
||||
def test_function_retry_policy_is_part_of_registration():
|
||||
policy = lancedb.FunctionRetryPolicy(transient=True, max_attempts=4)
|
||||
definition = function(retry_policy=policy)(normalize_score.__wrapped__)
|
||||
request = json.loads(definition.registration_request.to_canonical_json())
|
||||
assert request["retry_policy"] == {"max_attempts": 4, "transient": True}
|
||||
assert lancedb.FunctionRetryPolicy(max_attempts=1).max_attempts == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"options",
|
||||
[
|
||||
{"max_attempts": 0, "transient": True},
|
||||
{"max_attempts": 101, "transient": True},
|
||||
{"max_attempts": True},
|
||||
{"max_attempts": 3},
|
||||
{"transient": True, "initial_backoff_seconds": -1},
|
||||
{"transient": True, "max_backoff_seconds": float("inf")},
|
||||
{"transient": True, "max_backoff_seconds": 0},
|
||||
{"message_pattern": "["},
|
||||
{"exception_types": [""]},
|
||||
{"transient": True, "typo": 1},
|
||||
],
|
||||
)
|
||||
def test_function_retry_policy_rejects_invalid_options(options):
|
||||
with pytest.raises(ValueError):
|
||||
lancedb.FunctionRetryPolicy(**options)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("options", "field"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user