Skip to content

Commit ff268ea

Browse files
g-despotclaude
andcommitted
docs: improve Boost API docstrings (consistency, clarity, accuracy)
Polish the docstrings for the Boost API (the Boost class, its factory methods, the Curve/Modifier enums, and the boost= parameter): - Document the boost= parameter in the Args of all 14 query and generate methods (hybrid, near_text, near_object, near_vector, near_image, near_media, bm25). It was present in every signature but documented in none. - Correct the documented defaults and semantics to match server behavior: weight (blend weight in [0, 1], default 0.5, (1 - weight)*primary + weight*boost, 0 is a no-op), depth (the overfetched candidate pool, default 100), curve (default exp), decay value (range (0, 1], default 0.5), offset (default 0), and blend's per-condition weight (default 1.0, may be negative) plus the 20-condition cap. - Unify terminology and add Attributes blocks describing the Curve and Modifier enum members. Docstrings only -- no API or behavior changes. Defaults verified against the server implementation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cccff14 commit ff268ea

15 files changed

Lines changed: 130 additions & 51 deletions

File tree

weaviate/collections/classes/grpc.py

Lines changed: 116 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,52 @@ def _decay_origin_to_str(val: Union[str, datetime]) -> str:
341341

342342

343343
class _BoostCurve(str, BaseEnum):
344-
"""Decay curve type for distance-based boost scoring."""
344+
"""The decay curve used by a distance-based boost (`time_decay`, `numeric_decay`).
345+
346+
Each curve scores 1 at the origin and falls to the `decay` value at `scale` distance.
347+
348+
Attributes:
349+
EXPONENTIAL: Heavy-tailed decay that halves geometrically. The default if no curve is set.
350+
GAUSSIAN: Bell-shaped decay with a sharp falloff once past `scale`.
351+
LINEAR: Straight-line decay that reaches zero beyond `scale`.
352+
"""
345353

346354
EXPONENTIAL = "exp"
347355
GAUSSIAN = "gauss"
348356
LINEAR = "linear"
349357

350358

351359
class _BoostModifier(str, BaseEnum):
352-
"""Score modifier for property-value boost scoring."""
360+
"""The transform applied to a numeric property's value in `numeric_property` before normalization.
361+
362+
Use a modifier to dampen values that span many orders of magnitude. If no modifier is
363+
set, the raw value is used.
364+
365+
Attributes:
366+
LOG1P: Apply `log(1 + value)` for strong long-tail dampening.
367+
SQRT: Apply `sqrt(value)` for milder long-tail dampening.
368+
"""
353369

354370
LOG1P = "log1p"
355371
SQRT = "sqrt"
356372

357373

358374
class Boost:
359-
"""Define soft-scoring conditions to boost or demote matching documents without excluding them.
375+
"""Soft-rank search results: promote or demote objects without removing them from the result set.
360376
361-
Use the static methods `filter()`, `time_decay()`, `numeric_decay()`, `numeric_property()`, and `blend()` to create boost configurations.
377+
A boost is a query-time rescorer. The primary search (vector, hybrid, or BM25) fetches a pool of
378+
candidates, the boost re-scores them against its conditions, and the results are re-sorted. Unlike
379+
a filter, a boost never excludes objects: non-matching objects stay in the result set but rank lower.
380+
381+
Use the static methods to build a boost, then pass it to a query or generate method via `boost=`:
382+
383+
- `filter()`: promote or demote objects matching a filter condition.
384+
- `time_decay()`: rank by recency, decaying with distance from an origin date.
385+
- `numeric_decay()`: rank by closeness to a target numeric value.
386+
- `numeric_property()`: rank by a numeric property's raw value.
387+
- `blend()`: combine several of the above, each with its own weight.
388+
389+
Available in Weaviate `v1.38` and later.
362390
"""
363391

364392
Curve = _BoostCurve
@@ -374,12 +402,20 @@ def filter( # noqa: A003
374402
weight: Optional[float] = None,
375403
depth: Optional[int] = None,
376404
) -> BoostReturn:
377-
"""Boost or demote results matching a filter condition.
405+
"""Promote or demote objects that match a filter condition.
406+
407+
Matching objects score 1 and non-matching objects score 0, so this acts as a soft `WHERE`:
408+
non-matching objects are demoted but stay in the result set.
378409
379410
Args:
380-
filter: The filter condition (same as used in `filters=` parameter).
381-
weight: Weight controlling how much the boost affects final scores. Uses the server-side default if not set.
382-
depth: Number of results to rescore. Uses the server-side default if not set. Higher values improve accuracy at the cost of performance.
411+
filter: The filter condition, built the same way as for the `filters=` parameter.
412+
Only `Equal`, `NotEqual`, the comparison operators, and `And`/`Or`/`Not` are supported.
413+
weight: How much the boost influences the final score, in `[0, 1]`: the result is
414+
`(1 - weight)` of the primary score plus `weight` of the boost score. `0` is a no-op.
415+
If not set, the server default of `0.5` is used.
416+
depth: How many candidates the primary search fetches for the boost to re-score.
417+
Higher values let the boost reorder more results, at the cost of performance.
418+
If not set, the server default (`100`) is used.
383419
"""
384420
return _Boost(conditions=[_BoostCondition(filter=filter)], weight=weight, depth=depth)
385421

@@ -395,21 +431,29 @@ def time_decay(
395431
weight: Optional[float] = None,
396432
depth: Optional[int] = None,
397433
) -> BoostReturn:
398-
"""Apply time-based decay scoring from an origin date.
434+
"""Rank objects by recency: the score decays with distance from an origin date.
435+
436+
Objects at the origin score 1; the score falls along the chosen `curve` as the property
437+
value moves away from the origin. Use this to favour more recent (or near-a-date) objects.
399438
400439
Args:
401-
property: The date property name to compute distance from.
402-
origin: The origin point. Use "now" for current time or a datetime for a specific time.
403-
Defaults to "now".
404-
scale: Distance from origin where score equals decay. Use timedelta
405-
(e.g. timedelta(days=7)) or a string shorthand like "7d", "24h".
406-
offset: Documents within this distance from origin get full score.
407-
Accepts the same types as scale. Uses the server-side default if not set.
408-
curve: Decay curve type: `Boost.Curve.EXPONENTIAL`, `Boost.Curve.GAUSSIAN`, or `Boost.Curve.LINEAR`.
409-
Uses the server-side default if not set.
410-
decay: Score at scale distance from origin. Uses the server-side default if not set.
411-
weight: Weight controlling how much the boost affects final scores. Uses the server-side default if not set.
412-
depth: Number of results to rescore. Uses the server-side default if not set.
440+
property: The name of the `date` property to measure distance from.
441+
origin: The reference point. Use `"now"` for the current time or a `datetime` for a
442+
specific time. Defaults to `"now"`.
443+
scale: The distance from the origin at which the score equals `decay`. Use a `timedelta`
444+
(e.g. `timedelta(days=7)`) or a duration string such as `"7d"`, `"24h"`, `"30m"`.
445+
offset: Objects within this distance from the origin keep the full score of 1; decay
446+
starts beyond it. Accepts the same types as `scale`. If not set, no offset is applied.
447+
curve: The decay curve: `Boost.Curve.EXPONENTIAL`, `Boost.Curve.GAUSSIAN`, or
448+
`Boost.Curve.LINEAR`. If not set, the server default (`EXPONENTIAL`) is used.
449+
decay: The score at `scale` distance from the origin, in `(0, 1]`. If not set, the
450+
server default of `0.5` is used.
451+
weight: How much the boost influences the final score, in `[0, 1]`: the result is
452+
`(1 - weight)` of the primary score plus `weight` of the boost score. `0` is a no-op.
453+
If not set, the server default of `0.5` is used.
454+
depth: How many candidates the primary search fetches for the boost to re-score.
455+
Higher values let the boost reorder more results, at the cost of performance.
456+
If not set, the server default (`100`) is used.
413457
"""
414458
return _Boost(
415459
conditions=[
@@ -440,22 +484,28 @@ def numeric_decay(
440484
weight: Optional[float] = None,
441485
depth: Optional[int] = None,
442486
) -> BoostReturn:
443-
"""Score decays with distance from a numeric origin — closer to the origin ranks higher.
487+
"""Rank objects by closeness to a target numeric value: the score decays with distance from it.
444488
445-
Use this when "closer to X is better" (e.g., prefer prices near $50, apartments near 80 ).
446-
Requires you to define an origin and scale. For simple "higher is better" boosting without
447-
an origin, use `Boost.numeric_property()` instead.
489+
Use this when "closer to X is better" (e.g. prefer prices near $50, apartments near 80 m2).
490+
Requires an origin and a scale. For simple "higher is better" ranking without an origin,
491+
use `Boost.numeric_property()` instead.
448492
449493
Args:
450-
property: The numeric property name to compute distance from.
451-
origin: The target value — documents closest to this score highest.
452-
scale: Distance from origin where score equals the decay value.
453-
offset: Documents within this distance from origin get full score. Uses the server-side default if not set.
454-
curve: Decay curve type: `Boost.Curve.EXPONENTIAL`, `Boost.Curve.GAUSSIAN`, or `Boost.Curve.LINEAR`.
455-
Uses the server-side default if not set.
456-
decay: Score at scale distance from origin. Uses the server-side default if not set.
457-
weight: Weight controlling how much the boost affects final scores. Uses the server-side default if not set.
458-
depth: Number of results to rescore. Uses the server-side default if not set.
494+
property: The name of the numeric (`int`/`number`) property to measure distance from.
495+
origin: The target value; objects closest to it score highest.
496+
scale: The distance from the origin at which the score equals `decay`.
497+
offset: Objects within this distance from the origin keep the full score of 1; decay
498+
starts beyond it. If not set, no offset is applied.
499+
curve: The decay curve: `Boost.Curve.EXPONENTIAL`, `Boost.Curve.GAUSSIAN`, or
500+
`Boost.Curve.LINEAR`. If not set, the server default (`EXPONENTIAL`) is used.
501+
decay: The score at `scale` distance from the origin, in `(0, 1]`. If not set, the
502+
server default of `0.5` is used.
503+
weight: How much the boost influences the final score, in `[0, 1]`: the result is
504+
`(1 - weight)` of the primary score plus `weight` of the boost score. `0` is a no-op.
505+
If not set, the server default of `0.5` is used.
506+
depth: How many candidates the primary search fetches for the boost to re-score.
507+
Higher values let the boost reorder more results, at the cost of performance.
508+
If not set, the server default (`100`) is used.
459509
"""
460510
return _Boost(
461511
conditions=[
@@ -482,20 +532,26 @@ def numeric_property(
482532
weight: Optional[float] = None,
483533
depth: Optional[int] = None,
484534
) -> BoostReturn:
485-
"""Boost by a numeric property's raw value higher values rank higher.
535+
"""Rank objects by a numeric property's raw value: higher values rank higher.
486536
487-
Use this for simple proportional boosting (e.g., popularity count, review score)
488-
when you don't need to define an origin or scale. For distance-based decay from a
489-
specific value, use `Boost.numeric_decay()` instead.
537+
Use this for simple proportional ranking (e.g. popularity count, review score) when you
538+
don't need an origin or scale. For distance-based decay from a target value, use
539+
`Boost.numeric_decay()` instead.
490540
491-
Only supports numeric (int/float) properties. To boost by other property types, use `Boost.filter()`.
541+
Only supports numeric (`int`/`number`) properties. To rank by other property types, use
542+
`Boost.filter()`.
492543
493544
Args:
494-
name: The numeric property name to use as a ranking signal.
495-
modifier: Score modifier: `Boost.Modifier.LOG1P` or `Boost.Modifier.SQRT` to dampen
496-
the effect of large value ranges. If not set, the raw value is used.
497-
weight: Weight controlling how much the boost affects final scores. Uses the server-side default if not set.
498-
depth: Number of results to rescore. Uses the server-side default if not set.
545+
name: The name of the numeric property to use as a ranking signal.
546+
modifier: A transform applied to the value before normalization: `Boost.Modifier.LOG1P`
547+
or `Boost.Modifier.SQRT`, both of which dampen values that span many orders of
548+
magnitude. If not set, the raw value is used.
549+
weight: How much the boost influences the final score, in `[0, 1]`: the result is
550+
`(1 - weight)` of the primary score plus `weight` of the boost score. `0` is a no-op.
551+
If not set, the server default of `0.5` is used.
552+
depth: How many candidates the primary search fetches for the boost to re-score.
553+
Higher values let the boost reorder more results, at the cost of performance.
554+
If not set, the server default (`100`) is used.
499555
"""
500556
return _Boost(
501557
conditions=[
@@ -517,18 +573,27 @@ def blend(
517573
weight: Optional[float] = None,
518574
depth: Optional[int] = None,
519575
) -> BoostReturn:
520-
"""Combine multiple boost conditions with individual weights.
576+
"""Combine several boosts into one, each weighted relative to the others.
521577
522-
When blending, each sub-boost's weight becomes a per-condition weight,
523-
and the `weight` parameter here controls the overall blending strength.
578+
Each input boost's `weight` becomes a per-condition weight, balancing the conditions
579+
against each other (e.g. recency twice as important as popularity). A per-condition weight
580+
defaults to `1.0` and may be negative to actively demote matching objects. The `weight`
581+
argument here is separate: it sets the overall strength of the combined boost. A boost may
582+
carry at most 20 conditions in total.
524583
525584
Args:
526-
boosts: One or more Boost objects created via `Boost.filter()`, `Boost.time_decay()`, `Boost.numeric_decay()`, or `Boost.numeric_property()`.
527-
weight: Overall blending weight [0,1] for combining primary search and boost scores. Uses the server-side default if not set.
528-
depth: Number of results to rescore. Uses the server-side default if not set. Higher values improve accuracy at the cost of performance.
585+
boosts: One or more boosts created via `Boost.filter()`, `Boost.time_decay()`,
586+
`Boost.numeric_decay()`, or `Boost.numeric_property()`.
587+
weight: How much the combined boost influences the final score, in `[0, 1]`: the result
588+
is `(1 - weight)` of the primary score plus `weight` of the boost score. `0` is a
589+
no-op. If not set, the server default of `0.5` is used.
590+
depth: How many candidates the primary search fetches for the boost to re-score.
591+
Higher values let the boost reorder more results, at the cost of performance.
592+
If not set, the server default (`100`) is used.
529593
530594
Raises:
531-
WeaviateInvalidInputError: If no boosts are provided or if any sub-boost has `depth` set.
595+
WeaviateInvalidInputError: If no boosts are provided, or if any input boost has its own
596+
`depth` set (set `depth` here on `blend()` instead).
532597
"""
533598
if isinstance(boosts, _Boost):
534599
boosts = [boosts]

weaviate/collections/queries/bm25/generate/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ def bm25(
396396
filters: The filters to apply to the search.
397397
group_by: How the results should be grouped by a specific property.
398398
rerank: How the results should be reranked. NOTE: A `rerank-*` module must be enabled for this functionality to work.
399+
boost: A `Boost` that re-scores the search candidates to promote or demote objects without removing them. Build one with `Boost.filter()`, `Boost.time_decay()`, `Boost.numeric_decay()`, `Boost.numeric_property()`, or `Boost.blend()`.
399400
include_vector: Whether to include the vector in the results. If not specified, this is set to False.
400401
return_metadata: The metadata to return for each object, defaults to `None`.
401402
return_properties: The properties to return for each object.

weaviate/collections/queries/bm25/query/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def bm25(
331331
filters: The filters to apply to the search.
332332
group_by: How the results should be grouped by a specific property.
333333
rerank: How the results should be reranked. NOTE: A `rerank-*` module must be enabled for this functionality to work.
334+
boost: A `Boost` that re-scores the search candidates to promote or demote objects without removing them. Build one with `Boost.filter()`, `Boost.time_decay()`, `Boost.numeric_decay()`, `Boost.numeric_property()`, or `Boost.blend()`.
334335
include_vector: Whether to include the vector in the results. If not specified, this is set to False.
335336
return_metadata: The metadata to return for each object, defaults to `None`.
336337
return_properties: The properties to return for each object.

weaviate/collections/queries/hybrid/generate/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ def hybrid(
475475
filters: The filters to apply to the search.
476476
group_by: How the results should be grouped by a specific property.
477477
rerank: How the results should be reranked. NOTE: A `rerank-*` module must be enabled for this functionality to work.
478+
boost: A `Boost` that re-scores the search candidates to promote or demote objects without removing them. Build one with `Boost.filter()`, `Boost.time_decay()`, `Boost.numeric_decay()`, `Boost.numeric_property()`, or `Boost.blend()`.
478479
target_vector: The name of the vector space to search in for named vector configurations. Required if multiple spaces are configured.
479480
include_vector: Whether to include the vector in the results. If not specified, this is set to False.
480481
return_metadata: The metadata to return for each object, defaults to `None`.

weaviate/collections/queries/hybrid/query/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def hybrid(
411411
filters: The filters to apply to the search.
412412
group_by: How the results should be grouped by a specific property.
413413
rerank: How the results should be reranked. NOTE: A `rerank-*` module must be enabled for this functionality to work.
414+
boost: A `Boost` that re-scores the search candidates to promote or demote objects without removing them. Build one with `Boost.filter()`, `Boost.time_decay()`, `Boost.numeric_decay()`, `Boost.numeric_property()`, or `Boost.blend()`.
414415
target_vector: The name of the vector space to search in for named vector configurations. Required if multiple spaces are configured.
415416
include_vector: Whether to include the vector in the results. If not specified, this is set to False.
416417
return_metadata: The metadata to return for each object, defaults to `None`.

weaviate/collections/queries/near_image/generate/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def near_image(
430430
filters: The filters to apply to the search.
431431
group_by: How the results should be grouped by a specific property.
432432
rerank: How the results should be reranked. NOTE: A `rerank-*` module must be enabled for this functionality to work.
433+
boost: A `Boost` that re-scores the search candidates to promote or demote objects without removing them. Build one with `Boost.filter()`, `Boost.time_decay()`, `Boost.numeric_decay()`, `Boost.numeric_property()`, or `Boost.blend()`.
433434
target_vector: The name of the vector space to search in for named vector configurations. Required if multiple spaces are configured.
434435
include_vector: Whether to include the vector in the results. If not specified, this is set to False.
435436
return_metadata: The metadata to return for each object, defaults to `None`.

weaviate/collections/queries/near_image/query/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ def near_image(
369369
filters: The filters to apply to the search.
370370
group_by: How the results should be grouped by a specific property.
371371
rerank: How the results should be reranked. NOTE: A `rerank-*` module must be enabled for this functionality to work.
372+
boost: A `Boost` that re-scores the search candidates to promote or demote objects without removing them. Build one with `Boost.filter()`, `Boost.time_decay()`, `Boost.numeric_decay()`, `Boost.numeric_property()`, or `Boost.blend()`.
372373
target_vector: The name of the vector space to search in for named vector configurations. Required if multiple spaces are configured.
373374
include_vector: Whether to include the vector in the results. If not specified, this is set to False.
374375
return_metadata: The metadata to return for each object, defaults to `None`.

0 commit comments

Comments
 (0)