chroma-db 0.5.0 → 0.7.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: 2d7ef50774b1e00c56ee2f67670afc3b7d2fd0760ace64627985ed6460701b7b
4
- data.tar.gz: 9e4f771c7ab2fe8b3ceead3efa3dbe3e03155d2ab8823c895b90e72ac78f7f9b
3
+ metadata.gz: 860772eeeda54b7057681aa0d82bf1d1737501c6d699645d74f0df907e2881d0
4
+ data.tar.gz: 66acb245e05333fdf2c2abae27823d8963f7c75c7186b0922ae83265cdb577ca
5
5
  SHA512:
6
- metadata.gz: 3dee2d6604b17ac0baf2872ba0b807ebe7acafdbce4c3fdbc1453f737161e1916b30fe80e7a09daf34d0ced994a918d604e74b4aac355381fff1f89b635fc2ce
7
- data.tar.gz: bb8a63c2937041c4123d08f89704fa755a2096724e57176e37c8fed2d3902d7c6df2889c621cb7ced4372938a70870f47525560c09615c7d8d48520192d3ae4f
6
+ metadata.gz: '09c0a28cc809673c658558f95bb3fa85bc6e4845eb95b076105b4aa0e083693663e0fab386e534ae674848fc0007944b135e8a85d48a4bd616a5a105b7592b31'
7
+ data.tar.gz: b1037adef96c371cbc794580000e40ea1017085093889f248019095f80c82f18d74ca6a5394703f81f873d6366d9a99aebae56dbe6391c4e34274b56d794ccae
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.0] 2023-06-05
4
+
5
+ - Fix failure to rescue from API call exceptions.
6
+ - Fix embedding loading into Embedding resource.
7
+
3
8
  ## [0.5.0] 2023-05-26
4
9
 
5
10
  - Adds method `get_or_create` to Collection class.
data/Gemfile.lock CHANGED
@@ -1,91 +1,103 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chroma-db (0.5.0)
4
+ chroma-db (0.7.0)
5
5
  dry-monads (~> 1.6)
6
6
  ruby-next (>= 0.15.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.8.4)
11
+ abbrev (0.1.2)
12
+ addressable (2.8.6)
12
13
  public_suffix (>= 2.0.2, < 6.0)
13
14
  ast (2.4.2)
14
- concurrent-ruby (1.2.2)
15
- crack (0.4.5)
15
+ bigdecimal (3.1.7)
16
+ concurrent-ruby (1.2.3)
17
+ crack (1.0.0)
18
+ bigdecimal
16
19
  rexml
17
- diff-lcs (1.5.0)
18
- dry-core (1.0.0)
20
+ diff-lcs (1.5.1)
21
+ dry-core (1.0.1)
19
22
  concurrent-ruby (~> 1.0)
20
23
  zeitwerk (~> 2.6)
21
24
  dry-monads (1.6.0)
22
25
  concurrent-ruby (~> 1.0)
23
26
  dry-core (~> 1.0, < 2)
24
27
  zeitwerk (~> 2.6)
25
- hashdiff (1.0.1)
26
- json (2.6.3)
28
+ hashdiff (1.1.0)
29
+ json (2.7.2)
27
30
  language_server-protocol (3.17.0.3)
28
- lint_roller (1.0.0)
29
- minitest (5.18.0)
30
- parallel (1.23.0)
31
- parser (3.2.2.1)
31
+ lint_roller (1.1.0)
32
+ minitest (5.22.3)
33
+ paco (0.2.3)
34
+ parallel (1.24.0)
35
+ parser (3.3.0.5)
32
36
  ast (~> 2.4.1)
33
- psych (5.1.0)
37
+ racc
38
+ psych (5.1.2)
34
39
  stringio
35
- public_suffix (5.0.1)
40
+ public_suffix (5.0.5)
41
+ racc (1.7.3)
36
42
  rainbow (3.1.1)
37
- rake (13.0.6)
38
- rbs (3.1.0)
39
- rdoc (6.5.0)
43
+ rake (13.2.1)
44
+ rbs (3.4.4)
45
+ abbrev
46
+ rdoc (6.6.3.1)
40
47
  psych (>= 4.0.0)
41
- regexp_parser (2.8.0)
42
- rexml (3.2.5)
43
- rubocop (1.50.2)
48
+ regexp_parser (2.9.0)
49
+ require-hooks (0.2.2)
50
+ rexml (3.2.6)
51
+ rubocop (1.62.1)
44
52
  json (~> 2.3)
53
+ language_server-protocol (>= 3.17.0)
45
54
  parallel (~> 1.10)
46
- parser (>= 3.2.0.0)
55
+ parser (>= 3.3.0.2)
47
56
  rainbow (>= 2.2.2, < 4.0)
48
57
  regexp_parser (>= 1.8, < 3.0)
49
58
  rexml (>= 3.2.5, < 4.0)
50
- rubocop-ast (>= 1.28.0, < 2.0)
59
+ rubocop-ast (>= 1.31.1, < 2.0)
51
60
  ruby-progressbar (~> 1.7)
52
61
  unicode-display_width (>= 2.4.0, < 3.0)
53
- rubocop-ast (1.28.1)
54
- parser (>= 3.2.1.0)
55
- rubocop-performance (1.16.0)
56
- rubocop (>= 1.7.0, < 2.0)
57
- rubocop-ast (>= 0.4.0)
58
- ruby-next (0.15.3)
59
- ruby-next-core (= 0.15.3)
60
- ruby-next-parser (>= 3.1.1.0)
62
+ rubocop-ast (1.31.2)
63
+ parser (>= 3.3.0.4)
64
+ rubocop-performance (1.20.2)
65
+ rubocop (>= 1.48.1, < 2.0)
66
+ rubocop-ast (>= 1.30.0, < 2.0)
67
+ ruby-next (1.0.2)
68
+ paco (~> 0.2)
69
+ require-hooks (~> 0.2)
70
+ ruby-next-core (= 1.0.2)
71
+ ruby-next-parser (>= 3.2.2.0)
61
72
  unparser (~> 0.6.0)
62
- ruby-next-core (0.15.3)
63
- ruby-next-parser (3.1.1.3)
73
+ ruby-next-core (1.0.2)
74
+ ruby-next-parser (3.2.2.0)
64
75
  parser (>= 3.0.3.1)
65
76
  ruby-progressbar (1.13.0)
66
77
  sdoc (2.6.1)
67
78
  rdoc (>= 5.0)
68
- standard (1.28.2)
79
+ standard (1.35.1)
69
80
  language_server-protocol (~> 3.17.0.2)
70
81
  lint_roller (~> 1.0)
71
- rubocop (~> 1.50.2)
82
+ rubocop (~> 1.62.0)
72
83
  standard-custom (~> 1.0.0)
73
- standard-performance (~> 1.0.1)
74
- standard-custom (1.0.0)
84
+ standard-performance (~> 1.3)
85
+ standard-custom (1.0.2)
75
86
  lint_roller (~> 1.0)
76
- standard-performance (1.0.1)
77
- lint_roller (~> 1.0)
78
- rubocop-performance (~> 1.16.0)
79
- stringio (3.0.6)
80
- unicode-display_width (2.4.2)
81
- unparser (0.6.7)
87
+ rubocop (~> 1.50)
88
+ standard-performance (1.3.1)
89
+ lint_roller (~> 1.1)
90
+ rubocop-performance (~> 1.20.2)
91
+ stringio (3.1.0)
92
+ unicode-display_width (2.5.0)
93
+ unparser (0.6.13)
82
94
  diff-lcs (~> 1.3)
83
- parser (>= 3.2.0)
84
- webmock (3.18.1)
95
+ parser (>= 3.3.0)
96
+ webmock (3.23.0)
85
97
  addressable (>= 2.8.0)
86
98
  crack (>= 0.3.2)
87
99
  hashdiff (>= 0.4.0, < 2.0.0)
88
- zeitwerk (2.6.8)
100
+ zeitwerk (2.6.13)
89
101
 
90
102
  PLATFORMS
91
103
  arm64-darwin-22
data/README.md CHANGED
@@ -41,7 +41,7 @@ For a complete example, please refer to the Jupyter Noterbook [Chroma gem](https
41
41
 
42
42
  ## Requirements
43
43
  - Ruby 2.7.8 or newer
44
- - Chroma Database 0.3.25 or later running as a client/server model.
44
+ - Chroma Database 0.4.24 or later running as a client/server model.
45
45
 
46
46
  For Chroma database 0.3.22 or older, please use version 0.3.0 of this gem.
47
47
 
@@ -61,6 +61,7 @@ To use the Jupyter Noterbook [Chroma gem](https://github.com/mariochavez/chroma/
61
61
  $ gem install iruby
62
62
  $ iruby register --force
63
63
 
64
+ **NOTE: ** Notebook has an example on how to create embeddings using [Ollama](https://ollama.com) and [Nomic embed text](https://ollama.com/library/nomic-embed-text) with a simple Ruby HTTP client.
64
65
  ## Development 
65
66
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 
66
67
 
@@ -68,6 +69,8 @@ To install this gem onto your local machine, run `bundle exec rake install`.
68
69
 
69
70
  To generate Rdoc documentation for the gem, run `bundle exec rake rdoc`.
70
71
 
72
+ ## Rails integration
73
+ If you are looking for a solution to embed your ActiveRecord models into ChromaDB, look at [Cromable gem](https://github.com/AliOsm/chromable)
71
74
  ## Contributing
72
75
  Bug reports and pull requests are welcome on GitHub at https://github.com/mariochavez/chroma. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mariochavez/chroma/blob/main/CODE_OF_CONDUCT.md). 
73
76
 
@@ -44,7 +44,7 @@ module Chroma
44
44
 
45
45
  request = build_request(method, uri, params)
46
46
 
47
- use_ssl = options.delete(:use_ssl) || false
47
+ use_ssl = uri.scheme == "https"
48
48
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
49
49
  Chroma::Util.log_debug("Sending a request", {method: method, uri: uri, params: params})
50
50
  http.request(request)
@@ -125,6 +125,7 @@ module Chroma
125
125
 
126
126
  request.content_type = "application/json"
127
127
  request.body = params.to_json if params.size > 0
128
+ request.basic_auth(uri.user, uri.password) if !uri.user.nil?
128
129
 
129
130
  request
130
131
  end
@@ -48,7 +48,7 @@ module Chroma
48
48
  if result.success?
49
49
  build_embeddings_response(result.success.body)
50
50
  else
51
- raise_failure_error(result)
51
+ self.class.raise_failure_error(result)
52
52
  end
53
53
  end
54
54
 
@@ -92,7 +92,7 @@ module Chroma
92
92
  if result.success?
93
93
  build_embeddings_response(result.success.body)
94
94
  else
95
- raise_failure_error(result)
95
+ self.class.raise_failure_error(result)
96
96
  end
97
97
  end
98
98
 
@@ -116,7 +116,7 @@ module Chroma
116
116
 
117
117
  return true if result.success?
118
118
 
119
- raise_failure_error(result)
119
+ self.class.raise_failure_error(result)
120
120
  end
121
121
 
122
122
  # Delete embeddings from the collection.
@@ -142,7 +142,7 @@ module Chroma
142
142
 
143
143
  return result.success.body if result.success?
144
144
 
145
- raise_failure_error(result)
145
+ self.class.raise_failure_error(result)
146
146
  end
147
147
 
148
148
  # Update one or many embeddings to the collection.
@@ -166,7 +166,7 @@ module Chroma
166
166
 
167
167
  return true if result.success?
168
168
 
169
- raise_failure_error(result)
169
+ self.class.raise_failure_error(result)
170
170
  end
171
171
 
172
172
  # Upsert (insert or update) one or many embeddings to the collection.
@@ -177,10 +177,10 @@ module Chroma
177
177
  #
178
178
  # collection = Chroma::Resource::Collection.get("ruby-documentation")
179
179
  # embeddings = [
180
- # Embedding.new(id: "Array#fetch", embeddings[9.8, 2.3, 2.9], metadata: {url: "https://..."}),
181
- # Embedding.new(id: "Array#select", embeddings[5.6, 3.1, 4.7], metadata: {url: "https://..."})
180
+ # Embedding.new(id: "Array#fetch", embeddings: [9.8, 2.3, 2.9], metadata: {url: "https://..."}),
181
+ # Embedding.new(id: "Array#select", embeddings: [5.6, 3.1, 4.7], metadata: {url: "https://..."})
182
182
  # ]
183
- # collection.upsert()
183
+ # collection.upsert(embeddings)
184
184
  #
185
185
  # Returns true with success or raises a Chroma::Error on failure.
186
186
  def upsert(embeddings = [])
@@ -193,7 +193,7 @@ module Chroma
193
193
 
194
194
  return true if result.success?
195
195
 
196
- raise_failure_error(result)
196
+ self.class.raise_failure_error(result)
197
197
  end
198
198
 
199
199
  # Count the number of embeddings in a collection.
@@ -209,7 +209,7 @@ module Chroma
209
209
 
210
210
  return result.success.body if result.success?
211
211
 
212
- raise_failure_error(result)
212
+ self.class.raise_failure_error(result)
213
213
  end
214
214
 
215
215
  # Modify the name and metadata of the current collection.
@@ -233,26 +233,10 @@ module Chroma
233
233
  @name = new_name
234
234
  @metadata = new_metadata
235
235
  else
236
- raise_failure_error(result)
236
+ self.class.raise_failure_error(result)
237
237
  end
238
238
  end
239
239
 
240
- # Creates an index for the collection.
241
- #
242
- # Examples:
243
- #
244
- # collection = Chroma::Resource::Collection.get("ruby-documentation")
245
- # collection.create_index
246
- #
247
- # Returns true on success or raise a Chroma::Error on failure.
248
- def create_index
249
- result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/create_index")
250
-
251
- return true if result.success?
252
-
253
- raise_failure_error(result)
254
- end
255
-
256
240
  # Create a new collection on the database.
257
241
  #
258
242
  # name - The name of the collection. Name needs to be between 3-63 characters, starts and ends
@@ -376,7 +360,6 @@ module Chroma
376
360
  raise Chroma::APIError.new(result.failure.body, status: result.failure.status, body: result.failure.body)
377
361
  end
378
362
  end
379
- private_class_method :raise_failure_error
380
363
 
381
364
  private
382
365
 
@@ -397,7 +380,7 @@ module Chroma
397
380
  Chroma::Util.log_debug("Building embeddings from #{result.inspect}")
398
381
 
399
382
  result_ids = result.fetch("ids", []).flatten
400
- result_embeddings = (result.dig("embeddings") || []).flatten
383
+ result_embeddings = result.dig("embeddings") || []
401
384
  result_documents = (result.dig("documents") || []).flatten
402
385
  result_metadatas = (result.dig("metadatas") || []).flatten
403
386
  result_distances = (result.dig("distances") || []).flatten
@@ -29,17 +29,6 @@ module Chroma
29
29
  raise_failure_error(result)
30
30
  end
31
31
 
32
- # Persist Chroma database data.
33
- #
34
- # Resturn true on success or raise a Chroma::Error on failure.
35
- def self.persist
36
- result = execute_request(:post, "#{Chroma.api_url}/persist")
37
-
38
- return result.success.body if result.success?
39
-
40
- raise_failure_error(result)
41
- end
42
-
43
32
  # Check the heartbeat of the Chroma database server.
44
33
  #
45
34
  # Return a Hash with a timestamp.
@@ -44,7 +44,7 @@ module Chroma
44
44
 
45
45
  request = build_request(method, uri, params)
46
46
 
47
- use_ssl = options.delete(:use_ssl) || false
47
+ use_ssl = uri.scheme == "https"
48
48
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
49
49
  Chroma::Util.log_debug("Sending a request", {method: method, uri: uri, params: params})
50
50
  http.request(request)
@@ -117,6 +117,7 @@ module Chroma
117
117
 
118
118
  request.content_type = "application/json"
119
119
  request.body = params.to_json if params.size > 0
120
+ request.basic_auth(uri.user, uri.password) if !uri.user.nil?
120
121
 
121
122
  request
122
123
  end
@@ -48,7 +48,7 @@ module Chroma
48
48
  if result.success?
49
49
  build_embeddings_response(result.success.body)
50
50
  else
51
- raise_failure_error(result)
51
+ self.class.raise_failure_error(result)
52
52
  end
53
53
  end
54
54
 
@@ -92,7 +92,7 @@ module Chroma
92
92
  if result.success?
93
93
  build_embeddings_response(result.success.body)
94
94
  else
95
- raise_failure_error(result)
95
+ self.class.raise_failure_error(result)
96
96
  end
97
97
  end
98
98
 
@@ -116,7 +116,7 @@ module Chroma
116
116
 
117
117
  return true if result.success?
118
118
 
119
- raise_failure_error(result)
119
+ self.class.raise_failure_error(result)
120
120
  end
121
121
 
122
122
  # Delete embeddings from the collection.
@@ -142,7 +142,7 @@ module Chroma
142
142
 
143
143
  return result.success.body if result.success?
144
144
 
145
- raise_failure_error(result)
145
+ self.class.raise_failure_error(result)
146
146
  end
147
147
 
148
148
  # Update one or many embeddings to the collection.
@@ -166,7 +166,7 @@ module Chroma
166
166
 
167
167
  return true if result.success?
168
168
 
169
- raise_failure_error(result)
169
+ self.class.raise_failure_error(result)
170
170
  end
171
171
 
172
172
  # Upsert (insert or update) one or many embeddings to the collection.
@@ -177,10 +177,10 @@ module Chroma
177
177
  #
178
178
  # collection = Chroma::Resource::Collection.get("ruby-documentation")
179
179
  # embeddings = [
180
- # Embedding.new(id: "Array#fetch", embeddings[9.8, 2.3, 2.9], metadata: {url: "https://..."}),
181
- # Embedding.new(id: "Array#select", embeddings[5.6, 3.1, 4.7], metadata: {url: "https://..."})
180
+ # Embedding.new(id: "Array#fetch", embeddings: [9.8, 2.3, 2.9], metadata: {url: "https://..."}),
181
+ # Embedding.new(id: "Array#select", embeddings: [5.6, 3.1, 4.7], metadata: {url: "https://..."})
182
182
  # ]
183
- # collection.upsert()
183
+ # collection.upsert(embeddings)
184
184
  #
185
185
  # Returns true with success or raises a Chroma::Error on failure.
186
186
  def upsert(embeddings = [])
@@ -193,7 +193,7 @@ module Chroma
193
193
 
194
194
  return true if result.success?
195
195
 
196
- raise_failure_error(result)
196
+ self.class.raise_failure_error(result)
197
197
  end
198
198
 
199
199
  # Count the number of embeddings in a collection.
@@ -209,7 +209,7 @@ module Chroma
209
209
 
210
210
  return result.success.body if result.success?
211
211
 
212
- raise_failure_error(result)
212
+ self.class.raise_failure_error(result)
213
213
  end
214
214
 
215
215
  # Modify the name and metadata of the current collection.
@@ -233,26 +233,10 @@ module Chroma
233
233
  @name = new_name
234
234
  @metadata = new_metadata
235
235
  else
236
- raise_failure_error(result)
236
+ self.class.raise_failure_error(result)
237
237
  end
238
238
  end
239
239
 
240
- # Creates an index for the collection.
241
- #
242
- # Examples:
243
- #
244
- # collection = Chroma::Resource::Collection.get("ruby-documentation")
245
- # collection.create_index
246
- #
247
- # Returns true on success or raise a Chroma::Error on failure.
248
- def create_index
249
- result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/create_index")
250
-
251
- return true if result.success?
252
-
253
- raise_failure_error(result)
254
- end
255
-
256
240
  # Create a new collection on the database.
257
241
  #
258
242
  # name - The name of the collection. Name needs to be between 3-63 characters, starts and ends
@@ -372,7 +356,6 @@ module Chroma
372
356
  raise Chroma::APIError.new(result.failure.body, status: result.failure.status, body: result.failure.body)
373
357
  end
374
358
  end
375
- private_class_method :raise_failure_error
376
359
 
377
360
  private
378
361
 
@@ -393,7 +376,7 @@ module Chroma
393
376
  Chroma::Util.log_debug("Building embeddings from #{result.inspect}")
394
377
 
395
378
  result_ids = result.fetch("ids", []).flatten
396
- result_embeddings = (result.dig("embeddings") || []).flatten
379
+ result_embeddings = result.dig("embeddings") || []
397
380
  result_documents = (result.dig("documents") || []).flatten
398
381
  result_metadatas = (result.dig("metadatas") || []).flatten
399
382
  result_distances = (result.dig("distances") || []).flatten
@@ -44,7 +44,7 @@ module Chroma
44
44
 
45
45
  request = build_request(method, uri, params)
46
46
 
47
- use_ssl = options.delete(:use_ssl) || false
47
+ use_ssl = uri.scheme == "https"
48
48
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl:) do |http|
49
49
  Chroma::Util.log_debug("Sending a request", {method:, uri:, params:})
50
50
  http.request(request)
@@ -117,6 +117,7 @@ module Chroma
117
117
 
118
118
  request.content_type = "application/json"
119
119
  request.body = params.to_json if params.size > 0
120
+ request.basic_auth(uri.user, uri.password) if !uri.user.nil?
120
121
 
121
122
  request
122
123
  end
@@ -48,7 +48,7 @@ module Chroma
48
48
  if result.success?
49
49
  build_embeddings_response(result.success.body)
50
50
  else
51
- raise_failure_error(result)
51
+ self.class.raise_failure_error(result)
52
52
  end
53
53
  end
54
54
 
@@ -92,7 +92,7 @@ module Chroma
92
92
  if result.success?
93
93
  build_embeddings_response(result.success.body)
94
94
  else
95
- raise_failure_error(result)
95
+ self.class.raise_failure_error(result)
96
96
  end
97
97
  end
98
98
 
@@ -116,7 +116,7 @@ module Chroma
116
116
 
117
117
  return true if result.success?
118
118
 
119
- raise_failure_error(result)
119
+ self.class.raise_failure_error(result)
120
120
  end
121
121
 
122
122
  # Delete embeddings from the collection.
@@ -142,7 +142,7 @@ module Chroma
142
142
 
143
143
  return result.success.body if result.success?
144
144
 
145
- raise_failure_error(result)
145
+ self.class.raise_failure_error(result)
146
146
  end
147
147
 
148
148
  # Update one or many embeddings to the collection.
@@ -166,7 +166,7 @@ module Chroma
166
166
 
167
167
  return true if result.success?
168
168
 
169
- raise_failure_error(result)
169
+ self.class.raise_failure_error(result)
170
170
  end
171
171
 
172
172
  # Upsert (insert or update) one or many embeddings to the collection.
@@ -177,10 +177,10 @@ module Chroma
177
177
  #
178
178
  # collection = Chroma::Resource::Collection.get("ruby-documentation")
179
179
  # embeddings = [
180
- # Embedding.new(id: "Array#fetch", embeddings[9.8, 2.3, 2.9], metadata: {url: "https://..."}),
181
- # Embedding.new(id: "Array#select", embeddings[5.6, 3.1, 4.7], metadata: {url: "https://..."})
180
+ # Embedding.new(id: "Array#fetch", embeddings: [9.8, 2.3, 2.9], metadata: {url: "https://..."}),
181
+ # Embedding.new(id: "Array#select", embeddings: [5.6, 3.1, 4.7], metadata: {url: "https://..."})
182
182
  # ]
183
- # collection.upsert()
183
+ # collection.upsert(embeddings)
184
184
  #
185
185
  # Returns true with success or raises a Chroma::Error on failure.
186
186
  def upsert(embeddings = [])
@@ -193,7 +193,7 @@ module Chroma
193
193
 
194
194
  return true if result.success?
195
195
 
196
- raise_failure_error(result)
196
+ self.class.raise_failure_error(result)
197
197
  end
198
198
 
199
199
  # Count the number of embeddings in a collection.
@@ -209,7 +209,7 @@ module Chroma
209
209
 
210
210
  return result.success.body if result.success?
211
211
 
212
- raise_failure_error(result)
212
+ self.class.raise_failure_error(result)
213
213
  end
214
214
 
215
215
  # Modify the name and metadata of the current collection.
@@ -233,26 +233,10 @@ module Chroma
233
233
  @name = new_name
234
234
  @metadata = new_metadata
235
235
  else
236
- raise_failure_error(result)
236
+ self.class.raise_failure_error(result)
237
237
  end
238
238
  end
239
239
 
240
- # Creates an index for the collection.
241
- #
242
- # Examples:
243
- #
244
- # collection = Chroma::Resource::Collection.get("ruby-documentation")
245
- # collection.create_index
246
- #
247
- # Returns true on success or raise a Chroma::Error on failure.
248
- def create_index
249
- result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/create_index")
250
-
251
- return true if result.success?
252
-
253
- raise_failure_error(result)
254
- end
255
-
256
240
  # Create a new collection on the database.
257
241
  #
258
242
  # name - The name of the collection. Name needs to be between 3-63 characters, starts and ends
@@ -372,7 +356,6 @@ module Chroma
372
356
  raise Chroma::APIError.new(result.failure.body, status: result.failure.status, body: result.failure.body)
373
357
  end
374
358
  end
375
- private_class_method :raise_failure_error
376
359
 
377
360
  private
378
361
 
@@ -393,7 +376,7 @@ module Chroma
393
376
  Chroma::Util.log_debug("Building embeddings from #{result.inspect}")
394
377
 
395
378
  result_ids = result.fetch("ids", []).flatten
396
- result_embeddings = (result.dig("embeddings") || []).flatten
379
+ result_embeddings = result.dig("embeddings") || []
397
380
  result_documents = (result.dig("documents") || []).flatten
398
381
  result_metadatas = (result.dig("metadatas") || []).flatten
399
382
  result_distances = (result.dig("distances") || []).flatten
@@ -29,17 +29,6 @@ module Chroma
29
29
  raise_failure_error(result)
30
30
  end
31
31
 
32
- # Persist Chroma database data.
33
- #
34
- # Resturn true on success or raise a Chroma::Error on failure.
35
- def self.persist
36
- result = execute_request(:post, "#{Chroma.api_url}/persist")
37
-
38
- return result.success.body if result.success?
39
-
40
- raise_failure_error(result)
41
- end
42
-
43
32
  # Check the heartbeat of the Chroma database server.
44
33
  #
45
34
  # Return a Hash with a timestamp.
data/lib/chroma/util.rb CHANGED
@@ -63,7 +63,7 @@ module Chroma
63
63
  def self.log_internal(message, data = {}, level:, logger:)
64
64
  data_str = data.reject { |_k, v| v.nil? }.map { |(k, v)| "#{k}=#{v}" }.join(" ")
65
65
 
66
- logger&.log(level, "message=#{message} #{data_str}".strip)
66
+ logger&.add(level, "message=#{message} #{data_str}".strip)
67
67
  end
68
68
  private_class_method :log_internal
69
69
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chroma
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.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.5.0
4
+ version: 0.7.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-26 00:00:00.000000000 Z
11
+ date: 2024-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby-next-core
28
+ name: ruby-next
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.4.12
110
+ rubygems_version: 3.5.9
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Ruby client for Chroma DB.