Quantcast
Channel: Weaviate Community Forum - Latest posts
Viewing all articles
Browse latest Browse all 3588

Specifying properties with multi-tenancy causes bug

$
0
0

Hi @Tejas_Sharma !!

You need to specify at least one nested property if using the object. Also, there was a missing , in your code, right after inverted_index_config

Here is a working example:

import uuid
import weaviate
import weaviate.classes as wvc
from weaviate.classes.query import Filter, MetadataQuery
from weaviate.classes.config import Configure, VectorDistances, Property, DataType
from weaviate.classes.tenants import Tenant
from datetime import datetime, timedelta
import pytz

# For all objects
client.collections.delete("Test")
nodes_collection = client.collections.create(
    name="Test",
    vectorizer_config=wvc.config.Configure.Vectorizer.none(),
    vector_index_config=Configure.VectorIndex.hnsw(
        distance_metric=VectorDistances.COSINE
    ),
    # Multi tenancy to separate each user's data
    multi_tenancy_config=Configure.multi_tenancy(enabled=True, auto_tenant_creation=True, auto_tenant_activation=True),
    inverted_index_config=Configure.inverted_index( 
        index_null_state=True,
        index_property_length=True,
        index_timestamps=True
    ),
    # Specify some properties beforehand to set right data type (i.e. obj[] instead of string[])
    properties=[
        wvc.config.Property(
            name="tags",
            data_type=wvc.config.DataType.OBJECT,
            nested_properties=[
                wvc.config.Property(
                    name="sub_property1",
                    data_type=wvc.config.DataType.TEXT
                ),
                wvc.config.Property(
                    name="sub_property2",
                    data_type=wvc.config.DataType.INT
                )
            ]
        )
    ]
)


# Create tenant on Node
nodes_collection.tenants.create(
    tenants=[
        Tenant(name="tenantA"),
        Tenant(name="tenantB"),
    ]
)

# Will cause an error
nodes_collection.with_tenant('tenantA').data.insert(
	vector=[0.0] * 384,
	properties={
        'lastUpdateDeviceId': 'device-78C24351-F40A-4E37-8953-F003FA474877',
        "tags": {"sub_property1": "somedata", "sub_property2": 123}        
    },
	uuid=str(uuid.uuid4())
)

Let me know if this helps.

Thanks!


Viewing all articles
Browse latest Browse all 3588

Trending Articles