Class: Weaviate::Schema
Constant Summary collapse
- PATH =
"schema"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add_property(class_name:, property:) ⇒ Object
Add a property to an existing schema class.
-
#add_tenants(class_name:, tenants:) ⇒ Object
Adds one or more tenants to a class.
-
#create(class_name:, description: nil, properties: nil, multi_tenant: false, auto_tenant_creation: false, auto_tenant_activation: false, vector_index_type: nil, vector_index_config: nil, vectorizer: nil, module_config: nil, inverted_index_config: nil, replication_config: nil) ⇒ Object
Create a new data object class in the schema.
-
#delete(class_name:) ⇒ Object
Remove a class (and all data in the instances) from the schema.
-
#get(class_name:) ⇒ Object
Get a single class from the schema.
-
#list ⇒ Object
Dumps the current Weaviate schema.
-
#list_tenants(class_name:) ⇒ Object
List tenants of a class.
-
#remove_tenants(class_name:, tenants:) ⇒ Object
Remove one or more tenants from a class.
-
#shards(class_name:) ⇒ Object
Inspect the shards of a class.
-
#update(class_name:, description: nil, vector_index_type: nil, vector_index_config: nil, vectorizer: nil, module_config: nil, properties: nil, inverted_index_config: nil, replication_config: nil) ⇒ Object
Update settings of an existing schema class.
-
#update_shard_status(class_name:, shard_name:, status:) ⇒ Object
Update shard status.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Weaviate::Base
Instance Method Details
#add_property(class_name:, property:) ⇒ Object
Add a property to an existing schema class.
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/weaviate/schema.rb', line 142 def add_property( class_name:, property: ) response = client.connection.post("#{PATH}/#{class_name}/properties") do |req| req.body = property end if response.success? end response.body end |
#add_tenants(class_name:, tenants:) ⇒ Object
Adds one or more tenants to a class.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/weaviate/schema.rb', line 109 def add_tenants( class_name:, tenants: ) response = client.connection.post("#{PATH}/#{class_name}/tenants") do |req| tenants_str = tenants.map { |t| %({"name": "#{t}"}) }.join(", ") req.body = "[#{tenants_str}]" end response.body end |
#create(class_name:, description: nil, properties: nil, multi_tenant: false, auto_tenant_creation: false, auto_tenant_activation: false, vector_index_type: nil, vector_index_config: nil, vectorizer: nil, module_config: nil, inverted_index_config: nil, replication_config: nil) ⇒ Object
Create a new data object class in the schema.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/weaviate/schema.rb', line 25 def create( class_name:, description: nil, properties: nil, multi_tenant: false, auto_tenant_creation: false, auto_tenant_activation: false, vector_index_type: nil, vector_index_config: nil, vectorizer: nil, module_config: nil, inverted_index_config: nil, replication_config: nil ) response = client.connection.post(PATH) do |req| req.body = {} req.body["class"] = class_name req.body["description"] = description unless description.nil? req.body["vectorIndexType"] = vector_index_type unless vector_index_type.nil? req.body["vectorIndexConfig"] = vector_index_config unless vector_index_config.nil? 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 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 response.body end |
#delete(class_name:) ⇒ Object
Remove a class (and all data in the instances) from the schema.
65 66 67 68 69 70 71 72 73 |
# File 'lib/weaviate/schema.rb', line 65 def delete(class_name:) response = client.connection.delete("#{PATH}/#{class_name}") if response.success? response.body.empty? else response.body end end |
#get(class_name:) ⇒ Object
Get a single class from the schema
14 15 16 17 18 19 20 21 22 |
# File 'lib/weaviate/schema.rb', line 14 def get(class_name:) response = client.connection.get("#{PATH}/#{class_name}") if response.success? response.body elsif response.status == 404 response.reason_phrase end end |
#list ⇒ Object
Dumps the current Weaviate schema. The result contains an array of objects.
8 9 10 11 |
# File 'lib/weaviate/schema.rb', line 8 def list response = client.connection.get(PATH) response.body end |
#list_tenants(class_name:) ⇒ Object
List tenants of a class.
121 122 123 124 |
# File 'lib/weaviate/schema.rb', line 121 def list_tenants(class_name:) response = client.connection.get("#{PATH}/#{class_name}/tenants") response.body end |
#remove_tenants(class_name:, tenants:) ⇒ Object
Remove one or more tenants from a class.
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/weaviate/schema.rb', line 127 def remove_tenants( class_name:, tenants: ) response = client.connection.delete("#{PATH}/#{class_name}/tenants") do |req| req.body = tenants end if response.success? end response.body end |
#shards(class_name:) ⇒ Object
Inspect the shards of a class
156 157 158 159 |
# File 'lib/weaviate/schema.rb', line 156 def shards(class_name:) response = client.connection.get("#{PATH}/#{class_name}/shards") response.body if response.success? end |
#update(class_name:, description: nil, vector_index_type: nil, vector_index_config: nil, vectorizer: nil, module_config: nil, properties: nil, inverted_index_config: nil, replication_config: nil) ⇒ Object
Update settings of an existing schema class. TODO: Fix it. This endpoint keeps returning the following error:
> cannot be updated through updating the class. Use the add property feature (e.g. "POST /v1/schema/{className/properties") to add additional properties”}]}
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/weaviate/schema.rb', line 79 def update( class_name:, description: nil, vector_index_type: nil, vector_index_config: nil, vectorizer: nil, module_config: nil, properties: nil, inverted_index_config: nil, replication_config: nil ) response = client.connection.put("#{PATH}/#{class_name}") do |req| req.body = {} req.body["class"] = class_name unless class_name.nil? req.body["description"] = description unless description.nil? req.body["vectorIndexType"] = vector_index_type unless vector_index_type.nil? req.body["vectorIndexConfig"] = vector_index_config unless vector_index_config.nil? req.body["vectorizer"] = vectorizer unless vectorizer.nil? req.body["moduleConfig"] = module_config unless module_config.nil? req.body["properties"] = properties unless properties.nil? req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil? req.body["replicationConfig"] = replication_config unless replication_config.nil? end if response.success? end response.body end |
#update_shard_status(class_name:, shard_name:, status:) ⇒ Object
Update shard status
162 163 164 165 166 167 168 169 170 |
# File 'lib/weaviate/schema.rb', line 162 def update_shard_status(class_name:, shard_name:, status:) validate_status!(status) response = client.connection.put("#{PATH}/#{class_name}/shards/#{shard_name}") do |req| req.body = {} req.body["status"] = status end response.body if response.success? end |