Skip to content

Commit f1abc27

Browse files
robbespo00rlmanrique
authored andcommitted
add enum for centroids index type in spfresh
1 parent 8957d61 commit f1abc27

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

weaviate/classes/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from weaviate.collections.classes.config_vector_index import (
1818
MultiVectorAggregation,
1919
VectorFilterStrategy,
20+
VectorCentroidsIndexType
2021
)
2122
from weaviate.collections.classes.config_vectorizers import Multi2VecField, Vectorizers
2223
from weaviate.connect.integrations import Integrations
@@ -41,4 +42,5 @@
4142
"Vectorizers",
4243
"VectorDistances",
4344
"VectorFilterStrategy",
45+
"VectorCentroidsIndexType",
4446
]

weaviate/collections/classes/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
PQEncoderDistribution,
3636
PQEncoderType,
3737
VectorFilterStrategy,
38+
VectorCentroidsIndexType,
3839
_BQConfigUpdate,
3940
_PQConfigUpdate,
4041
_PQEncoderConfigUpdate,
@@ -1602,7 +1603,7 @@ class _VectorIndexConfigSPFresh(_VectorIndexConfig):
16021603
replicas: int
16031604
rng_factor: int
16041605
search_probe: int
1605-
centroids_index_type: str
1606+
centroids_index_type: VectorCentroidsIndexType
16061607

16071608
@staticmethod
16081609
def vector_index_type() -> str:

weaviate/collections/classes/config_methods.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
VectorDistances,
1313
VectorFilterStrategy,
1414
VectorIndexType,
15+
VectorCentroidsIndexType,
1516
Vectorizers,
1617
_BM25Config,
1718
_BQConfig,
@@ -220,7 +221,11 @@ def __get_spfresh_config(config: Dict[str, Any]) -> _VectorIndexConfigSPFresh:
220221
replicas=config["replicas"],
221222
rng_factor=config["rngFactor"],
222223
search_probe=config["searchProbe"],
223-
centroids_index_type=config["centroidsIndexType"],
224+
centroids_index_type=(
225+
VectorCentroidsIndexType(config["centroidsIndexType"])
226+
if "centroidsIndexType" in config
227+
else VectorCentroidsIndexType.HNSW
228+
),
224229
quantizer=quantizer,
225230
)
226231

weaviate/collections/classes/config_vector_index.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ class VectorIndexType(str, Enum):
4444
SPFRESH = "spfresh"
4545

4646

47+
class VectorCentroidsIndexType(str, Enum):
48+
"""The available index type that can be used for centroids in SPFresh.
49+
50+
Attributes:
51+
HNSW: Hierarchical Navigable Small World (HNSW) index.
52+
FLAT: flat index.
53+
"""
54+
55+
HNSW = "hnsw"
56+
FLAT = "bruteforce"
57+
58+
4759
class _MultiVectorConfigCreateBase(_ConfigCreateModel):
4860
enabled: bool = Field(default=True)
4961

@@ -136,7 +148,7 @@ class _VectorIndexConfigSPFreshCreate(_VectorIndexConfigCreate):
136148
replicas: Optional[int]
137149
rngFactor: Optional[int]
138150
searchProbe: Optional[int]
139-
centroidsIndexType: Optional[str]
151+
centroidsIndexType: Optional[VectorCentroidsIndexType]
140152

141153
@staticmethod
142154
def vector_index_type() -> VectorIndexType:
@@ -599,7 +611,7 @@ def spfresh(
599611
replicas: Optional[int] = None,
600612
rng_factor: Optional[int] = None,
601613
search_probe: Optional[int] = None,
602-
centroids_index_type: Optional[str] = None,
614+
centroids_index_type: Optional[VectorCentroidsIndexType] = None,
603615
quantizer: Optional[_QuantizerConfigCreate] = None,
604616
) -> _VectorIndexConfigSPFreshCreate:
605617
"""Create a `_VectorIndexConfigSPFreshCreate` object to be used when defining the SPFresh vector index configuration of Weaviate.

0 commit comments

Comments
 (0)