Skip to content

Commit 174661a

Browse files
committed
add enum for centroids index type in spfresh
1 parent 6cb1d30 commit 174661a

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,
@@ -1599,7 +1600,7 @@ class _VectorIndexConfigSPFresh(_VectorIndexConfig):
15991600
replicas: int
16001601
rng_factor: int
16011602
search_probe: int
1602-
centroids_index_type: str
1603+
centroids_index_type: VectorCentroidsIndexType
16031604

16041605
@staticmethod
16051606
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,
@@ -219,7 +220,11 @@ def __get_spfresh_config(config: Dict[str, Any]) -> _VectorIndexConfigSPFresh:
219220
replicas=config["replicas"],
220221
rng_factor=config["rngFactor"],
221222
search_probe=config["searchProbe"],
222-
centroids_index_type=config["centroidsIndexType"],
223+
centroids_index_type=(
224+
VectorCentroidsIndexType(config["centroidsIndexType"])
225+
if "centroidsIndexType" in config
226+
else VectorCentroidsIndexType.HNSW
227+
),
223228
quantizer=quantizer,
224229
)
225230

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:
@@ -596,7 +608,7 @@ def spfresh(
596608
replicas: Optional[int] = None,
597609
rng_factor: Optional[int] = None,
598610
search_probe: Optional[int] = None,
599-
centroids_index_type: Optional[str] = None,
611+
centroids_index_type: Optional[VectorCentroidsIndexType] = None,
600612
quantizer: Optional[_QuantizerConfigCreate] = None,
601613
) -> _VectorIndexConfigSPFreshCreate:
602614
"""Create a `_VectorIndexConfigSPFreshCreate` object to be used when defining the SPFresh vector index configuration of Weaviate.

0 commit comments

Comments
 (0)