Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
WEAVIATE_124: preview-rename-object-deletion-to-deletion-strategy-727ecf7
WEAVIATE_125: stable-v1.25-d9f6cbb
WEAVIATE_126: stable-v1.26-6a411a4
WEAVIATE_127: preview-merge-stable-v1-27-into-main-33adc57
WEAVIATE_127: stable-v1.27-0694720

jobs:
lint-and-format:
Expand Down
17 changes: 17 additions & 0 deletions integration/test_collection_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def test_collection_config_full(collection_factory: CollectionFactory) -> None:
dynamic_ef_min=10,
ef=-2,
ef_construction=100,
filter_strategy=wvc.config.FilterStrategyHNSW.ACORN,
flat_search_cutoff=41000,
max_connections=72,
quantizer=Configure.VectorIndex.Quantizer.pq(
Expand Down Expand Up @@ -375,6 +376,11 @@ def test_collection_config_full(collection_factory: CollectionFactory) -> None:
assert config.vector_index_config.quantizer.training_limit == 1000001
assert config.vector_index_config.skip is False
assert config.vector_index_config.vector_cache_max_objects == 100000
if collection._connection._weaviate_version.is_at_least(1, 27, 0):
assert config.vector_index_config.filter_strategy == wvc.config.FilterStrategyHNSW.ACORN
else:
# default value if not present in schema
assert config.vector_index_config.filter_strategy == wvc.config.FilterStrategyHNSW.SWEEPING

assert config.vector_index_type == VectorIndexType.HNSW

Expand All @@ -399,6 +405,8 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None
assert config.multi_tenancy_config.auto_tenant_activation is False
assert config.multi_tenancy_config.auto_tenant_creation is False

assert config.vector_index_config.filter_strategy == wvc.config.FilterStrategyHNSW.SWEEPING

collection.config.update(
description="Test",
inverted_index_config=Reconfigure.inverted_index(
Expand All @@ -414,6 +422,7 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None
), # currently not updateable in RAFT
vectorizer_config=Reconfigure.VectorIndex.hnsw(
vector_cache_max_objects=2000000,
filter_strategy=wvc.config.FilterStrategyHNSW.ACORN,
quantizer=Reconfigure.VectorIndex.Quantizer.pq(
centroids=128,
encoder_type=PQEncoderType.TILE,
Expand Down Expand Up @@ -472,6 +481,12 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None
assert config.vector_index_config.skip is False
assert config.vector_index_config.vector_cache_max_objects == 2000000

if collection._connection._weaviate_version.is_at_least(1, 27, 0):
assert config.vector_index_config.filter_strategy == wvc.config.FilterStrategyHNSW.ACORN
else:
# default value if not present in schema
assert config.vector_index_config.filter_strategy == wvc.config.FilterStrategyHNSW.SWEEPING

assert config.vector_index_type == VectorIndexType.HNSW

assert config.multi_tenancy_config.enabled is True
Expand All @@ -488,6 +503,7 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None

collection.config.update(
vectorizer_config=Reconfigure.VectorIndex.hnsw(
filter_strategy=wvc.config.FilterStrategyHNSW.SWEEPING,
quantizer=Reconfigure.VectorIndex.Quantizer.pq(enabled=False),
)
)
Expand Down Expand Up @@ -529,6 +545,7 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None
assert config.vector_index_config.quantizer is None
assert config.vector_index_config.skip is False
assert config.vector_index_config.vector_cache_max_objects == 2000000
assert config.vector_index_config.filter_strategy == wvc.config.FilterStrategyHNSW.SWEEPING

assert config.vector_index_type == VectorIndexType.HNSW

Expand Down
2 changes: 1 addition & 1 deletion mock_tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_return_from_bind_module(
prop_modconf: Dict[str, Any] = {"multi2vec-bind": {}}

hnsw_config = config.VectorIndex.hnsw(
1, VectorDistances.COSINE, 1, 1, 1, 1, 1, 1, 1, 1
1, VectorDistances.COSINE, 1, 1, 1, 1, 1, None, 1, 1, 1
)._to_dict()
hnsw_config["skip"] = True
ii_config = config.inverted_index(
Expand Down
4 changes: 2 additions & 2 deletions weaviate/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
Tokenization,
VectorDistances,
)

from weaviate.collections.classes.config_vector_index import FilterStrategyHNSW
from weaviate.collections.classes.config_vectorizers import Multi2VecField, Vectorizers
from weaviate.connect.integrations import Integrations


__all__ = [
"Configure",
"ConsistencyLevel",
"Reconfigure",
"DataType",
"GenerativeSearches",
"FilterStrategyHNSW",
"Integrations",
"Multi2VecField",
"DeletionStrategy",
Expand Down
10 changes: 9 additions & 1 deletion weaviate/collections/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
_NamedVectors,
_NamedVectorsUpdate,
)
from weaviate.collections.classes.config_vector_index import VectorIndexType as VectorIndexTypeAlias
from weaviate.collections.classes.config_vector_index import (
VectorIndexType as VectorIndexTypeAlias,
FilterStrategyHNSW,
)
from weaviate.collections.classes.config_vector_index import (
_QuantizerConfigCreate,
_VectorIndexConfigCreate,
Expand Down Expand Up @@ -1533,6 +1536,7 @@ class _VectorIndexConfigHNSW(_VectorIndexConfig):
dynamic_ef_factor: int
ef: int
ef_construction: int
filter_strategy: FilterStrategyHNSW
flat_search_cutoff: int
max_connections: int
skip: bool
Expand Down Expand Up @@ -2064,6 +2068,7 @@ def hnsw(
dynamic_ef_min: Optional[int] = None,
ef: Optional[int] = None,
ef_construction: Optional[int] = None,
filter_strategy: Optional[FilterStrategyHNSW] = None,
flat_search_cutoff: Optional[int] = None,
max_connections: Optional[int] = None,
vector_cache_max_objects: Optional[int] = None,
Expand All @@ -2084,6 +2089,7 @@ def hnsw(
dynamicEfFactor=dynamic_ef_factor,
efConstruction=ef_construction,
ef=ef,
filterStrategy=filter_strategy,
flatSearchCutoff=flat_search_cutoff,
maxConnections=max_connections,
vectorCacheMaxObjects=vector_cache_max_objects,
Expand Down Expand Up @@ -2335,6 +2341,7 @@ def hnsw(
dynamic_ef_max: Optional[int] = None,
ef: Optional[int] = None,
flat_search_cutoff: Optional[int] = None,
filter_strategy: Optional[FilterStrategyHNSW] = None,
vector_cache_max_objects: Optional[int] = None,
quantizer: Optional[Union[_PQConfigUpdate, _BQConfigUpdate, _SQConfigUpdate]] = None,
) -> _VectorIndexConfigHNSWUpdate:
Expand All @@ -2350,6 +2357,7 @@ def hnsw(
dynamicEfMax=dynamic_ef_max,
dynamicEfFactor=dynamic_ef_factor,
ef=ef,
filterStrategy=filter_strategy,
flatSearchCutoff=flat_search_cutoff,
vectorCacheMaxObjects=vector_cache_max_objects,
quantizer=quantizer,
Expand Down
6 changes: 6 additions & 0 deletions weaviate/collections/classes/config_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Rerankers,
_NestedProperty,
DeletionStrategy,
FilterStrategyHNSW,
)


Expand Down Expand Up @@ -157,6 +158,11 @@ def __get_hnsw_config(config: Dict[str, Any]) -> _VectorIndexConfigHNSW:
dynamic_ef_factor=config["dynamicEfFactor"],
ef=config["ef"],
ef_construction=config["efConstruction"],
filter_strategy=(
FilterStrategyHNSW(config["filterStrategy"])
if "filterStrategy" in config
else FilterStrategyHNSW.SWEEPING
),
flat_search_cutoff=config["flatSearchCutoff"],
max_connections=config["maxConnections"],
quantizer=quantizer,
Expand Down
16 changes: 15 additions & 1 deletion weaviate/collections/classes/config_vector_index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import abstractmethod
from enum import Enum
from typing import Any, Dict, Optional

from pydantic import Field

from weaviate.collections.classes.config_base import (
Expand All @@ -9,10 +10,21 @@
_QuantizerConfigCreate,
_QuantizerConfigUpdate,
)

from weaviate.collections.classes.config_vectorizers import VectorDistances


class FilterStrategyHNSW(str, Enum):
"""Set the strategy when doing a filtered HNSW search.

Attributes:
SWEEPING: Do normal ANN search and skip nodes.
ACORN: Multi-hop search to find new candidates matching the filter.
"""

SWEEPING = "sweeping"
ACORN = "acorn"


class VectorIndexType(str, Enum):
"""The available vector index types in Weaviate.

Expand Down Expand Up @@ -67,6 +79,7 @@ class _VectorIndexConfigHNSWCreate(_VectorIndexConfigCreate):
dynamicEfFactor: Optional[int]
efConstruction: Optional[int]
ef: Optional[int]
filterStrategy: Optional[FilterStrategyHNSW]
flatSearchCutoff: Optional[int]
maxConnections: Optional[int]
vectorCacheMaxObjects: Optional[int]
Expand All @@ -89,6 +102,7 @@ class _VectorIndexConfigHNSWUpdate(_VectorIndexConfigUpdate):
dynamicEfMax: Optional[int]
dynamicEfFactor: Optional[int]
ef: Optional[int]
filterStrategy: Optional[FilterStrategyHNSW]
flatSearchCutoff: Optional[int]
vectorCacheMaxObjects: Optional[int]

Expand Down