chroma-db 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dd1f6255d588aae1829e27a9b6c75f33367fb131d22ed7aa6074aebe9f1a63e
4
- data.tar.gz: 7b5d9c7bec11e80bcce275af7b2c1f4ea33965fd92a2955b8d835853d2ea5e2d
3
+ metadata.gz: 81e14d1d408077096602201fb386612b9d511a0294726efcba2942491a164763
4
+ data.tar.gz: bc06c130d7ad215d5a2264527813e10900bda1b6d8975de8c59712a7cb438a99
5
5
  SHA512:
6
- metadata.gz: 453ba9818006fc4a28e56160919d1b85cd797c5f67de92a4b06c05a3a9edc15e33b32b1ef819fba96f6ee55a83f4557b3ff188892ec95b544406993e9d5ccc73
7
- data.tar.gz: 05fa61d8ab158ec6e4f00b7f517dac756a4adba6a7ea1025d5d37f8a032de63613311157209b1888e32cd25c83783c8fbe8a6e8ffee98369826a1f5f58dc2c95
6
+ metadata.gz: 109074182103666dca9fb201c0dc473220b0a5ee6849ff3022203a4debea1388347b98d74a0ce14d75361953a1c70b6c1a24ab62387c317e394712fe677e082a
7
+ data.tar.gz: f075cf97229240b6d38ff72946188ec436a0010b8f0925d1b30a63e6c2b3dc0b6bf8436a16d0c3abf5c89cabe64951b73bd10eb036b95a3ae9a40b8f2c778cdd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] 2023-05-23
4
+
5
+ - This version implements Chroma's API change where Collection uses its collection id for many operations. Changes in the
6
+ gem are internals, public API remains the same. Just be aware you need Chroma 0.3.25 or better with this gem version.
7
+
3
8
  ## [0.3.0] 2023-05-19
4
9
 
5
10
  - 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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chroma-db (0.2.0)
4
+ chroma-db (0.4.0)
5
5
  dry-monads (~> 1.6)
6
6
  ruby-next (>= 0.15.0)
7
7
 
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.22 or later running as a client/server model.
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
- # using RubyNext
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
- puts "BUILDING RESPONSE OLD RUBY"
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
- using RubyNext
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
@@ -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/#{name}/get", payload)
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/#{name}/add", payload)
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/#{name}/delete", payload)
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/#{name}/update", payload)
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/#{name}/upsert", payload)
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/#{name}/count")
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/#{name}", payload)
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/#{name}/create_index")
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,7 @@ 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"])
293
296
  else
294
297
  raise_failure_error(result)
295
298
  end
@@ -307,7 +310,7 @@ module Chroma
307
310
 
308
311
  if result.success?
309
312
  data = result.success.body
310
- data.map { |item| new(name: item["name"], metadata: item["metadata"]) }
313
+ data.map { |item| new(id: item["id"], name: item["name"], metadata: item["metadata"]) }
311
314
  else
312
315
  raise_failure_error(result)
313
316
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Chroma
4
4
  module APIOperations
5
- # using RubyNext
5
+ using RubyNext
6
6
 
7
7
  # Request's response Data object.
8
8
  #
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chroma
4
- using RubyNext
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
@@ -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/#{name}/get", payload)
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/#{name}/add", payload)
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/#{name}/delete", payload)
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/#{name}/update", payload)
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/#{name}/upsert", payload)
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/#{name}/count")
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/#{name}", payload)
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/#{name}/create_index")
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,7 @@ 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"])
293
296
  else
294
297
  raise_failure_error(result)
295
298
  end
@@ -307,7 +310,7 @@ module Chroma
307
310
 
308
311
  if result.success?
309
312
  data = result.success.body
310
- data.map { |item| new(name: item["name"], metadata: item["metadata"]) }
313
+ data.map { |item| new(id: item["id"], name: item["name"], metadata: item["metadata"]) }
311
314
  else
312
315
  raise_failure_error(result)
313
316
  end
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chroma
4
- using RubyNext
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/#{name}/query", payload)
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/#{name}/get", payload)
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/#{name}/add", payload)
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/#{name}/delete", payload)
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/#{name}/update", payload)
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/#{name}/upsert", payload)
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/#{name}/count")
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/#{name}", payload)
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/#{name}/create_index")
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,7 @@ 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"])
293
296
  else
294
297
  raise_failure_error(result)
295
298
  end
@@ -307,7 +310,7 @@ module Chroma
307
310
 
308
311
  if result.success?
309
312
  data = result.success.body
310
- data.map { |item| new(name: item["name"], metadata: item["metadata"]) }
313
+ data.map { |item| new(id: item["id"], name: item["name"], metadata: item["metadata"]) }
311
314
  else
312
315
  raise_failure_error(result)
313
316
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chroma
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
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.3.0
4
+ version: 0.4.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-19 00:00:00.000000000 Z
11
+ date: 2023-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads