Class: Weaviate::Collections
- Defined in:
- lib/weaviate/collections.rb,
sig/weaviate.rbs
Overview
Manage collections (formerly known as "classes" in the Weaviate schema).
Constant Summary collapse
- PATH =
"schema"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add_property(class_name:, property:) ⇒ json
Add a property to an existing collection.
-
#add_tenants(class_name:, tenants:) ⇒ json
Adds one or more tenants to a collection.
-
#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, vector_config: nil) ⇒ json
Create a new collection.
-
#delete(class_name:) ⇒ Boolean
Remove a collection (and all data in the instances).
-
#get(class_name:) ⇒ json
Get a single collection.
-
#get_tenant(class_name:, tenant:) ⇒ json
Get a single tenant of a collection.
-
#list ⇒ json
Lists all collections in the Weaviate schema.
-
#list_tenants(class_name:) ⇒ json
List tenants of a collection.
-
#remove_tenants(class_name:, tenants:) ⇒ json
Remove one or more tenants from a collection.
-
#shards(class_name:, tenant: nil) ⇒ json
Inspect the shards of a collection.
-
#tenant_exists?(class_name:, tenant:) ⇒ Boolean
Check if a tenant exists.
-
#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, vector_config: nil) ⇒ json
Update settings of an existing collection.
-
#update_shard_status(class_name:, shard_name:, status:) ⇒ json
Update shard status.
-
#update_tenants(class_name:, tenants:) ⇒ json
Update the activity status of one or more tenants.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Weaviate::Base
Instance Method Details
#add_property(class_name:, property:) ⇒ json
Add a property to an existing collection.
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/weaviate/collections.rb', line 161 def add_property( class_name:, property: ) response = client.connection.post("#{PATH}/#{class_name}/properties") do |req| req.body = property end response.body end |
#add_tenants(class_name:, tenants:) ⇒ json
Adds one or more tenants to a collection.
106 107 108 109 110 111 112 113 114 |
# File 'lib/weaviate/collections.rb', line 106 def add_tenants( class_name:, tenants: ) response = client.connection.post("#{PATH}/#{class_name}/tenants") do |req| req.body = tenants_body(tenants) 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, vector_config: nil) ⇒ json
Create a new collection.
23 24 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/collections.rb', line 23 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, vector_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? req.body["vectorConfig"] = vector_config unless vector_config.nil? end response.body end |
#delete(class_name:) ⇒ Boolean
Remove a collection (and all data in the instances).
65 66 67 68 |
# File 'lib/weaviate/collections.rb', line 65 def delete(class_name:) response = client.connection.delete("#{PATH}/#{class_name}") response.body.empty? end |
#get(class_name:) ⇒ json
Get a single collection
17 18 19 20 |
# File 'lib/weaviate/collections.rb', line 17 def get(class_name:) response = client.connection.get("#{PATH}/#{class_name}") response.body end |
#get_tenant(class_name:, tenant:) ⇒ json
Get a single tenant of a collection.
129 130 131 132 |
# File 'lib/weaviate/collections.rb', line 129 def get_tenant(class_name:, tenant:) response = client.connection.get("#{PATH}/#{class_name}/tenants/#{tenant}") response.body end |
#list ⇒ json
Lists all collections in the Weaviate schema.
11 12 13 14 |
# File 'lib/weaviate/collections.rb', line 11 def list response = client.connection.get(PATH) response.body end |
#list_tenants(class_name:) ⇒ json
List tenants of a collection.
143 144 145 146 |
# File 'lib/weaviate/collections.rb', line 143 def list_tenants(class_name:) response = client.connection.get("#{PATH}/#{class_name}/tenants") response.body end |
#remove_tenants(class_name:, tenants:) ⇒ json
Remove one or more tenants from a collection.
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/weaviate/collections.rb', line 149 def remove_tenants( class_name:, tenants: ) response = client.connection.delete("#{PATH}/#{class_name}/tenants") do |req| req.body = tenants end response.body end |
#shards(class_name:, tenant: nil) ⇒ json
Inspect the shards of a collection
173 174 175 176 177 178 |
# File 'lib/weaviate/collections.rb', line 173 def shards(class_name:, tenant: nil) response = client.connection.get("#{PATH}/#{class_name}/shards") do |req| req.params["tenant"] = tenant unless tenant.nil? end response.body end |
#tenant_exists?(class_name:, tenant:) ⇒ Boolean
Check if a tenant exists.
135 136 137 138 139 140 |
# File 'lib/weaviate/collections.rb', line 135 def tenant_exists?(class_name:, tenant:) response = client.connection.head("#{PATH}/#{class_name}/tenants/#{tenant}") response.success? rescue Weaviate::ResourceNotFound false 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, vector_config: nil) ⇒ json
Update settings of an existing collection. Weaviate replaces the whole collection definition on update, so the provided settings are merged into the current definition. Immutable settings and existing properties cannot be changed.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/weaviate/collections.rb', line 73 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, vector_config: nil ) changes = { "description" => description, "vectorIndexType" => vector_index_type, "vectorIndexConfig" => vector_index_config, "vectorizer" => vectorizer, "moduleConfig" => module_config, "properties" => properties, "invertedIndexConfig" => inverted_index_config, "replicationConfig" => replication_config, "vectorConfig" => vector_config }.compact response = client.connection.put("#{PATH}/#{class_name}") do |req| req.body = deep_merge(get(class_name: class_name), JSON.parse(changes.to_json)) end response.body end |
#update_shard_status(class_name:, shard_name:, status:) ⇒ json
Update shard status
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/weaviate/collections.rb', line 181 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 end |
#update_tenants(class_name:, tenants:) ⇒ json
Update the activity status of one or more tenants.
118 119 120 121 122 123 124 125 126 |
# File 'lib/weaviate/collections.rb', line 118 def update_tenants( class_name:, tenants: ) response = client.connection.put("#{PATH}/#{class_name}/tenants") do |req| req.body = tenants_body(tenants) end response.body end |