Class: Qdrant::Collections
Constant Summary collapse
- PATH =
"collections"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#aliases(collection_name:) ⇒ Object
Get list of all aliases for a collection.
-
#cluster_info(collection_name:) ⇒ Object
Get cluster information for a collection.
-
#create(collection_name:, vectors:, sparse_vectors: nil, shard_number: nil, replication_factor: nil, write_consistency_factor: nil, on_disk_payload: nil, hnsw_config: nil, wal_config: nil, optimizers_config: nil, init_from: nil, quantization_config: nil) ⇒ Object
Create new collection with given parameters.
-
#create_index(collection_name:, field_name:, field_schema: nil, wait: nil, ordering: nil) ⇒ Object
Create index for field in collection.
-
#create_snapshot(collection_name:) ⇒ Object
Create new snapshot for a collection.
-
#delete(collection_name:) ⇒ Object
Drop collection and all associated data.
-
#delete_index(collection_name:, field_name:) ⇒ Object
Delete field index for collection.
-
#delete_snapshot(collection_name:, snapshot_name:) ⇒ Object
Delete snapshot for a collection.
-
#download_snapshot(collection_name:, snapshot_name:, filepath:) ⇒ Object
Download specified snapshot from a collection as a file.
-
#get(collection_name:) ⇒ Object
Get detailed information about specified existing collection.
-
#list ⇒ Object
Get list name of all existing collections.
-
#list_snapshots(collection_name:) ⇒ Object
Get list of snapshots for a collection.
-
#restore_snapshot(collection_name:, filepath:, priority: nil, wait: nil) ⇒ Object
Recover local collection data from a snapshot.
-
#update(collection_name:, optimizers_config: nil, params: nil) ⇒ Object
Update parameters of the existing collection.
-
#update_aliases(actions:) ⇒ Object
Update aliases of the collections.
-
#update_cluster(collection_name:, move_shard:) ⇒ Object
Update collection cluster setup.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Qdrant::Base
Instance Method Details
#aliases(collection_name:) ⇒ Object
Get list of all aliases for a collection
74 75 76 77 |
# File 'lib/qdrant/collections.rb', line 74 def aliases(collection_name:) response = client.connection.get("#{PATH}/#{collection_name}/aliases") response.body end |
#cluster_info(collection_name:) ⇒ Object
Get cluster information for a collection
119 120 121 122 |
# File 'lib/qdrant/collections.rb', line 119 def cluster_info(collection_name:) response = client.connection.get("#{PATH}/#{collection_name}/cluster") response.body end |
#create(collection_name:, vectors:, sparse_vectors: nil, shard_number: nil, replication_factor: nil, write_consistency_factor: nil, on_disk_payload: nil, hnsw_config: nil, wal_config: nil, optimizers_config: nil, init_from: nil, quantization_config: nil) ⇒ Object
Create new collection with given parameters
20 21 22 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 |
# File 'lib/qdrant/collections.rb', line 20 def create( collection_name:, vectors:, sparse_vectors: nil, shard_number: nil, replication_factor: nil, write_consistency_factor: nil, on_disk_payload: nil, hnsw_config: nil, wal_config: nil, optimizers_config: nil, init_from: nil, quantization_config: nil ) response = client.connection.put("#{PATH}/#{collection_name}") do |req| req.body = {} req.body["vectors"] = vectors req.body["sparse_vectors"] = sparse_vectors unless sparse_vectors.nil? req.body["shard_number"] = shard_number unless shard_number.nil? req.body["replication_factor"] = replication_factor unless replication_factor.nil? req.body["write_consistency_factor"] = write_consistency_factor unless write_consistency_factor.nil? req.body["on_disk_payload"] = on_disk_payload unless on_disk_payload.nil? req.body["hnsw_config"] = hnsw_config unless hnsw_config.nil? req.body["wal_config"] = wal_config unless wal_config.nil? req.body["optimizers_config"] = optimizers_config unless optimizers_config.nil? req.body["init_from"] = init_from unless init_from.nil? req.body["quantization_config"] = quantization_config unless quantization_config.nil? end response.body end |
#create_index(collection_name:, field_name:, field_schema: nil, wait: nil, ordering: nil) ⇒ Object
Create index for field in collection.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/qdrant/collections.rb', line 91 def create_index( collection_name:, field_name:, field_schema: nil, wait: nil, ordering: nil ) response = client.connection.put("#{PATH}/#{collection_name}/index") do |req| req.params["ordering"] = ordering unless ordering.nil? # Add explicit false check to avoid nil case. True is default behavior. req.params["wait"] = wait unless wait.nil? req.body = {field_name: field_name} req.body["field_schema"] = field_schema unless field_schema.nil? end response.body end |
#create_snapshot(collection_name:) ⇒ Object
Create new snapshot for a collection
157 158 159 160 161 162 |
# File 'lib/qdrant/collections.rb', line 157 def create_snapshot( collection_name: ) response = client.connection.post("#{PATH}/#{collection_name}/snapshots") response.body end |
#delete(collection_name:) ⇒ Object
Drop collection and all associated data
68 69 70 71 |
# File 'lib/qdrant/collections.rb', line 68 def delete(collection_name:) response = client.connection.delete("#{PATH}/#{collection_name}") response.body end |
#delete_index(collection_name:, field_name:) ⇒ Object
Delete field index for collection
110 111 112 113 114 115 116 |
# File 'lib/qdrant/collections.rb', line 110 def delete_index( collection_name:, field_name: ) response = client.connection.delete("#{PATH}/#{collection_name}/index/#{field_name}") response.body end |
#delete_snapshot(collection_name:, snapshot_name:) ⇒ Object
Delete snapshot for a collection
148 149 150 151 152 153 154 |
# File 'lib/qdrant/collections.rb', line 148 def delete_snapshot( collection_name:, snapshot_name: ) response = client.connection.delete("#{PATH}/#{collection_name}/snapshots/#{snapshot_name}") response.body end |
#download_snapshot(collection_name:, snapshot_name:, filepath:) ⇒ Object
Download specified snapshot from a collection as a file
138 139 140 141 142 143 144 145 |
# File 'lib/qdrant/collections.rb', line 138 def download_snapshot( collection_name:, snapshot_name:, filepath: ) response = client.connection.get("#{PATH}/#{collection_name}/snapshots/#{snapshot_name}") File.open(File.(filepath), "wb+") { |fp| fp.write(response.body) } end |
#get(collection_name:) ⇒ Object
Get detailed information about specified existing collection
14 15 16 17 |
# File 'lib/qdrant/collections.rb', line 14 def get(collection_name:) response = client.connection.get("#{PATH}/#{collection_name}") response.body end |
#list ⇒ Object
Get list name of all existing collections
8 9 10 11 |
# File 'lib/qdrant/collections.rb', line 8 def list response = client.connection.get(PATH) response.body end |
#list_snapshots(collection_name:) ⇒ Object
Get list of snapshots for a collection
165 166 167 168 169 170 |
# File 'lib/qdrant/collections.rb', line 165 def list_snapshots( collection_name: ) response = client.connection.get("collections/#{collection_name}/snapshots") response.body end |
#restore_snapshot(collection_name:, filepath:, priority: nil, wait: nil) ⇒ Object
Recover local collection data from a snapshot. This will overwrite any data, stored on this node, for the collection. If collection does not exist - it will be created.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/qdrant/collections.rb', line 173 def restore_snapshot( collection_name:, filepath:, priority: nil, wait: nil ) response = client.connection.post("#{PATH}/#{collection_name}/snapshots/recover") do |req| req.params["wait"] = wait unless wait.nil? req.body = { location: filepath } req.body["priority"] = priority unless priority.nil? end response.body end |
#update(collection_name:, optimizers_config: nil, params: nil) ⇒ Object
Update parameters of the existing collection
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/qdrant/collections.rb', line 53 def update( collection_name:, optimizers_config: nil, params: nil ) response = client.connection.patch("#{PATH}/#{collection_name}") do |req| req.body = {} req.body["optimizers_config"] = optimizers_config unless optimizers_config.nil? req.body["params"] = params unless params.nil? end response.body end |
#update_aliases(actions:) ⇒ Object
Update aliases of the collections
80 81 82 83 84 85 86 87 88 |
# File 'lib/qdrant/collections.rb', line 80 def update_aliases(actions:) response = client.connection.post("#{PATH}/aliases") do |req| req.body = { actions: actions } end response.body end |
#update_cluster(collection_name:, move_shard:) ⇒ Object
Update collection cluster setup
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/qdrant/collections.rb', line 125 def update_cluster( collection_name:, move_shard: ) response = client.connection.post("#{PATH}/#{collection_name}/cluster") do |req| req.body = { move_shard: move_shard } end response.body end |