chroma-db 0.7.0 → 0.8.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/.rbnextrc +1 -1
- data/.ruby-version +1 -1
- data/Gemfile +5 -9
- data/Gemfile.lock +48 -46
- data/README.md +33 -10
- data/lib/chroma/api_operations/request.rb +1 -1
- data/lib/chroma/chroma.rb +15 -1
- data/lib/chroma/chroma_configuration.rb +30 -0
- data/lib/chroma/version.rb +1 -1
- metadata +34 -13
- data/lib/.rbnext/2.7/chroma/api_operations/request.rb +0 -139
- data/lib/.rbnext/2.7/chroma/resources/collection.rb +0 -400
- data/lib/.rbnext/2.7/chroma/resources/database.rb +0 -64
- data/lib/.rbnext/3.1/chroma/api_operations/request.rb +0 -131
- data/lib/.rbnext/3.1/chroma/resources/collection.rb +0 -396
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31c131ea9ab54905d2665520303a6fa9790e960cd70db7b8cfda1aac3ee09231
|
|
4
|
+
data.tar.gz: d21d2e933fee0ad66f37f053982e3601db7b3bce1702ce6ecb8cd6e0f70d8018
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc54636facaf17ca619aebc999c9712f8babb112c53dca3935e3027bdb7d37e1412554fbef93357459e8da505c4f1030fbba7480474882667481c8fdb962fbc2
|
|
7
|
+
data.tar.gz: 12b613729e1f6981f56c7d4c91324ab417a2e6a05e299bd11eeb15388f49c8f5b45ec6e5b6287522789be2ae65b9387e9357ba14bebe31ec26838d0b784f4917
|
data/.rbnextrc
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.3.5
|
data/Gemfile
CHANGED
|
@@ -5,14 +5,10 @@ source "https://rubygems.org"
|
|
|
5
5
|
# Specify your gem's dependencies in chroma-db.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
gem "rake", "~> 13.
|
|
9
|
-
|
|
10
|
-
gem "minitest", "~> 5.0"
|
|
11
|
-
|
|
12
|
-
gem "standard", "~> 1.3"
|
|
13
|
-
|
|
14
|
-
gem "rbs", "~> 3.1"
|
|
8
|
+
gem "rake", "~> 13.2", ">= 13.2.1"
|
|
15
9
|
|
|
10
|
+
gem "minitest", "~> 5.25.0"
|
|
11
|
+
gem "standard", "~> 1.41"
|
|
12
|
+
gem "rbs", "~> 3.6.0"
|
|
16
13
|
gem "sdoc", "~> 2.6", ">= 2.6.1"
|
|
17
|
-
|
|
18
|
-
gem "webmock", "~> 3.18", ">= 3.18.1"
|
|
14
|
+
gem "webmock", "~> 3.24"
|
data/Gemfile.lock
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
chroma-db (0.
|
|
4
|
+
chroma-db (0.8.0)
|
|
5
5
|
dry-monads (~> 1.6)
|
|
6
|
-
ruby-next (>= 0.
|
|
6
|
+
ruby-next (~> 1.0, >= 1.0.3)
|
|
7
|
+
zeitwerk (~> 2.6.0)
|
|
7
8
|
|
|
8
9
|
GEM
|
|
9
10
|
remote: https://rubygems.org/
|
|
10
11
|
specs:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
public_suffix (>= 2.0.2, < 6.0)
|
|
12
|
+
addressable (2.8.7)
|
|
13
|
+
public_suffix (>= 2.0.2, < 7.0)
|
|
14
14
|
ast (2.4.2)
|
|
15
|
-
bigdecimal (3.1.
|
|
16
|
-
concurrent-ruby (1.
|
|
15
|
+
bigdecimal (3.1.8)
|
|
16
|
+
concurrent-ruby (1.3.4)
|
|
17
17
|
crack (1.0.0)
|
|
18
18
|
bigdecimal
|
|
19
19
|
rexml
|
|
@@ -25,93 +25,95 @@ GEM
|
|
|
25
25
|
concurrent-ruby (~> 1.0)
|
|
26
26
|
dry-core (~> 1.0, < 2)
|
|
27
27
|
zeitwerk (~> 2.6)
|
|
28
|
-
hashdiff (1.1.
|
|
28
|
+
hashdiff (1.1.1)
|
|
29
29
|
json (2.7.2)
|
|
30
30
|
language_server-protocol (3.17.0.3)
|
|
31
31
|
lint_roller (1.1.0)
|
|
32
|
-
|
|
32
|
+
logger (1.6.1)
|
|
33
|
+
minitest (5.25.1)
|
|
33
34
|
paco (0.2.3)
|
|
34
|
-
parallel (1.
|
|
35
|
-
parser (3.3.0
|
|
35
|
+
parallel (1.26.3)
|
|
36
|
+
parser (3.3.5.0)
|
|
36
37
|
ast (~> 2.4.1)
|
|
37
38
|
racc
|
|
38
39
|
psych (5.1.2)
|
|
39
40
|
stringio
|
|
40
|
-
public_suffix (
|
|
41
|
-
racc (1.
|
|
41
|
+
public_suffix (6.0.1)
|
|
42
|
+
racc (1.8.1)
|
|
42
43
|
rainbow (3.1.1)
|
|
43
44
|
rake (13.2.1)
|
|
44
|
-
rbs (3.
|
|
45
|
-
|
|
46
|
-
rdoc (6.
|
|
45
|
+
rbs (3.6.1)
|
|
46
|
+
logger
|
|
47
|
+
rdoc (6.7.0)
|
|
47
48
|
psych (>= 4.0.0)
|
|
48
|
-
regexp_parser (2.9.
|
|
49
|
+
regexp_parser (2.9.2)
|
|
49
50
|
require-hooks (0.2.2)
|
|
50
|
-
rexml (3.
|
|
51
|
-
rubocop (1.
|
|
51
|
+
rexml (3.3.8)
|
|
52
|
+
rubocop (1.66.1)
|
|
52
53
|
json (~> 2.3)
|
|
53
54
|
language_server-protocol (>= 3.17.0)
|
|
54
55
|
parallel (~> 1.10)
|
|
55
56
|
parser (>= 3.3.0.2)
|
|
56
57
|
rainbow (>= 2.2.2, < 4.0)
|
|
57
|
-
regexp_parser (>=
|
|
58
|
-
|
|
59
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
|
58
|
+
regexp_parser (>= 2.4, < 3.0)
|
|
59
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
|
60
60
|
ruby-progressbar (~> 1.7)
|
|
61
61
|
unicode-display_width (>= 2.4.0, < 3.0)
|
|
62
|
-
rubocop-ast (1.
|
|
63
|
-
parser (>= 3.3.0
|
|
64
|
-
rubocop-performance (1.
|
|
62
|
+
rubocop-ast (1.32.3)
|
|
63
|
+
parser (>= 3.3.1.0)
|
|
64
|
+
rubocop-performance (1.22.1)
|
|
65
65
|
rubocop (>= 1.48.1, < 2.0)
|
|
66
|
-
rubocop-ast (>= 1.
|
|
67
|
-
ruby-next (1.0.
|
|
66
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
|
67
|
+
ruby-next (1.0.3)
|
|
68
68
|
paco (~> 0.2)
|
|
69
69
|
require-hooks (~> 0.2)
|
|
70
|
-
ruby-next-core (= 1.0.
|
|
70
|
+
ruby-next-core (= 1.0.3)
|
|
71
71
|
ruby-next-parser (>= 3.2.2.0)
|
|
72
72
|
unparser (~> 0.6.0)
|
|
73
|
-
ruby-next-core (1.0.
|
|
73
|
+
ruby-next-core (1.0.3)
|
|
74
74
|
ruby-next-parser (3.2.2.0)
|
|
75
75
|
parser (>= 3.0.3.1)
|
|
76
76
|
ruby-progressbar (1.13.0)
|
|
77
77
|
sdoc (2.6.1)
|
|
78
78
|
rdoc (>= 5.0)
|
|
79
|
-
standard (1.
|
|
79
|
+
standard (1.41.0)
|
|
80
80
|
language_server-protocol (~> 3.17.0.2)
|
|
81
81
|
lint_roller (~> 1.0)
|
|
82
|
-
rubocop (~> 1.
|
|
82
|
+
rubocop (~> 1.66.0)
|
|
83
83
|
standard-custom (~> 1.0.0)
|
|
84
|
-
standard-performance (~> 1.
|
|
84
|
+
standard-performance (~> 1.5)
|
|
85
85
|
standard-custom (1.0.2)
|
|
86
86
|
lint_roller (~> 1.0)
|
|
87
87
|
rubocop (~> 1.50)
|
|
88
|
-
standard-performance (1.
|
|
88
|
+
standard-performance (1.5.0)
|
|
89
89
|
lint_roller (~> 1.1)
|
|
90
|
-
rubocop-performance (~> 1.
|
|
91
|
-
stringio (3.1.
|
|
92
|
-
unicode-display_width (2.
|
|
93
|
-
unparser (0.6.
|
|
90
|
+
rubocop-performance (~> 1.22.0)
|
|
91
|
+
stringio (3.1.1)
|
|
92
|
+
unicode-display_width (2.6.0)
|
|
93
|
+
unparser (0.6.15)
|
|
94
94
|
diff-lcs (~> 1.3)
|
|
95
95
|
parser (>= 3.3.0)
|
|
96
|
-
webmock (3.
|
|
96
|
+
webmock (3.24.0)
|
|
97
97
|
addressable (>= 2.8.0)
|
|
98
98
|
crack (>= 0.3.2)
|
|
99
99
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
100
|
-
zeitwerk (2.6.
|
|
100
|
+
zeitwerk (2.6.18)
|
|
101
101
|
|
|
102
102
|
PLATFORMS
|
|
103
103
|
arm64-darwin-22
|
|
104
|
+
arm64-darwin-24
|
|
105
|
+
x86_64-darwin-22
|
|
104
106
|
x86_64-linux
|
|
105
107
|
|
|
106
108
|
DEPENDENCIES
|
|
107
109
|
chroma-db!
|
|
108
|
-
minitest (~> 5.0)
|
|
109
|
-
rake (~> 13.
|
|
110
|
-
rbs (~> 3.
|
|
111
|
-
ruby-next (>= 0.
|
|
110
|
+
minitest (~> 5.25.0)
|
|
111
|
+
rake (~> 13.2, >= 13.2.1)
|
|
112
|
+
rbs (~> 3.6.0)
|
|
113
|
+
ruby-next (~> 1.0, >= 1.0.3)
|
|
112
114
|
sdoc (~> 2.6, >= 2.6.1)
|
|
113
|
-
standard (~> 1.
|
|
114
|
-
webmock (~> 3.
|
|
115
|
+
standard (~> 1.41)
|
|
116
|
+
webmock (~> 3.24)
|
|
115
117
|
|
|
116
118
|
BUNDLED WITH
|
|
117
|
-
2.4.
|
|
119
|
+
2.4.19
|
data/README.md
CHANGED
|
@@ -7,6 +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
|
+
|
|
10
11
|
Chroma-rb is a Ruby client for Chroma Database. It works with version 0.3.22 or better **(Please see requirements below)**.
|
|
11
12
|
|
|
12
13
|
A small example usage
|
|
@@ -39,43 +40,65 @@ collection.add(embeddings)
|
|
|
39
40
|
|
|
40
41
|
For a complete example, please refer to the Jupyter Noterbook [Chroma gem](https://github.com/mariochavez/chroma/blob/main/notebook/Chroma%20Gem.ipynb)
|
|
41
42
|
|
|
43
|
+
### Hosted Chroma
|
|
44
|
+
|
|
45
|
+
You can use this gem with Chroma hosted service at [https://trychroma.com](https://trychroma.com). In the configuration
|
|
46
|
+
options, you can set the `api_key` to use the hosted service. Also, you can set the `tenant` and `database` to use
|
|
47
|
+
the hosted service, by default they are set to `default_tenant` and `default_database`.
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
Chroma.api_key = "cd75e50bf8213fb7ce57c05b"
|
|
51
|
+
Chroma.tenant = "my_tenant" # Optional
|
|
52
|
+
Chroma.database = "my_database" # Optional
|
|
53
|
+
```
|
|
54
|
+
|
|
42
55
|
## Requirements
|
|
43
|
-
|
|
56
|
+
|
|
57
|
+
- Ruby 3.0.6 or newer
|
|
44
58
|
- Chroma Database 0.4.24 or later running as a client/server model.
|
|
45
59
|
|
|
46
60
|
For Chroma database 0.3.22 or older, please use version 0.3.0 of this gem.
|
|
47
61
|
|
|
48
62
|
## Installation
|
|
63
|
+
|
|
49
64
|
To install the gem and add to the application's Gemfile, execute:
|
|
50
65
|
|
|
51
|
-
|
|
66
|
+
bundle add chroma-db
|
|
52
67
|
|
|
53
68
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
54
69
|
|
|
55
|
-
|
|
70
|
+
gem install chroma-db
|
|
56
71
|
|
|
57
72
|
## Use the Jupyter notebook
|
|
73
|
+
|
|
58
74
|
To use the Jupyter Noterbook [Chroma gem](https://github.com/mariochavez/chroma/blob/main/notebook/Chroma%20Gem.ipynb) in this repository, please install python 3.9 or better, iruby and Jupyter notebook dependencies:
|
|
59
75
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
76
|
+
pip install jupyterlab notebook ipywidgets
|
|
77
|
+
gem install iruby
|
|
78
|
+
iruby register --force
|
|
79
|
+
|
|
80
|
+
**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.
|
|
63
81
|
|
|
64
|
-
|
|
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.
|
|
82
|
+
## Development
|
|
83
|
+
|
|
84
|
+
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.
|
|
67
85
|
|
|
68
86
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
69
87
|
|
|
70
88
|
To generate Rdoc documentation for the gem, run `bundle exec rake rdoc`.
|
|
71
89
|
|
|
72
90
|
## Rails integration
|
|
91
|
+
|
|
73
92
|
If you are looking for a solution to embed your ActiveRecord models into ChromaDB, look at [Cromable gem](https://github.com/AliOsm/chromable)
|
|
93
|
+
|
|
74
94
|
## Contributing
|
|
75
|
-
|
|
95
|
+
|
|
96
|
+
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).
|
|
76
97
|
|
|
77
98
|
## License
|
|
99
|
+
|
|
78
100
|
The gem is available as open source under the terms of the [MIT License](https://github.com/mariochavez/chroma/blob/main/LICENSE.txt).
|
|
79
101
|
|
|
80
102
|
## Code of Conduct
|
|
103
|
+
|
|
81
104
|
Everyone interacting in the Chroma project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mariochavez/chroma/blob/main/CODE_OF_CONDUCT.md).
|
|
@@ -118,7 +118,7 @@ module Chroma
|
|
|
118
118
|
request.content_type = "application/json"
|
|
119
119
|
request.body = params.to_json if params.size > 0
|
|
120
120
|
request.basic_auth(uri.user, uri.password) if !uri.user.nil?
|
|
121
|
-
|
|
121
|
+
request['X-Chroma-Token'] = ENV.fetch('CHROMA_SERVER_AUTHN_CREDENTIALS', nil) if ENV.fetch('CHROMA_SERVER_AUTHN_CREDENTIALS', nil)
|
|
122
122
|
request
|
|
123
123
|
end
|
|
124
124
|
end
|
data/lib/chroma/chroma.rb
CHANGED
|
@@ -19,10 +19,24 @@ module Chroma
|
|
|
19
19
|
def_delegators :@config, :api_version, :api_version=
|
|
20
20
|
def_delegators :@config, :log_level, :log_level=
|
|
21
21
|
def_delegators :@config, :logger, :logger=
|
|
22
|
+
def_delegators :@config, :tenant, :tenant=
|
|
23
|
+
def_delegators :@config, :database, :database=
|
|
24
|
+
def_delegators :@config, :api_key, :api_key=
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
def self.api_url
|
|
25
|
-
"#{connect_host}/#{api_base}/#{api_version}"
|
|
28
|
+
base_url = "#{connect_host}/#{api_base}/#{api_version}"
|
|
29
|
+
uri = URI(base_url)
|
|
30
|
+
|
|
31
|
+
unless api_key.nil?
|
|
32
|
+
query_params = {
|
|
33
|
+
tenant: tenant,
|
|
34
|
+
database: database
|
|
35
|
+
}
|
|
36
|
+
query_params["x-chroma-token"] = api_key
|
|
37
|
+
uri.query = URI.encode_www_form(query_params)
|
|
38
|
+
end
|
|
39
|
+
uri.to_s
|
|
26
40
|
end
|
|
27
41
|
|
|
28
42
|
Chroma.log_level = ENV["CHROMA_LOG"].to_i unless ENV["CHROMA_LOG"].nil?
|
|
@@ -26,6 +26,33 @@ module Chroma
|
|
|
26
26
|
# Returns the String host name.
|
|
27
27
|
attr_accessor :connect_host
|
|
28
28
|
|
|
29
|
+
# Sets the tenant for the Chroma service, Defaults to 'default_tenant'.
|
|
30
|
+
#
|
|
31
|
+
# Examples
|
|
32
|
+
#
|
|
33
|
+
# config.tenant = "my_tenant"
|
|
34
|
+
#
|
|
35
|
+
# Returns the String tenant.
|
|
36
|
+
attr_accessor :tenant
|
|
37
|
+
|
|
38
|
+
# Sets the database for the Chroma service, Defaults to 'default_database'.
|
|
39
|
+
#
|
|
40
|
+
# Examples
|
|
41
|
+
#
|
|
42
|
+
# config.database = "my_database"
|
|
43
|
+
#
|
|
44
|
+
# Returns the String database.
|
|
45
|
+
attr_accessor :database
|
|
46
|
+
|
|
47
|
+
# Sets the API Key for the Chroma service, for `x-chroma-token` header.
|
|
48
|
+
#
|
|
49
|
+
# Examples
|
|
50
|
+
#
|
|
51
|
+
# config.api_key = "1234abcd"
|
|
52
|
+
#
|
|
53
|
+
# Returns the String database.
|
|
54
|
+
attr_accessor :api_key
|
|
55
|
+
|
|
29
56
|
# Sets the base path for the Chroma API.
|
|
30
57
|
#
|
|
31
58
|
# Examples
|
|
@@ -70,6 +97,9 @@ module Chroma
|
|
|
70
97
|
@api_version = "v1"
|
|
71
98
|
|
|
72
99
|
@log_level = Chroma::LEVEL_INFO
|
|
100
|
+
|
|
101
|
+
@tenant ||= "default_tenant"
|
|
102
|
+
@database ||= "default_database"
|
|
73
103
|
end
|
|
74
104
|
end
|
|
75
105
|
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.8.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: 2024-
|
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dry-monads
|
|
@@ -24,34 +24,60 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: zeitwerk
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 2.6.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 2.6.0
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: ruby-next
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
30
44
|
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.0'
|
|
31
48
|
- - ">="
|
|
32
49
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.
|
|
50
|
+
version: 1.0.3
|
|
34
51
|
type: :runtime
|
|
35
52
|
prerelease: false
|
|
36
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
54
|
requirements:
|
|
55
|
+
- - "~>"
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '1.0'
|
|
38
58
|
- - ">="
|
|
39
59
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.
|
|
60
|
+
version: 1.0.3
|
|
41
61
|
- !ruby/object:Gem::Dependency
|
|
42
62
|
name: ruby-next
|
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
|
44
64
|
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1.0'
|
|
45
68
|
- - ">="
|
|
46
69
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.
|
|
70
|
+
version: 1.0.3
|
|
48
71
|
type: :development
|
|
49
72
|
prerelease: false
|
|
50
73
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
74
|
requirements:
|
|
75
|
+
- - "~>"
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '1.0'
|
|
52
78
|
- - ">="
|
|
53
79
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.
|
|
80
|
+
version: 1.0.3
|
|
55
81
|
description: Chroma is the open-source embedding database. Chroma makes it easy to
|
|
56
82
|
build LLM apps by making knowledge, facts, and skills pluggable for LLMs.
|
|
57
83
|
email:
|
|
@@ -69,11 +95,6 @@ files:
|
|
|
69
95
|
- LICENSE.txt
|
|
70
96
|
- README.md
|
|
71
97
|
- Rakefile
|
|
72
|
-
- lib/.rbnext/2.7/chroma/api_operations/request.rb
|
|
73
|
-
- lib/.rbnext/2.7/chroma/resources/collection.rb
|
|
74
|
-
- lib/.rbnext/2.7/chroma/resources/database.rb
|
|
75
|
-
- lib/.rbnext/3.1/chroma/api_operations/request.rb
|
|
76
|
-
- lib/.rbnext/3.1/chroma/resources/collection.rb
|
|
77
98
|
- lib/chroma-db.rb
|
|
78
99
|
- lib/chroma/api_operations/request.rb
|
|
79
100
|
- lib/chroma/chroma.rb
|
|
@@ -100,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
100
121
|
requirements:
|
|
101
122
|
- - ">="
|
|
102
123
|
- !ruby/object:Gem::Version
|
|
103
|
-
version:
|
|
124
|
+
version: 3.1.4
|
|
104
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
126
|
requirements:
|
|
106
127
|
- - ">="
|
|
107
128
|
- !ruby/object:Gem::Version
|
|
108
129
|
version: '0'
|
|
109
130
|
requirements: []
|
|
110
|
-
rubygems_version: 3.5.
|
|
131
|
+
rubygems_version: 3.5.21
|
|
111
132
|
signing_key:
|
|
112
133
|
specification_version: 4
|
|
113
134
|
summary: Ruby client for Chroma DB.
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Chroma
|
|
4
|
-
module APIOperations
|
|
5
|
-
using RubyNext
|
|
6
|
-
|
|
7
|
-
# Request's response Data object.
|
|
8
|
-
#
|
|
9
|
-
# status - HTTP status code. It is zero when a request fails due to network error.
|
|
10
|
-
# body - Parsed JSON object or response body.
|
|
11
|
-
# headers - HTTP response headers.
|
|
12
|
-
# error - Exception or Net::HTTPResponse object if the response is not Net::HTTPSuccess
|
|
13
|
-
#
|
|
14
|
-
# NOTE: Not supported yet by Ruby Next
|
|
15
|
-
# Response = Data.define(:status, :body, :headers, :error)
|
|
16
|
-
Response = Struct.new("Response", :status, :body, :headers, :error)
|
|
17
|
-
|
|
18
|
-
# Request module provides functionality to perform HTTP requests.
|
|
19
|
-
module Request
|
|
20
|
-
module ClassMethods
|
|
21
|
-
include Dry::Monads[:result]
|
|
22
|
-
|
|
23
|
-
# Execute an HTTP request and return a monad wrapping the response.
|
|
24
|
-
#
|
|
25
|
-
# method - The HTTP method to use (e.g. 'GET', 'POST'). Method must be a `Symbol`.
|
|
26
|
-
# url - The URL to send the request to.
|
|
27
|
-
# params - The query parameters or request body. Params needs to be in a form of a Hash.
|
|
28
|
-
# options - Additional options to pass to the request.
|
|
29
|
-
#
|
|
30
|
-
# A `Dry::Monads::Result` monad wrapping the response, either a success or failure.
|
|
31
|
-
# The response is a `Chroma::APIOperations::Response` Data object.
|
|
32
|
-
#
|
|
33
|
-
# Examples
|
|
34
|
-
#
|
|
35
|
-
# result = execute_request(:get, "https://example.com", {name: "test request"})
|
|
36
|
-
# if result.success?
|
|
37
|
-
# puts "Response status: #{result.success.status}"
|
|
38
|
-
# puts "Response body: #{result.success.body}"
|
|
39
|
-
# else
|
|
40
|
-
# puts "Request failed with error: #{result.failure.error}"
|
|
41
|
-
# end
|
|
42
|
-
def execute_request(method, url, params = {}, options = {})
|
|
43
|
-
uri = URI.parse(url)
|
|
44
|
-
|
|
45
|
-
request = build_request(method, uri, params)
|
|
46
|
-
|
|
47
|
-
use_ssl = uri.scheme == "https"
|
|
48
|
-
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
|
|
49
|
-
Chroma::Util.log_debug("Sending a request", {method: method, uri: uri, params: params})
|
|
50
|
-
http.request(request)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
build_response(response)
|
|
54
|
-
rescue => ex
|
|
55
|
-
build_response(ex)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
private def build_response(response)
|
|
59
|
-
case; when ((__m__ = response)) && false
|
|
60
|
-
when (((success_response,) = nil) || ((Net::HTTPSuccess === __m__) && ((success_response = __m__) || true)))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Chroma::Util.log_info("Successful response", code: success_response.code)
|
|
64
|
-
|
|
65
|
-
build_response_details(success_response)
|
|
66
|
-
when (((redirect_response,) = nil) || ((Net::HTTPRedirection === __m__) && ((redirect_response = __m__) || true)))
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Chroma::Util.log_info("Server redirect response", code: redirect_response.code, location: redirect_response["location"])
|
|
70
|
-
|
|
71
|
-
build_response_details(redirect_response)
|
|
72
|
-
when (((client_error_response,) = nil) || ((Net::HTTPClientError === __m__) && ((client_error_response = __m__) || true)))
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Chroma::Util.log_error("Client error response", code: client_error_response.code, body: client_error_response.body)
|
|
76
|
-
|
|
77
|
-
build_response_details(client_error_response)
|
|
78
|
-
when (((server_error_response,) = nil) || ((Net::HTTPServerError === __m__) && ((server_error_response = __m__) || true)))
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Chroma::Util.log_error("Server error response", code: server_error_response.code)
|
|
82
|
-
|
|
83
|
-
build_response_details(server_error_response, parse_body: false)
|
|
84
|
-
else
|
|
85
|
-
Chroma::Util.log_error("An error happened", error: response.to_s)
|
|
86
|
-
|
|
87
|
-
build_response_details(response, exception: true, parse_body: false)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
private def build_response_details(response, exception: false, parse_body: true)
|
|
92
|
-
response_data = Chroma::APIOperations::Response.new(
|
|
93
|
-
exception ? 0 : response.code.to_i,
|
|
94
|
-
if exception
|
|
95
|
-
exception.to_s
|
|
96
|
-
else
|
|
97
|
-
(parse_body ? body_to_json(response.body) : response.body)
|
|
98
|
-
end,
|
|
99
|
-
exception ? {} : response.each_header.to_h,
|
|
100
|
-
response.is_a?(Net::HTTPSuccess) ? nil : response
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
case; when ((__m__ = response)) && false
|
|
104
|
-
when (Net::HTTPSuccess === __m__)
|
|
105
|
-
return Success(response_data)
|
|
106
|
-
else
|
|
107
|
-
return Failure(response_data)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
private def body_to_json(content)
|
|
112
|
-
JSON.parse(content, symbolize_keys: true)
|
|
113
|
-
rescue JSON::ParserError, TypeError
|
|
114
|
-
content
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
private def build_request(method, uri, params)
|
|
118
|
-
request = case method
|
|
119
|
-
when :post then Net::HTTP::Post.new(uri)
|
|
120
|
-
when :put then Net::HTTP::Put.new(uri)
|
|
121
|
-
when :delete then Net::HTTP::Delete.new(uri)
|
|
122
|
-
else
|
|
123
|
-
Net::HTTP::Get.new(uri)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
request.content_type = "application/json"
|
|
127
|
-
request.body = params.to_json if params.size > 0
|
|
128
|
-
request.basic_auth(uri.user, uri.password) if !uri.user.nil?
|
|
129
|
-
|
|
130
|
-
request
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def self.included(base)
|
|
135
|
-
base.extend(ClassMethods)
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|