Class: Qdrant::Collections

Inherits:
Base
  • Object
show all
Defined in:
lib/qdrant/collections.rb

Constant Summary collapse

PATH =
"collections"

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

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



72
73
74
75
# File 'lib/qdrant/collections.rb', line 72

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



114
115
116
117
# File 'lib/qdrant/collections.rb', line 114

def cluster_info(collection_name:)
  response = client.connection.get("#{PATH}/#{collection_name}/cluster")
  response.body
end

#create(collection_name:, vectors:, 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
# File 'lib/qdrant/collections.rb', line 20

def create(
  collection_name:,
  vectors:,
  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["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) ⇒ Object

Create index for field in collection.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/qdrant/collections.rb', line 89

def create_index(
  collection_name:,
  field_name:,
  field_schema: nil
)
  response = client.connection.put("#{PATH}/#{collection_name}/index") do |req|
    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



152
153
154
155
156
157
# File 'lib/qdrant/collections.rb', line 152

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



66
67
68
69
# File 'lib/qdrant/collections.rb', line 66

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



105
106
107
108
109
110
111
# File 'lib/qdrant/collections.rb', line 105

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



143
144
145
146
147
148
149
# File 'lib/qdrant/collections.rb', line 143

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



133
134
135
136
137
138
139
140
# File 'lib/qdrant/collections.rb', line 133

def download_snapshot(
  collection_name:,
  snapshot_name:,
  filepath:
)
  response = client.connection.get("#{PATH}/#{collection_name}/snapshots/#{snapshot_name}")
  File.open(File.expand_path(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

#listObject

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



160
161
162
163
164
165
# File 'lib/qdrant/collections.rb', line 160

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.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/qdrant/collections.rb', line 168

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



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/qdrant/collections.rb', line 51

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



78
79
80
81
82
83
84
85
86
# File 'lib/qdrant/collections.rb', line 78

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



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/qdrant/collections.rb', line 120

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