diff --git a/README.md b/README.md index 4307efe..6780180 100644 --- a/README.md +++ b/README.md @@ -354,21 +354,14 @@ client.ready? ### Tenants -Any schema can be multi-tenant +Any schema can be multi-tenant by passing in these options for to `schema.create()`. ```ruby client.schema.create( # Other keys... - mutli_tenant: true, # passes { enabled: true } to weaviate -) -``` - -You can also manually specify your multi tenancy configuration with a hash - -```ruby -client.schema.create( - # Other keys... - mutli_tenant: { enabled: true, autoTenantCreation: true, autoTenantActivation: true }, + multi_tenant: true, + auto_tenant_creation: true, + auto_tenant_activation: true ) ``` diff --git a/lib/weaviate/objects.rb b/lib/weaviate/objects.rb index e511689..7429607 100644 --- a/lib/weaviate/objects.rb +++ b/lib/weaviate/objects.rb @@ -50,7 +50,7 @@ def create( req.body = {} req.body["class"] = class_name req.body["properties"] = properties - req.body["tenant"] = tenant unless tenant.blank? + req.body["tenant"] = tenant unless tenant.nil? req.body["id"] = id unless id.nil? req.body["vector"] = vector unless vector.nil? end diff --git a/lib/weaviate/schema.rb b/lib/weaviate/schema.rb index d79e991..3044806 100644 --- a/lib/weaviate/schema.rb +++ b/lib/weaviate/schema.rb @@ -26,7 +26,9 @@ def create( class_name:, description: nil, properties: nil, - multi_tenant: nil, + multi_tenant: false, + auto_tenant_creation: false, + auto_tenant_activation: false, vector_index_type: nil, vector_index_config: nil, vectorizer: nil, @@ -43,11 +45,15 @@ def create( req.body["vectorizer"] = vectorizer unless vectorizer.nil? req.body["moduleConfig"] = module_config unless module_config.nil? req.body["properties"] = properties unless properties.nil? - if multi_tenant.is_a?(Hash) - req.body["multiTenancyConfig"] = multi_tenant - elsif multi_tenant.present? - req.body["multiTenancyConfig"] = {enabled: true} + + if multi_tenant + req.body["multiTenancyConfig"] = { + enabled: multi_tenant, + autoTenantCreation: auto_tenant_creation, + autoTenantActivation: auto_tenant_activation + } end + req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil? req.body["replicationConfig"] = replication_config unless replication_config.nil? end diff --git a/spec/weaviate/schema_spec.rb b/spec/weaviate/schema_spec.rb index d2bc2c7..442e37c 100644 --- a/spec/weaviate/schema_spec.rb +++ b/spec/weaviate/schema_spec.rb @@ -76,6 +76,31 @@ ) expect(response.dig("class")).to eq("Question") end + + context "when auto_tenant_creation passed" do + before do + @captured_request = nil + allow_any_instance_of(Faraday::Connection).to receive(:post) do |_, path, &block| + expect(path).to eq("schema") + req = OpenStruct.new(body: {}) + block.call(req) + @captured_request = req + response + end + end + + it "sets up multiTenancyConfig with autoTenantCreation and autoTenantActivation enabled" do + schema.create( + class_name: "Question", + description: "Information from a Jeopardy! question", + multi_tenant: true, + auto_tenant_creation: true, + auto_tenant_activation: true + ) + + expect(@captured_request.body["multiTenancyConfig"]).to eq({enabled: true, autoTenantCreation: true, autoTenantActivation: true}) + end + end end describe "#delete" do