chroma-db 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -3
- data/lib/.rbnext/2.7/chroma/api_operations/request.rb +3 -4
- data/lib/.rbnext/2.7/chroma/resources/collection.rb +42 -14
- data/lib/.rbnext/3.1/chroma/api_operations/request.rb +1 -1
- data/lib/.rbnext/3.1/chroma/resources/collection.rb +42 -14
- data/lib/chroma/resources/collection.rb +42 -14
- data/lib/chroma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d7ef50774b1e00c56ee2f67670afc3b7d2fd0760ace64627985ed6460701b7b
|
4
|
+
data.tar.gz: 9e4f771c7ab2fe8b3ceead3efa3dbe3e03155d2ab8823c895b90e72ac78f7f9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dee2d6604b17ac0baf2872ba0b807ebe7acafdbce4c3fdbc1453f737161e1916b30fe80e7a09daf34d0ced994a918d604e74b4aac355381fff1f89b635fc2ce
|
7
|
+
data.tar.gz: bb8a63c2937041c4123d08f89704fa755a2096724e57176e37c8fed2d3902d7c6df2889c621cb7ced4372938a70870f47525560c09615c7d8d48520192d3ae4f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.0] 2023-05-26
|
4
|
+
|
5
|
+
- Adds method `get_or_create` to Collection class.
|
6
|
+
|
7
|
+
## [0.4.0] 2023-05-23
|
8
|
+
|
9
|
+
- This version implements Chroma's API change where Collection uses its collection id for many operations. Changes in the
|
10
|
+
gem are internals, public API remains the same. Just be aware you need Chroma 0.3.25 or better with this gem version.
|
11
|
+
|
3
12
|
## [0.3.0] 2023-05-19
|
4
13
|
|
5
14
|
- Uses Ruby Next to transpile newer Ruby to older Ruby versions in order to support Ruby 2.7, 3.0, and 3.1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,8 +7,7 @@ This Ruby gem is a client to connect to Chroma's database via its API.
|
|
7
7
|
Find more information about Chroma on how to install at their website. [https://www.trychroma.com/](https://www.trychroma.com/)
|
8
8
|
|
9
9
|
## Description
|
10
|
-
Chroma-rb is a Ruby client for Chroma Database. It works with version
|
11
|
-
0.3.22 or better.
|
10
|
+
Chroma-rb is a Ruby client for Chroma Database. It works with version 0.3.22 or better **(Please see requirements below)**.
|
12
11
|
|
13
12
|
A small example usage
|
14
13
|
|
@@ -42,7 +41,9 @@ For a complete example, please refer to the Jupyter Noterbook [Chroma gem](https
|
|
42
41
|
|
43
42
|
## Requirements
|
44
43
|
- Ruby 2.7.8 or newer
|
45
|
-
- Chroma Database 0.3.
|
44
|
+
- Chroma Database 0.3.25 or later running as a client/server model.
|
45
|
+
|
46
|
+
For Chroma database 0.3.22 or older, please use version 0.3.0 of this gem.
|
46
47
|
|
47
48
|
## Installation
|
48
49
|
To install the gem and add to the application's Gemfile, execute:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Chroma
|
4
4
|
module APIOperations
|
5
|
-
|
5
|
+
using RubyNext
|
6
6
|
|
7
7
|
# Request's response Data object.
|
8
8
|
#
|
@@ -56,8 +56,7 @@ module Chroma
|
|
56
56
|
end
|
57
57
|
|
58
58
|
private def build_response(response)
|
59
|
-
|
60
|
-
case; when ((__m__ = response)) && false
|
59
|
+
case; when ((__m__ = response)) && false
|
61
60
|
when (((success_response,) = nil) || ((Net::HTTPSuccess === __m__) && ((success_response = __m__) || true)))
|
62
61
|
|
63
62
|
|
@@ -101,7 +100,7 @@ module Chroma
|
|
101
100
|
response.is_a?(Net::HTTPSuccess) ? nil : response
|
102
101
|
)
|
103
102
|
|
104
|
-
case; when ((__m__ = response)) && false
|
103
|
+
case; when ((__m__ = response)) && false
|
105
104
|
when (Net::HTTPSuccess === __m__)
|
106
105
|
return Success(response_data)
|
107
106
|
else
|
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Chroma
|
4
|
-
|
4
|
+
using RubyNext
|
5
|
+
|
5
6
|
module Resources
|
6
7
|
# A Collection class represents a store for your embeddings, documents, and any additional metadata.
|
7
8
|
# This class can be instantiated by receiving the collection's name and metadata hash.
|
8
9
|
class Collection
|
9
10
|
include Chroma::APIOperations::Request
|
10
11
|
|
12
|
+
attr_reader :id
|
11
13
|
attr_reader :name
|
12
14
|
attr_reader :metadata
|
13
15
|
|
14
|
-
def initialize(name:, metadata: nil)
|
16
|
+
def initialize(id:, name:, metadata: nil)
|
17
|
+
@id = id
|
15
18
|
@name = name
|
16
19
|
@metadata = metadata
|
17
20
|
end
|
@@ -40,7 +43,7 @@ module Chroma
|
|
40
43
|
include: include
|
41
44
|
}
|
42
45
|
|
43
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
46
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/query", payload)
|
44
47
|
|
45
48
|
if result.success?
|
46
49
|
build_embeddings_response(result.success.body)
|
@@ -84,7 +87,7 @@ module Chroma
|
|
84
87
|
include: include
|
85
88
|
}
|
86
89
|
|
87
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
90
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/get", payload)
|
88
91
|
|
89
92
|
if result.success?
|
90
93
|
build_embeddings_response(result.success.body)
|
@@ -109,7 +112,7 @@ module Chroma
|
|
109
112
|
|
110
113
|
payload = build_embeddings_payload(embeddings_array)
|
111
114
|
|
112
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
115
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/add", payload)
|
113
116
|
|
114
117
|
return true if result.success?
|
115
118
|
|
@@ -135,7 +138,7 @@ module Chroma
|
|
135
138
|
where_document: where_document
|
136
139
|
}
|
137
140
|
|
138
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
141
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/delete", payload)
|
139
142
|
|
140
143
|
return result.success.body if result.success?
|
141
144
|
|
@@ -159,7 +162,7 @@ module Chroma
|
|
159
162
|
payload = build_embeddings_payload(embeddings_array)
|
160
163
|
payload.delete(:increment_index)
|
161
164
|
|
162
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
165
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/update", payload)
|
163
166
|
|
164
167
|
return true if result.success?
|
165
168
|
|
@@ -186,7 +189,7 @@ module Chroma
|
|
186
189
|
|
187
190
|
payload = build_embeddings_payload(embeddings_array)
|
188
191
|
|
189
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
192
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/upsert", payload)
|
190
193
|
|
191
194
|
return true if result.success?
|
192
195
|
|
@@ -202,7 +205,7 @@ module Chroma
|
|
202
205
|
#
|
203
206
|
# Returns the count of embeddings in the collection.
|
204
207
|
def count
|
205
|
-
result = self.class.execute_request(:get, "#{Chroma.api_url}/collections/#{
|
208
|
+
result = self.class.execute_request(:get, "#{Chroma.api_url}/collections/#{id}/count")
|
206
209
|
|
207
210
|
return result.success.body if result.success?
|
208
211
|
|
@@ -224,7 +227,7 @@ module Chroma
|
|
224
227
|
payload = {new_name: new_name}
|
225
228
|
payload[:new_metadata] = new_metadata if new_metadata.any?
|
226
229
|
|
227
|
-
result = self.class.execute_request(:put, "#{Chroma.api_url}/collections/#{
|
230
|
+
result = self.class.execute_request(:put, "#{Chroma.api_url}/collections/#{id}", payload)
|
228
231
|
|
229
232
|
if result.success?
|
230
233
|
@name = new_name
|
@@ -243,7 +246,7 @@ module Chroma
|
|
243
246
|
#
|
244
247
|
# Returns true on success or raise a Chroma::Error on failure.
|
245
248
|
def create_index
|
246
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
249
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/create_index")
|
247
250
|
|
248
251
|
return true if result.success?
|
249
252
|
|
@@ -269,7 +272,7 @@ module Chroma
|
|
269
272
|
|
270
273
|
if result.success?
|
271
274
|
data = result.success.body
|
272
|
-
new(name: data["name"], metadata: data["metadata"])
|
275
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
273
276
|
else
|
274
277
|
raise_failure_error(result)
|
275
278
|
end
|
@@ -289,7 +292,32 @@ module Chroma
|
|
289
292
|
|
290
293
|
if result.success?
|
291
294
|
data = result.success.body
|
292
|
-
new(name: data["name"], metadata: data["metadata"])
|
295
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
296
|
+
else
|
297
|
+
raise_failure_error(result)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# Get or create a collection on the database.
|
302
|
+
#
|
303
|
+
# name - The name of the collection. Name needs to be between 3-63 characters, starts and ends
|
304
|
+
# with an alphanumeric character, contains only alphanumeric characters, underscores or hyphens (-), and
|
305
|
+
# contains no two consecutive periods
|
306
|
+
# metadata - A hash of additional metadata associated with the collection, this is used if collection is created.
|
307
|
+
#
|
308
|
+
# Examples
|
309
|
+
#
|
310
|
+
# collection = Chorma::Resources::Collection.get_or_create("ruby-documentation", {source: "Ruby lang website"})
|
311
|
+
#
|
312
|
+
# Returns the created collection object.
|
313
|
+
def self.get_or_create(name, metadata = nil)
|
314
|
+
payload = {name: name, metadata: metadata, get_or_create: true}
|
315
|
+
|
316
|
+
result = execute_request(:post, "#{Chroma.api_url}/collections", payload)
|
317
|
+
|
318
|
+
if result.success?
|
319
|
+
data = result.success.body
|
320
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
293
321
|
else
|
294
322
|
raise_failure_error(result)
|
295
323
|
end
|
@@ -307,7 +335,7 @@ module Chroma
|
|
307
335
|
|
308
336
|
if result.success?
|
309
337
|
data = result.success.body
|
310
|
-
data.map { |item| new(name: item["name"], metadata: item["metadata"]) }
|
338
|
+
data.map { |item| new(id: item["id"], name: item["name"], metadata: item["metadata"]) }
|
311
339
|
else
|
312
340
|
raise_failure_error(result)
|
313
341
|
end
|
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Chroma
|
4
|
-
|
4
|
+
using RubyNext
|
5
|
+
|
5
6
|
module Resources
|
6
7
|
# A Collection class represents a store for your embeddings, documents, and any additional metadata.
|
7
8
|
# This class can be instantiated by receiving the collection's name and metadata hash.
|
8
9
|
class Collection
|
9
10
|
include Chroma::APIOperations::Request
|
10
11
|
|
12
|
+
attr_reader :id
|
11
13
|
attr_reader :name
|
12
14
|
attr_reader :metadata
|
13
15
|
|
14
|
-
def initialize(name:, metadata: nil)
|
16
|
+
def initialize(id:, name:, metadata: nil)
|
17
|
+
@id = id
|
15
18
|
@name = name
|
16
19
|
@metadata = metadata
|
17
20
|
end
|
@@ -40,7 +43,7 @@ module Chroma
|
|
40
43
|
include: include
|
41
44
|
}
|
42
45
|
|
43
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
46
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/query", payload)
|
44
47
|
|
45
48
|
if result.success?
|
46
49
|
build_embeddings_response(result.success.body)
|
@@ -84,7 +87,7 @@ module Chroma
|
|
84
87
|
include: include
|
85
88
|
}
|
86
89
|
|
87
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
90
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/get", payload)
|
88
91
|
|
89
92
|
if result.success?
|
90
93
|
build_embeddings_response(result.success.body)
|
@@ -109,7 +112,7 @@ module Chroma
|
|
109
112
|
|
110
113
|
payload = build_embeddings_payload(embeddings_array)
|
111
114
|
|
112
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
115
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/add", payload)
|
113
116
|
|
114
117
|
return true if result.success?
|
115
118
|
|
@@ -135,7 +138,7 @@ module Chroma
|
|
135
138
|
where_document: where_document
|
136
139
|
}
|
137
140
|
|
138
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
141
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/delete", payload)
|
139
142
|
|
140
143
|
return result.success.body if result.success?
|
141
144
|
|
@@ -159,7 +162,7 @@ module Chroma
|
|
159
162
|
payload = build_embeddings_payload(embeddings_array)
|
160
163
|
payload.delete(:increment_index)
|
161
164
|
|
162
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
165
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/update", payload)
|
163
166
|
|
164
167
|
return true if result.success?
|
165
168
|
|
@@ -186,7 +189,7 @@ module Chroma
|
|
186
189
|
|
187
190
|
payload = build_embeddings_payload(embeddings_array)
|
188
191
|
|
189
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
192
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/upsert", payload)
|
190
193
|
|
191
194
|
return true if result.success?
|
192
195
|
|
@@ -202,7 +205,7 @@ module Chroma
|
|
202
205
|
#
|
203
206
|
# Returns the count of embeddings in the collection.
|
204
207
|
def count
|
205
|
-
result = self.class.execute_request(:get, "#{Chroma.api_url}/collections/#{
|
208
|
+
result = self.class.execute_request(:get, "#{Chroma.api_url}/collections/#{id}/count")
|
206
209
|
|
207
210
|
return result.success.body if result.success?
|
208
211
|
|
@@ -224,7 +227,7 @@ module Chroma
|
|
224
227
|
payload = {new_name: new_name}
|
225
228
|
payload[:new_metadata] = new_metadata if new_metadata.any?
|
226
229
|
|
227
|
-
result = self.class.execute_request(:put, "#{Chroma.api_url}/collections/#{
|
230
|
+
result = self.class.execute_request(:put, "#{Chroma.api_url}/collections/#{id}", payload)
|
228
231
|
|
229
232
|
if result.success?
|
230
233
|
@name = new_name
|
@@ -243,7 +246,7 @@ module Chroma
|
|
243
246
|
#
|
244
247
|
# Returns true on success or raise a Chroma::Error on failure.
|
245
248
|
def create_index
|
246
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
249
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/create_index")
|
247
250
|
|
248
251
|
return true if result.success?
|
249
252
|
|
@@ -269,7 +272,7 @@ module Chroma
|
|
269
272
|
|
270
273
|
if result.success?
|
271
274
|
data = result.success.body
|
272
|
-
new(name: data["name"], metadata: data["metadata"])
|
275
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
273
276
|
else
|
274
277
|
raise_failure_error(result)
|
275
278
|
end
|
@@ -289,7 +292,32 @@ module Chroma
|
|
289
292
|
|
290
293
|
if result.success?
|
291
294
|
data = result.success.body
|
292
|
-
new(name: data["name"], metadata: data["metadata"])
|
295
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
296
|
+
else
|
297
|
+
raise_failure_error(result)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# Get or create a collection on the database.
|
302
|
+
#
|
303
|
+
# name - The name of the collection. Name needs to be between 3-63 characters, starts and ends
|
304
|
+
# with an alphanumeric character, contains only alphanumeric characters, underscores or hyphens (-), and
|
305
|
+
# contains no two consecutive periods
|
306
|
+
# metadata - A hash of additional metadata associated with the collection, this is used if collection is created.
|
307
|
+
#
|
308
|
+
# Examples
|
309
|
+
#
|
310
|
+
# collection = Chorma::Resources::Collection.get_or_create("ruby-documentation", {source: "Ruby lang website"})
|
311
|
+
#
|
312
|
+
# Returns the created collection object.
|
313
|
+
def self.get_or_create(name, metadata = nil)
|
314
|
+
payload = {name: name, metadata: metadata, get_or_create: true}
|
315
|
+
|
316
|
+
result = execute_request(:post, "#{Chroma.api_url}/collections", payload)
|
317
|
+
|
318
|
+
if result.success?
|
319
|
+
data = result.success.body
|
320
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
293
321
|
else
|
294
322
|
raise_failure_error(result)
|
295
323
|
end
|
@@ -307,7 +335,7 @@ module Chroma
|
|
307
335
|
|
308
336
|
if result.success?
|
309
337
|
data = result.success.body
|
310
|
-
data.map { |item| new(name: item["name"], metadata: item["metadata"]) }
|
338
|
+
data.map { |item| new(id: item["id"], name: item["name"], metadata: item["metadata"]) }
|
311
339
|
else
|
312
340
|
raise_failure_error(result)
|
313
341
|
end
|
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Chroma
|
4
|
-
|
4
|
+
using RubyNext
|
5
|
+
|
5
6
|
module Resources
|
6
7
|
# A Collection class represents a store for your embeddings, documents, and any additional metadata.
|
7
8
|
# This class can be instantiated by receiving the collection's name and metadata hash.
|
8
9
|
class Collection
|
9
10
|
include Chroma::APIOperations::Request
|
10
11
|
|
12
|
+
attr_reader :id
|
11
13
|
attr_reader :name
|
12
14
|
attr_reader :metadata
|
13
15
|
|
14
|
-
def initialize(name:, metadata: nil)
|
16
|
+
def initialize(id:, name:, metadata: nil)
|
17
|
+
@id = id
|
15
18
|
@name = name
|
16
19
|
@metadata = metadata
|
17
20
|
end
|
@@ -40,7 +43,7 @@ module Chroma
|
|
40
43
|
include:
|
41
44
|
}
|
42
45
|
|
43
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
46
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/query", payload)
|
44
47
|
|
45
48
|
if result.success?
|
46
49
|
build_embeddings_response(result.success.body)
|
@@ -84,7 +87,7 @@ module Chroma
|
|
84
87
|
include:
|
85
88
|
}
|
86
89
|
|
87
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
90
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/get", payload)
|
88
91
|
|
89
92
|
if result.success?
|
90
93
|
build_embeddings_response(result.success.body)
|
@@ -109,7 +112,7 @@ module Chroma
|
|
109
112
|
|
110
113
|
payload = build_embeddings_payload(embeddings_array)
|
111
114
|
|
112
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
115
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/add", payload)
|
113
116
|
|
114
117
|
return true if result.success?
|
115
118
|
|
@@ -135,7 +138,7 @@ module Chroma
|
|
135
138
|
where_document:
|
136
139
|
}
|
137
140
|
|
138
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
141
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/delete", payload)
|
139
142
|
|
140
143
|
return result.success.body if result.success?
|
141
144
|
|
@@ -159,7 +162,7 @@ module Chroma
|
|
159
162
|
payload = build_embeddings_payload(embeddings_array)
|
160
163
|
payload.delete(:increment_index)
|
161
164
|
|
162
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
165
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/update", payload)
|
163
166
|
|
164
167
|
return true if result.success?
|
165
168
|
|
@@ -186,7 +189,7 @@ module Chroma
|
|
186
189
|
|
187
190
|
payload = build_embeddings_payload(embeddings_array)
|
188
191
|
|
189
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
192
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/upsert", payload)
|
190
193
|
|
191
194
|
return true if result.success?
|
192
195
|
|
@@ -202,7 +205,7 @@ module Chroma
|
|
202
205
|
#
|
203
206
|
# Returns the count of embeddings in the collection.
|
204
207
|
def count
|
205
|
-
result = self.class.execute_request(:get, "#{Chroma.api_url}/collections/#{
|
208
|
+
result = self.class.execute_request(:get, "#{Chroma.api_url}/collections/#{id}/count")
|
206
209
|
|
207
210
|
return result.success.body if result.success?
|
208
211
|
|
@@ -224,7 +227,7 @@ module Chroma
|
|
224
227
|
payload = {new_name:}
|
225
228
|
payload[:new_metadata] = new_metadata if new_metadata.any?
|
226
229
|
|
227
|
-
result = self.class.execute_request(:put, "#{Chroma.api_url}/collections/#{
|
230
|
+
result = self.class.execute_request(:put, "#{Chroma.api_url}/collections/#{id}", payload)
|
228
231
|
|
229
232
|
if result.success?
|
230
233
|
@name = new_name
|
@@ -243,7 +246,7 @@ module Chroma
|
|
243
246
|
#
|
244
247
|
# Returns true on success or raise a Chroma::Error on failure.
|
245
248
|
def create_index
|
246
|
-
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{
|
249
|
+
result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/create_index")
|
247
250
|
|
248
251
|
return true if result.success?
|
249
252
|
|
@@ -269,7 +272,7 @@ module Chroma
|
|
269
272
|
|
270
273
|
if result.success?
|
271
274
|
data = result.success.body
|
272
|
-
new(name: data["name"], metadata: data["metadata"])
|
275
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
273
276
|
else
|
274
277
|
raise_failure_error(result)
|
275
278
|
end
|
@@ -289,7 +292,32 @@ module Chroma
|
|
289
292
|
|
290
293
|
if result.success?
|
291
294
|
data = result.success.body
|
292
|
-
new(name: data["name"], metadata: data["metadata"])
|
295
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
296
|
+
else
|
297
|
+
raise_failure_error(result)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# Get or create a collection on the database.
|
302
|
+
#
|
303
|
+
# name - The name of the collection. Name needs to be between 3-63 characters, starts and ends
|
304
|
+
# with an alphanumeric character, contains only alphanumeric characters, underscores or hyphens (-), and
|
305
|
+
# contains no two consecutive periods
|
306
|
+
# metadata - A hash of additional metadata associated with the collection, this is used if collection is created.
|
307
|
+
#
|
308
|
+
# Examples
|
309
|
+
#
|
310
|
+
# collection = Chorma::Resources::Collection.get_or_create("ruby-documentation", {source: "Ruby lang website"})
|
311
|
+
#
|
312
|
+
# Returns the created collection object.
|
313
|
+
def self.get_or_create(name, metadata = nil)
|
314
|
+
payload = {name:, metadata:, get_or_create: true}
|
315
|
+
|
316
|
+
result = execute_request(:post, "#{Chroma.api_url}/collections", payload)
|
317
|
+
|
318
|
+
if result.success?
|
319
|
+
data = result.success.body
|
320
|
+
new(id: data["id"], name: data["name"], metadata: data["metadata"])
|
293
321
|
else
|
294
322
|
raise_failure_error(result)
|
295
323
|
end
|
@@ -307,7 +335,7 @@ module Chroma
|
|
307
335
|
|
308
336
|
if result.success?
|
309
337
|
data = result.success.body
|
310
|
-
data.map { |item| new(name: item["name"], metadata: item["metadata"]) }
|
338
|
+
data.map { |item| new(id: item["id"], name: item["name"], metadata: item["metadata"]) }
|
311
339
|
else
|
312
340
|
raise_failure_error(result)
|
313
341
|
end
|
data/lib/chroma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chroma-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Alberto Chávez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|