Skip to content

Commit

Permalink
Merge pull request #1082 from weaviate/auto-tenant-activation
Browse files Browse the repository at this point in the history
Add support for auto-tenant-activation
  • Loading branch information
dirkkul authored May 31, 2024
2 parents 79fe621 + e77f368 commit 0a0fd67
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
env:
WEAVIATE_123: 1.23.14
WEAVIATE_124: 1.24.10
WEAVIATE_125: preview--grpc-clean-up-target-vectors-in-hybrid-30c49be
WEAVIATE_125: preview--c57fecf


jobs:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ repos:
language: node
pass_filenames: false
types: [python]
additional_dependencies: [pyright@1.1.347]
additional_dependencies: [pyright@1.1.364]
28 changes: 27 additions & 1 deletion integration/test_collection_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ def test_collection_config_full(collection_factory: CollectionFactory) -> None:
stopwords_preset=StopwordsPreset.EN,
stopwords_removals=["the"],
),
multi_tenancy_config=Configure.multi_tenancy(enabled=True),
multi_tenancy_config=Configure.multi_tenancy(
enabled=True, auto_tenant_activation=True, auto_tenant_creation=True
),
# replication_config=Configure.replication(factor=2), # currently not updateable in RAFT
vector_index_config=Configure.VectorIndex.hnsw(
cleanup_interval_seconds=10,
Expand Down Expand Up @@ -308,6 +310,11 @@ def test_collection_config_full(collection_factory: CollectionFactory) -> None:
assert config.inverted_index_config.stopwords.removals == ["the"]

assert config.multi_tenancy_config.enabled is True
if collection._connection._weaviate_version.is_at_least(1, 25, 0):
assert config.multi_tenancy_config.auto_tenant_activation is True
# change to 1.25.2 after it is out
if collection._connection._weaviate_version.is_at_least(1, 25, patch=1):
assert config.multi_tenancy_config.auto_tenant_creation is True

# assert config.replication_config.factor == 2

Expand Down Expand Up @@ -342,10 +349,19 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None
Property(name="age", data_type=DataType.INT),
],
ports=(8087, 50058),
multi_tenancy_config=Configure.multi_tenancy(
enabled=True, auto_tenant_creation=False, auto_tenant_activation=False
),
)
config = collection.config.get()

assert config.replication_config.factor == 1
assert config.multi_tenancy_config.enabled is True
if collection._connection._weaviate_version.is_at_least(1, 25, 0):
assert config.multi_tenancy_config.auto_tenant_activation is False
# change to 1.25.2 after it is out
if collection._connection._weaviate_version.is_at_least(1, 25, patch=1):
assert config.multi_tenancy_config.auto_tenant_creation is False

collection.config.update(
description="Test",
Expand All @@ -368,6 +384,9 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None
training_limit=100001,
),
),
multi_tenancy_config=Reconfigure.multi_tenancy(
auto_tenant_creation=True, auto_tenant_activation=True
),
)

config = collection.config.get()
Expand Down Expand Up @@ -404,6 +423,13 @@ def test_collection_config_update(collection_factory: CollectionFactory) -> None

assert config.vector_index_type == VectorIndexType.HNSW

assert config.multi_tenancy_config.enabled is True
if collection._connection._weaviate_version.is_at_least(1, 25, 0):
assert config.multi_tenancy_config.auto_tenant_activation is True
# change to 1.25.2 after it is out
if collection._connection._weaviate_version.is_at_least(1, 25, patch=1):
assert config.multi_tenancy_config.auto_tenant_creation is True

collection.config.update(
vectorizer_config=Reconfigure.VectorIndex.hnsw(
quantizer=Reconfigure.VectorIndex.Quantizer.pq(enabled=False),
Expand Down
4 changes: 3 additions & 1 deletion mock_tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def test_missing_multi_tenancy_config(
index_timestamps=False,
stopwords=StopwordsConfig(preset=StopwordsPreset.NONE, additions=[], removals=[]),
),
multi_tenancy_config=MultiTenancyConfig(enabled=True, auto_tenant_creation=False),
multi_tenancy_config=MultiTenancyConfig(
enabled=True, auto_tenant_creation=False, auto_tenant_activation=False
),
sharding_config=ShardingConfig(
virtual_per_physical=0,
desired_count=0,
Expand Down
61 changes: 37 additions & 24 deletions weaviate/collections/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,21 @@
cast,
)

from typing_extensions import TypeAlias

from pydantic import AnyHttpUrl, Field, field_validator

from weaviate.util import _capitalize_first_letter
from weaviate.collections.classes.config_vectorizers import (
_Vectorizer,
_VectorizerConfigCreate,
CohereModel,
Vectorizers as VectorizersAlias,
VectorDistances as VectorDistancesAlias,
)
from typing_extensions import TypeAlias

from weaviate.collections.classes.config_base import (
_ConfigBase,
_ConfigCreateModel,
_ConfigUpdateModel,
_QuantizerConfigUpdate,
)

from weaviate.collections.classes.config_named_vectors import (
_NamedVectorConfigCreate,
_NamedVectorConfigUpdate,
_NamedVectors,
_NamedVectorsUpdate,
)
from weaviate.collections.classes.config_vector_index import (
_QuantizerConfigCreate,
_VectorIndexConfigCreate,
Expand All @@ -47,14 +42,15 @@
_VectorIndexConfigUpdate,
VectorIndexType as VectorIndexTypeAlias,
)

from weaviate.collections.classes.config_named_vectors import (
_NamedVectorConfigCreate,
_NamedVectorConfigUpdate,
_NamedVectors,
_NamedVectorsUpdate,
from weaviate.collections.classes.config_vectorizers import (
_Vectorizer,
_VectorizerConfigCreate,
CohereModel,
Vectorizers as VectorizersAlias,
VectorDistances as VectorDistancesAlias,
)
from weaviate.exceptions import WeaviateInvalidInputError
from weaviate.util import _capitalize_first_letter
from weaviate.warnings import _Warnings

# BC for direct imports
Expand Down Expand Up @@ -360,10 +356,12 @@ class _InvertedIndexConfigUpdate(_ConfigUpdateModel):
class _MultiTenancyConfigCreate(_ConfigCreateModel):
enabled: bool
autoTenantCreation: Optional[bool]
autoTenantActivation: Optional[bool]


class _MultiTenancyConfigUpdate(_ConfigUpdateModel):
autoTenantCreation: Optional[bool] = None
autoTenantCreation: Optional[bool]
autoTenantActivation: Optional[bool]


class _GenerativeConfigCreate(_ConfigCreateModel):
Expand Down Expand Up @@ -952,6 +950,7 @@ class _InvertedIndexConfig(_ConfigBase):
class _MultiTenancyConfig(_ConfigBase):
enabled: bool
auto_tenant_creation: bool
auto_tenant_activation: bool


MultiTenancyConfig = _MultiTenancyConfig
Expand Down Expand Up @@ -1745,17 +1744,25 @@ def inverted_index(

@staticmethod
def multi_tenancy(
enabled: bool = True, auto_tenant_creation: bool = False
enabled: bool = True,
auto_tenant_creation: Optional[bool] = None,
auto_tenant_activation: Optional[bool] = None,
) -> _MultiTenancyConfigCreate:
"""Create a `MultiTenancyConfigCreate` object to be used when defining the multi-tenancy configuration of Weaviate.
Arguments:
`enabled`
Whether multi-tenancy is enabled. Defaults to `True`.
`auto_tenant_creation`
Automatically create nonexistent tenants during batch import. Defaults to `False`
Automatically create nonexistent tenants during batch import. Defaults to `None`, which uses the server-defined default.
`auto_tenant_activation`
Automatically turn tenants implicitly HOT when they are accessed. Defaults to `None`, which uses the server-defined default.
"""
return _MultiTenancyConfigCreate(enabled=enabled, autoTenantCreation=auto_tenant_creation)
return _MultiTenancyConfigCreate(
enabled=enabled,
autoTenantCreation=auto_tenant_creation,
autoTenantActivation=auto_tenant_activation,
)

@staticmethod
def replication(factor: Optional[int] = None) -> _ReplicationConfigCreate:
Expand Down Expand Up @@ -1972,13 +1979,19 @@ def replication(factor: Optional[int] = None) -> _ReplicationConfigUpdate:
return _ReplicationConfigUpdate(factor=factor)

@staticmethod
def multi_tenancy(auto_tenant_creation: Optional[bool] = None) -> _MultiTenancyConfigUpdate:
def multi_tenancy(
auto_tenant_creation: Optional[bool] = None, auto_tenant_activation: Optional[bool] = None
) -> _MultiTenancyConfigUpdate:
"""Create a `MultiTenancyConfigUpdate` object.
Use this method when defining the `multi_tenancy` argument in `collection.update()`.
Arguments:
`auto_tenant_creation`
When set, implicitly creates nonexisting tenants during batch imports
`auto_tenant_activation`
Automatically turn tenants implicitly HOT when they are accessed. Defaults to `None`, which uses the server-defined default.
"""
return _MultiTenancyConfigUpdate(autoTenantCreation=auto_tenant_creation)
return _MultiTenancyConfigUpdate(
autoTenantCreation=auto_tenant_creation, autoTenantActivation=auto_tenant_activation
)
3 changes: 3 additions & 0 deletions weaviate/collections/classes/config_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def _collection_config_from_json(schema: Dict[str, Any]) -> _CollectionConfig:
auto_tenant_creation=schema.get("multiTenancyConfig", {}).get(
"autoTenantCreation", False
),
auto_tenant_activation=schema.get("multiTenancyConfig", {}).get(
"autoTenantActivation", False
),
),
properties=_properties_from_config(schema) if schema.get("properties") is not None else [],
references=_references_from_config(schema) if schema.get("properties") is not None else [],
Expand Down

0 comments on commit 0a0fd67

Please sign in to comment.