Skip to content

Commit 922e15f

Browse files
authored
Merge pull request #1745 from weaviate/rq_add_rescore_limit
RQ: Add rescoreLimit parameter
2 parents c45f21f + 170cb8f commit 922e15f

File tree

7 files changed

+15
-4
lines changed

7 files changed

+15
-4
lines changed

integration/test_collection_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ def test_hnsw_with_rq(collection_factory: CollectionFactory) -> None:
622622
collection = collection_factory(
623623
vector_index_config=Configure.VectorIndex.hnsw(
624624
vector_cache_max_objects=5,
625-
quantizer=Configure.VectorIndex.Quantizer.rq(bits=8),
625+
quantizer=Configure.VectorIndex.Quantizer.rq(bits=8, rescore_limit=20),
626626
),
627627
)
628628

@@ -633,6 +633,7 @@ def test_hnsw_with_rq(collection_factory: CollectionFactory) -> None:
633633
assert isinstance(config.vector_index_config.quantizer, _RQConfig)
634634
assert config.vector_index_config.quantizer is not None
635635
assert config.vector_index_config.quantizer.bits == 8
636+
assert config.vector_index_config.quantizer.rescore_limit == 20
636637

637638

638639
@pytest.mark.parametrize(

mock_tests/mock_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"bq": {"enabled": False},
6565
"sq": {"enabled": False, "trainingLimit": 100000, "rescoreLimit": 20},
66-
"rq": {"enabled": False, "bits": 8},
66+
"rq": {"enabled": False, "bits": 8, "rescoreLimit": 20},
6767
},
6868
"vectorIndexType": "hnsw",
6969
"vectorizer": "text2vec-contextionary",

test/collection/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def multi_vector_schema(quantizer: Optional[Literal["pq", "bq", "sq", "rq"]] = N
6666
"rq": {
6767
"enabled": quantizer == "rq",
6868
"bits": 8,
69+
"rescoreLimit": 20,
6970
},
7071
},
7172
"vectorIndexType": "hnsw",
@@ -101,6 +102,7 @@ def multi_vector_schema(quantizer: Optional[Literal["pq", "bq", "sq", "rq"]] = N
101102
"rq": {
102103
"enabled": quantizer == "rq",
103104
"bits": 8,
105+
"rescoreLimit": 20,
104106
},
105107
},
106108
"vectorIndexType": "hnsw",

test/collection/test_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,13 +1368,14 @@ def test_vector_config_hnsw_sq() -> None:
13681368
def test_vector_config_hnsw_rq() -> None:
13691369
vector_index = Configure.VectorIndex.hnsw(
13701370
ef_construction=128,
1371-
quantizer=Configure.VectorIndex.Quantizer.rq(bits=8),
1371+
quantizer=Configure.VectorIndex.Quantizer.rq(bits=8, rescore_limit=123),
13721372
)
13731373

13741374
vi_dict = vector_index._to_dict()
13751375

13761376
assert vi_dict["efConstruction"] == 128
13771377
assert vi_dict["rq"]["bits"] == 8
1378+
assert vi_dict["rq"]["rescoreLimit"] == 123
13781379

13791380

13801381
def test_vector_config_flat_pq() -> None:

weaviate/collections/classes/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ class _SQConfig(_ConfigBase):
15011501
@dataclass
15021502
class _RQConfig(_ConfigBase):
15031503
bits: Optional[int]
1504+
rescore_limit: int
15041505

15051506

15061507
BQConfig = _BQConfig
@@ -2220,6 +2221,7 @@ def sq(
22202221

22212222
@staticmethod
22222223
def rq(
2224+
rescore_limit: Optional[int] = None,
22232225
enabled: bool = True,
22242226
) -> _RQConfigUpdate:
22252227
"""Create a `_RQConfigUpdate` object to be used when updating the Rotational quantization (RQ) configuration of Weaviate.
@@ -2229,7 +2231,7 @@ def rq(
22292231
Arguments:
22302232
See [the docs](https://weaviate.io/developers/weaviate/concepts/vector-index#hnsw-with-compression) for a more detailed view!
22312233
""" # noqa: D417 (missing argument descriptions in the docstring)
2232-
return _RQConfigUpdate(enabled=enabled)
2234+
return _RQConfigUpdate(enabled=enabled, rescoreLimit=rescore_limit)
22332235

22342236

22352237
class _VectorIndexUpdate:

weaviate/collections/classes/config_methods.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def __get_quantizer_config(
151151
elif "rq" in config and config["rq"].get("enabled"):
152152
quantizer = _RQConfig(
153153
bits=config["rq"].get("bits"),
154+
rescore_limit=config["rq"].get("rescoreLimit"),
154155
)
155156
return quantizer
156157

weaviate/collections/classes/config_vector_index.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def quantizer_name() -> str:
273273

274274
class _RQConfigCreate(_QuantizerConfigCreate):
275275
bits: Optional[int]
276+
rescoreLimit: Optional[int]
276277

277278
@staticmethod
278279
def quantizer_name() -> str:
@@ -303,6 +304,7 @@ def quantizer_name() -> str:
303304

304305
class _RQConfigUpdate(_QuantizerConfigUpdate):
305306
enabled: Optional[bool]
307+
rescoreLimit: Optional[int]
306308

307309
@staticmethod
308310
def quantizer_name() -> str:
@@ -432,6 +434,7 @@ def sq(
432434
@staticmethod
433435
def rq(
434436
bits: Optional[int] = None,
437+
rescore_limit: Optional[int] = None,
435438
) -> _RQConfigCreate:
436439
"""Create a `_RQConfigCreate` object to be used when defining the Rotational quantization (RQ) configuration of Weaviate.
437440
@@ -442,6 +445,7 @@ def rq(
442445
""" # noqa: D417 (missing argument descriptions in the docstring)
443446
return _RQConfigCreate(
444447
bits=bits,
448+
rescoreLimit=rescore_limit,
445449
)
446450

447451

0 commit comments

Comments
 (0)