Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions integration/test_collection_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,46 @@ def test_hnsw_with_rq(collection_factory: CollectionFactory) -> None:
assert config.vector_index_config.quantizer.rescore_limit == 20


def test_hnsw_with_rq4c(collection_factory: CollectionFactory) -> None:
dummy = collection_factory("dummy")
if dummy._connection._weaviate_version.is_lower_than(1, 39, 2):
pytest.skip("RQ centering is not supported in Weaviate versions lower than 1.39.2")

collection = collection_factory(
vector_index_config=Configure.VectorIndex.hnsw(
vector_cache_max_objects=5,
quantizer=Configure.VectorIndex.Quantizer.rq(
bits=4, centering=True, rescore_limit=20, training_limit=5000
),
),
)

config = collection.config.get()
assert config.vector_index_type == VectorIndexType.HNSW
assert config.vector_index_config is not None
assert isinstance(config.vector_index_config, _VectorIndexConfigHNSW)
assert isinstance(config.vector_index_config.quantizer, _RQConfig)
assert config.vector_index_config.quantizer is not None
assert config.vector_index_config.quantizer.bits == 4
assert config.vector_index_config.quantizer.centering is True
assert config.vector_index_config.quantizer.rescore_limit == 20
assert config.vector_index_config.quantizer.training_limit == 5000
Comment thread
trengrj marked this conversation as resolved.

collection.config.update(
vector_index_config=Reconfigure.VectorIndex.hnsw(
quantizer=Reconfigure.VectorIndex.Quantizer.rq(rescore_limit=50, training_limit=10000),
),
)

config = collection.config.get()
assert isinstance(config.vector_index_config, _VectorIndexConfigHNSW)
assert isinstance(config.vector_index_config.quantizer, _RQConfig)
assert config.vector_index_config.quantizer.bits == 4
assert config.vector_index_config.quantizer.centering is True
assert config.vector_index_config.quantizer.rescore_limit == 50
assert config.vector_index_config.quantizer.training_limit == 10000


@pytest.mark.parametrize(
"vector_index_config",
[
Expand Down
17 changes: 17 additions & 0 deletions test/collection/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,23 @@ def test_vector_config_hnsw_rq() -> None:
assert vi_dict["rq"]["rescoreLimit"] == 123


def test_vector_config_hnsw_rq4c() -> None:
vector_index = Configure.VectorIndex.hnsw(
ef_construction=128,
quantizer=Configure.VectorIndex.Quantizer.rq(
bits=4, centering=True, rescore_limit=123, training_limit=5012
),
)

vi_dict = vector_index._to_dict()

assert vi_dict["efConstruction"] == 128
assert vi_dict["rq"]["bits"] == 4
assert vi_dict["rq"]["centering"] is True
assert vi_dict["rq"]["rescoreLimit"] == 123
assert vi_dict["rq"]["trainingLimit"] == 5012


def test_vector_config_flat_pq() -> None:
vector_index = Configure.VectorIndex.flat(
distance_metric=VectorDistances.DOT,
Expand Down
12 changes: 11 additions & 1 deletion weaviate/collections/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,8 @@ class _RQConfig(_ConfigBase):
cache: Optional[bool]
bits: Optional[int]
rescore_limit: int
centering: Optional[bool]
training_limit: Optional[int]


BQConfig = _BQConfig
Expand Down Expand Up @@ -2984,6 +2986,8 @@ def rq(
rescore_limit: Optional[int] = None,
enabled: bool = True,
bits: Optional[int] = None,
centering: Optional[bool] = None,
training_limit: Optional[int] = None,
) -> _RQConfigUpdate:
"""Create a `_RQConfigUpdate` object to be used when updating the Rotational quantization (RQ) configuration of Weaviate.

Expand All @@ -2992,7 +2996,13 @@ def rq(
Arguments:
See [the docs](https://weaviate.io/developers/weaviate/concepts/vector-index#hnsw-with-compression) for a more detailed view!
""" # noqa: D417 (missing argument descriptions in the docstring)
return _RQConfigUpdate(enabled=enabled, rescoreLimit=rescore_limit, bits=bits)
return _RQConfigUpdate(
enabled=enabled,
rescoreLimit=rescore_limit,
bits=bits,
centering=centering,
trainingLimit=training_limit,
)


class _VectorIndexUpdate:
Expand Down
2 changes: 2 additions & 0 deletions weaviate/collections/classes/config_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def __get_quantizer_config(
cache=config["rq"].get("cache"),
bits=config["rq"].get("bits"),
rescore_limit=config["rq"].get("rescoreLimit"),
centering=config["rq"].get("centering"),
training_limit=config["rq"].get("trainingLimit"),
)
return quantizer

Expand Down
8 changes: 8 additions & 0 deletions weaviate/collections/classes/config_vector_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ class _RQConfigCreate(_QuantizerConfigCreate):
cache: Optional[bool]
bits: Optional[int]
rescoreLimit: Optional[int]
centering: Optional[bool]
trainingLimit: Optional[int]

@staticmethod
def quantizer_name() -> str:
Expand Down Expand Up @@ -337,6 +339,8 @@ class _RQConfigUpdate(_QuantizerConfigUpdate):
enabled: Optional[bool]
rescoreLimit: Optional[int]
bits: Optional[int]
centering: Optional[bool]
trainingLimit: Optional[int]

@staticmethod
def quantizer_name() -> str:
Expand Down Expand Up @@ -486,6 +490,8 @@ def rq(
cache: Optional[bool] = None,
bits: Optional[int] = None,
rescore_limit: Optional[int] = None,
centering: Optional[bool] = None,
training_limit: Optional[int] = None,
) -> _RQConfigCreate:
"""Create a `_RQConfigCreate` object to be used when defining the Rotational quantization (RQ) configuration of Weaviate.

Expand All @@ -498,6 +504,8 @@ def rq(
cache=cache,
bits=bits,
rescoreLimit=rescore_limit,
centering=centering,
trainingLimit=training_limit,
)

@staticmethod
Expand Down
Loading