chroma-db 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81e14d1d408077096602201fb386612b9d511a0294726efcba2942491a164763
4
- data.tar.gz: bc06c130d7ad215d5a2264527813e10900bda1b6d8975de8c59712a7cb438a99
3
+ metadata.gz: 2d7ef50774b1e00c56ee2f67670afc3b7d2fd0760ace64627985ed6460701b7b
4
+ data.tar.gz: 9e4f771c7ab2fe8b3ceead3efa3dbe3e03155d2ab8823c895b90e72ac78f7f9b
5
5
  SHA512:
6
- metadata.gz: 109074182103666dca9fb201c0dc473220b0a5ee6849ff3022203a4debea1388347b98d74a0ce14d75361953a1c70b6c1a24ab62387c317e394712fe677e082a
7
- data.tar.gz: f075cf97229240b6d38ff72946188ec436a0010b8f0925d1b30a63e6c2b3dc0b6bf8436a16d0c3abf5c89cabe64951b73bd10eb036b95a3ae9a40b8f2c778cdd
6
+ metadata.gz: 3dee2d6604b17ac0baf2872ba0b807ebe7acafdbce4c3fdbc1453f737161e1916b30fe80e7a09daf34d0ced994a918d604e74b4aac355381fff1f89b635fc2ce
7
+ data.tar.gz: bb8a63c2937041c4123d08f89704fa755a2096724e57176e37c8fed2d3902d7c6df2889c621cb7ced4372938a70870f47525560c09615c7d8d48520192d3ae4f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] 2023-05-26
4
+
5
+ - Adds method `get_or_create` to Collection class.
6
+
3
7
  ## [0.4.0] 2023-05-23
4
8
 
5
9
  - This version implements Chroma's API change where Collection uses its collection id for many operations. Changes in the
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chroma-db (0.4.0)
4
+ chroma-db (0.5.0)
5
5
  dry-monads (~> 1.6)
6
6
  ruby-next (>= 0.15.0)
7
7
 
@@ -43,7 +43,7 @@ module Chroma
43
43
  include: include
44
44
  }
45
45
 
46
- 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)
47
47
 
48
48
  if result.success?
49
49
  build_embeddings_response(result.success.body)
@@ -298,6 +298,31 @@ module Chroma
298
298
  end
299
299
  end
300
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"])
321
+ else
322
+ raise_failure_error(result)
323
+ end
324
+ end
325
+
301
326
  # Retrieves all collections in the database.
302
327
  #
303
328
  # Examples
@@ -43,7 +43,7 @@ module Chroma
43
43
  include: include
44
44
  }
45
45
 
46
- 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)
47
47
 
48
48
  if result.success?
49
49
  build_embeddings_response(result.success.body)
@@ -298,6 +298,31 @@ module Chroma
298
298
  end
299
299
  end
300
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"])
321
+ else
322
+ raise_failure_error(result)
323
+ end
324
+ end
325
+
301
326
  # Retrieves all collections in the database.
302
327
  #
303
328
  # Examples
@@ -298,6 +298,31 @@ module Chroma
298
298
  end
299
299
  end
300
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"])
321
+ else
322
+ raise_failure_error(result)
323
+ end
324
+ end
325
+
301
326
  # Retrieves all collections in the database.
302
327
  #
303
328
  # Examples
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chroma
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.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.4.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-23 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads