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
42 changes: 40 additions & 2 deletions weaviate/collections/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
_VectorIndexConfigDynamicUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshUpdate,
_VectorIndexConfigUpdate,
)
from weaviate.collections.classes.config_vector_index import (
Expand Down Expand Up @@ -1886,6 +1887,20 @@ def vector_index_type() -> str:

VectorIndexConfigHNSW = _VectorIndexConfigHNSW

@dataclass
class _VectorIndexConfigHFresh(_VectorIndexConfig):
distance_metric: VectorDistances
max_posting_size: int
min_posting_size: int
replicas: int
rng_factor: int
search_probe: int

@staticmethod
def vector_index_type() -> str:
return VectorIndexType.HFRESH.value

VectorIndexConfigHFresh = _VectorIndexConfigHFresh

@dataclass
class _VectorIndexConfigFlat(_VectorIndexConfig):
Expand Down Expand Up @@ -1960,7 +1975,7 @@ def to_dict(self) -> Dict[str, Any]:
class _NamedVectorConfig(_ConfigBase):
vectorizer: _NamedVectorizerConfig
vector_index_config: Union[
VectorIndexConfigHNSW, VectorIndexConfigFlat, VectorIndexConfigDynamic
VectorIndexConfigHNSW, VectorIndexConfigFlat, VectorIndexConfigDynamic, VectorIndexConfigHFresh
]

def to_dict(self) -> Dict:
Expand All @@ -1985,7 +2000,7 @@ class _CollectionConfig(_ConfigBase):
reranker_config: Optional[RerankerConfig]
sharding_config: Optional[ShardingConfig]
vector_index_config: Union[
VectorIndexConfigHNSW, VectorIndexConfigFlat, VectorIndexConfigDynamic, None
VectorIndexConfigHNSW, VectorIndexConfigFlat, VectorIndexConfigDynamic, VectorIndexConfigHFresh, None
]
vector_index_type: Optional[VectorIndexType]
vectorizer_config: Optional[VectorizerConfig]
Expand Down Expand Up @@ -2625,6 +2640,29 @@ def dynamic(
quantizer=quantizer,
)

@staticmethod
def hfresh(
max_posting_size: Optional[int] = None,
min_posting_size: Optional[int] = None,
rng_factor: Optional[int] = None,
search_probe: Optional[int] = None,
quantizer: Optional[_RQConfigUpdate] = None,
) -> _VectorIndexConfigHFreshUpdate:
"""Create an `_VectorIndexConfigHFreshUpdate` object to update the configuration of the HFresh vector index.

Use this method when defining the `vectorizer_config` argument in `collection.update()`.

Args:
See [the docs](https://weaviate.io/developers/weaviate/configuration/indexes#configure-the-inverted-index) for a more detailed view!
""" # noqa: D417 (missing argument descriptions in the docstring)
return _VectorIndexConfigHFreshUpdate(
maxPostingSize=max_posting_size,
minPostingSize=min_posting_size,
rngFactor=rng_factor,
searchProbe=search_probe,
quantizer=quantizer,
)


class Reconfigure:
"""Use this factory class to generate the correct `xxxConfig` object for use when using the `collection.update()` method.
Expand Down
17 changes: 16 additions & 1 deletion weaviate/collections/classes/config_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
_VectorIndexConfigDynamic,
_VectorIndexConfigFlat,
_VectorIndexConfigHNSW,
_VectorIndexConfigHFresh,
_VectorizerConfig,
)

Expand Down Expand Up @@ -210,6 +211,18 @@ def __get_hnsw_config(config: Dict[str, Any]) -> _VectorIndexConfigHNSW:
multi_vector=__get_multivector(config),
)

def __get_hfresh_config(config: Dict[str, Any]) -> _VectorIndexConfigHFresh:
quantizer = __get_quantizer_config(config)
return _VectorIndexConfigHFresh(
distance_metric=VectorDistances(config.get("distance")),
max_posting_size=config["maxPostingSize"],
min_posting_size=config["minPostingSize"],
replicas=config["replicas"],
rng_factor=config["rngFactor"],
search_probe=config["searchProbe"],
quantizer=quantizer,
multi_vector=None,
)

def __get_flat_config(config: Dict[str, Any]) -> _VectorIndexConfigFlat:
quantizer = __get_quantizer_config(config)
Expand All @@ -223,7 +236,7 @@ def __get_flat_config(config: Dict[str, Any]) -> _VectorIndexConfigFlat:

def __get_vector_index_config(
schema: Dict[str, Any],
) -> Union[_VectorIndexConfigHNSW, _VectorIndexConfigFlat, _VectorIndexConfigDynamic, None]:
) -> Union[_VectorIndexConfigHNSW, _VectorIndexConfigFlat, _VectorIndexConfigDynamic, _VectorIndexConfigHFresh, None]:
if "vectorIndexConfig" not in schema:
return None
if schema["vectorIndexType"] == "hnsw":
Expand All @@ -237,6 +250,8 @@ def __get_vector_index_config(
hnsw=__get_hnsw_config(schema["vectorIndexConfig"]["hnsw"]),
flat=__get_flat_config(schema["vectorIndexConfig"]["flat"]),
)
elif schema["vectorIndexType"] == "hfresh":
return __get_hfresh_config(schema["vectorIndexConfig"])
else:
return None

Expand Down
2 changes: 2 additions & 0 deletions weaviate/collections/classes/config_named_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
_VectorIndexConfigDynamicUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshUpdate,
_VectorIndexConfigUpdate,
)
from weaviate.collections.classes.config_vectorizers import (
Expand Down Expand Up @@ -1338,6 +1339,7 @@ def update(
*,
vector_index_config: Union[
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigDynamicUpdate,
],
Expand Down
56 changes: 56 additions & 0 deletions weaviate/collections/classes/config_vector_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ class VectorIndexType(str, Enum):
Attributes:
HNSW: Hierarchical Navigable Small World (HNSW) index.
FLAT: Flat index.
DYNAMIC: Dynamic index.
HFRESH: HFRESH index.
"""

HNSW = "hnsw"
FLAT = "flat"
DYNAMIC = "dynamic"
HFRESH = "hfresh"


class _MultiVectorConfigCreateBase(_ConfigCreateModel):
Expand Down Expand Up @@ -127,6 +130,18 @@ def vector_index_type() -> VectorIndexType:
return VectorIndexType.HNSW


class _VectorIndexConfigHFreshCreate(_VectorIndexConfigCreate):
maxPostingSize: Optional[int]
minPostingSize: Optional[int]
replicas: Optional[int]
rngFactor: Optional[int]
searchProbe: Optional[int]

@staticmethod
def vector_index_type() -> VectorIndexType:
return VectorIndexType.HFRESH


class _VectorIndexConfigFlatCreate(_VectorIndexConfigCreate):
vectorCacheMaxObjects: Optional[int]

Expand All @@ -149,6 +164,17 @@ def vector_index_type() -> VectorIndexType:
return VectorIndexType.HNSW


class _VectorIndexConfigHFreshUpdate(_VectorIndexConfigUpdate):
maxPostingSize: Optional[int]
minPostingSize: Optional[int]
rngFactor: Optional[int]
searchProbe: Optional[int]

@staticmethod
def vector_index_type() -> VectorIndexType:
return VectorIndexType.HFRESH


class _VectorIndexConfigFlatUpdate(_VectorIndexConfigUpdate):
vectorCacheMaxObjects: Optional[int]

Expand Down Expand Up @@ -564,6 +590,36 @@ def hnsw(
multivector=multi_vector,
)

@staticmethod
def hfresh(
distance_metric: Optional[VectorDistances] = None,
max_posting_size: Optional[int] = None,
min_posting_size: Optional[int] = None,
replicas: Optional[int] = None,
rng_factor: Optional[int] = None,
search_probe: Optional[int] = None,
quantizer: Optional[_QuantizerConfigCreate] = None,
multi_vector: Optional[_MultiVectorConfigCreate] = None,

) -> _VectorIndexConfigHFreshCreate:
"""Create a `_VectorIndexConfigHFreshCreate` object to be used when defining the HFresh vector index configuration of Weaviate.

Use this method when defining the `vector_index_config` argument in `collections.create()`.

Args:
See [the docs](https://weaviate.io/developers/weaviate/configuration/indexes#how-to-configure-hfresh) for a more detailed view!
"""
return _VectorIndexConfigHFreshCreate(
distance=distance_metric,
maxPostingSize=max_posting_size,
minPostingSize=min_posting_size,
replicas=replicas,
rngFactor=rng_factor,
searchProbe=search_probe,
quantizer=quantizer,
multivector=multi_vector,
)

@staticmethod
def flat(
distance_metric: Optional[VectorDistances] = None,
Expand Down
17 changes: 17 additions & 0 deletions weaviate/collections/classes/config_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigHNSWCreate,
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshCreate,
_VectorIndexConfigHFreshUpdate,
_VectorIndexConfigUpdate,
)
from weaviate.collections.classes.config_vectorizers import (
Expand Down Expand Up @@ -126,6 +128,20 @@
multivector=multivector,
)

@staticmethod
def __hfresh(*, quantizer: Optional[_QuantizerConfigCreate]) -> _VectorIndexConfigHFreshCreate:
return _VectorIndexConfigHFreshCreate(
distance_metric=None,

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.9, integration_embedded)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.12, weaviate)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.13, integration_embedded)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.9, weaviate)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.11, weaviate)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.10, weaviate)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.13, weaviate)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.11, integration_embedded)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.10, integration_embedded)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.11, integration)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.12, integration)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.12, integration_embedded)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.13, integration)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.9, integration)

No parameter named "distance_metric" (reportCallIssue)

Check failure on line 134 in weaviate/collections/classes/config_vectors.py

View workflow job for this annotation

GitHub Actions / Run Type Checking (3.10, integration)

No parameter named "distance_metric" (reportCallIssue)
maxPostingSize=None,
minPostingSize=None,
replicas=None,
rngFactor=None,
searchProbe=None,
quantizer=quantizer,
multivector=None,
distance=None,
)

@staticmethod
def __flat(*, quantizer: Optional[_QuantizerConfigCreate]) -> _VectorIndexConfigFlatCreate:
return _VectorIndexConfigFlatCreate(
Expand Down Expand Up @@ -1760,6 +1776,7 @@
name: Optional[str] = None,
vector_index_config: Union[
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigDynamicUpdate,
],
Expand Down
4 changes: 3 additions & 1 deletion weaviate/collections/config/async_.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from weaviate.collections.classes.config import (
_VectorConfigUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshUpdate,
)
from weaviate.collections.classes.config_vector_index import _VectorIndexConfigDynamicUpdate
from weaviate.connect.v4 import ConnectionAsync
Expand All @@ -45,13 +46,14 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
multi_tenancy_config: Optional[_MultiTenancyConfigUpdate] = None,
replication_config: Optional[_ReplicationConfigUpdate] = None,
vector_index_config: Optional[
Union[_VectorIndexConfigHNSWUpdate, _VectorIndexConfigFlatUpdate]
Union[_VectorIndexConfigHNSWUpdate, _VectorIndexConfigFlatUpdate, _VectorIndexConfigHFreshUpdate]
] = None,
vectorizer_config: Optional[
Union[
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigDynamicUpdate,
_VectorIndexConfigHFreshUpdate,
List[_NamedVectorConfigUpdate],
]
] = None,
Expand Down
4 changes: 4 additions & 0 deletions weaviate/collections/config/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
_VectorConfigUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshUpdate,
)
from weaviate.collections.classes.config_methods import (
_collection_config_from_json,
Expand Down Expand Up @@ -134,13 +135,15 @@ def update(
Union[
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigHFreshUpdate,
]
] = None,
vectorizer_config: Optional[
Union[
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigDynamicUpdate,
_VectorIndexConfigHFreshUpdate,
List[_NamedVectorConfigUpdate],
]
] = None,
Expand Down Expand Up @@ -184,6 +187,7 @@ def update(
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigDynamicUpdate,
_VectorIndexConfigHFreshUpdate,
),
):
_Warnings.vectorizer_config_in_config_update()
Expand Down
4 changes: 3 additions & 1 deletion weaviate/collections/config/sync.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from weaviate.collections.classes.config import (
_VectorConfigUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigHFreshUpdate,
)
from weaviate.collections.classes.config_vector_index import _VectorIndexConfigDynamicUpdate
from weaviate.connect.v4 import ConnectionSync
Expand All @@ -43,13 +44,14 @@ class _ConfigCollection(_ConfigCollectionExecutor[ConnectionSync]):
multi_tenancy_config: Optional[_MultiTenancyConfigUpdate] = None,
replication_config: Optional[_ReplicationConfigUpdate] = None,
vector_index_config: Optional[
Union[_VectorIndexConfigHNSWUpdate, _VectorIndexConfigFlatUpdate]
Union[_VectorIndexConfigHNSWUpdate, _VectorIndexConfigFlatUpdate, _VectorIndexConfigHFreshUpdate]
] = None,
vectorizer_config: Optional[
Union[
_VectorIndexConfigHNSWUpdate,
_VectorIndexConfigFlatUpdate,
_VectorIndexConfigDynamicUpdate,
_VectorIndexConfigHFreshUpdate,
List[_NamedVectorConfigUpdate],
]
] = None,
Expand Down
2 changes: 2 additions & 0 deletions weaviate/outputs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
VectorDistances,
VectorIndexConfigFlat,
VectorIndexConfigHNSW,
VectorIndexConfigHFresh,
VectorIndexType,
VectorizerConfig,
Vectorizers,
Expand Down Expand Up @@ -52,6 +53,7 @@
"ShardTypes",
"VectorDistances",
"VectorIndexConfigHNSW",
"VectorIndexConfigHFresh",
"VectorIndexConfigFlat",
"VectorIndexType",
"Vectorizers",
Expand Down
Loading