chromable 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -12
- data/chromable.gemspec +2 -2
- data/lib/chromable/version.rb +1 -1
- data/lib/chromable.rb +4 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6d73bbad7320d850d166f26242c6dda3e66d953c8fce98ff6f7ccc442ba79be
|
4
|
+
data.tar.gz: 8d5c5bf8082c3736715f11c79d68d95781917e86c511e09a148293758d4bba4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c023701e1f6cf205af6d5fe8dfbf44f84904896c1cf8bb1937060d98f1f218c668524f02a75f60384ce109a26eb3c0a4a7394ab37c2a56c938dac33387572874
|
7
|
+
data.tar.gz: 5d75a9dc95ddefd0698d3544d9281a361ec16d89d49de3b93742f10f3a2798ac700da1c609a78bc2d6af31817ee798ffff8bfb28aa6d18b1793c871e07a84ef9
|
data/README.md
CHANGED
@@ -1,34 +1,74 @@
|
|
1
1
|
# Chromable
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/chromable`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
Ruby on Rails integration for ChromaDB based on `chroma-db` gem.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
Since `chromable` is depending on `chroma-db` gem, you will need to install it using:
|
8
|
+
|
9
|
+
$ bundle add chroma-db
|
10
|
+
|
11
|
+
Or, if you are not using bundler, install it by executing:
|
12
|
+
|
13
|
+
$ gem install chroma-db
|
10
14
|
|
11
|
-
|
15
|
+
Then, install `chromable` and add to the application's Gemfile by executing:
|
12
16
|
|
13
|
-
$ bundle add
|
17
|
+
$ bundle add chromable
|
14
18
|
|
15
|
-
|
19
|
+
Or, if you are not using bundler, install it by executing:
|
16
20
|
|
17
|
-
$ gem install
|
21
|
+
$ gem install chromable
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
25
|
+
`chromable` is depending on `chroma-db`, so you will need to initialize it in `config/initializers/chroma.rb`:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'chroma-db'
|
29
|
+
|
30
|
+
Chroma.connect_host = ENV.fetch('CHROMA_DB_URL', 'http://localhost:8000')
|
31
|
+
Chroma.logger = Logger.new($stdout)
|
32
|
+
Chroma.log_level = Chroma::LEVEL_ERROR
|
33
|
+
```
|
34
|
+
|
35
|
+
Then, include `Chromable` module in your model and initialize it:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Post < ApplicationRecord
|
39
|
+
include Chromable
|
40
|
+
|
41
|
+
chromable document: :content, metadata: %i[author category], embedder: :embed
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Where:
|
46
|
+
- `document:` is a callable represents the text content you want to embed and store in ChromaDB.
|
47
|
+
- `metadata:` is the list of attributes to be passed to ChromaDB as metadata to be used to filter.
|
48
|
+
- `embedder:` is a callable returns the embedding representation for the current instance.
|
49
|
+
|
50
|
+
Optionaly you can pass `collection_name:`. If not passed, the plural form of the model name will be used.
|
51
|
+
|
52
|
+
All `chromable` method arguments are optional.
|
53
|
+
|
54
|
+
To interact with the ChromaDB collection, `chromable` provides `Model.collection` method to retrieve the collection instance.
|
55
|
+
Also, `chromable` provides the following methods for each model instance:
|
56
|
+
|
57
|
+
- `embedding`: Retrieves the instance's ChromaDB embedding object.
|
58
|
+
- `upsert_embedding`: Creates or updates the instance's ChromaDB embedding object.
|
59
|
+
- `destroy_embedding`: Destroys the instance's ChromaDB embedding object.
|
60
|
+
|
61
|
+
All these methods (including `Model.collection`) are available with `chroma_` prefix, if you have similar methods defined in your model.
|
22
62
|
|
23
63
|
## Development
|
24
64
|
|
25
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
66
|
|
27
|
-
To install this gem onto your local machine, run `bundle
|
67
|
+
To install this gem onto your local machine, run `bundle install`. To release a new version, update the version number in `version.rb`, and then create a git tag for the version, push git commits and the created tag. The `Publish Gem` Github Action will push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
68
|
|
29
69
|
## Contributing
|
30
70
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/AliOsm/chromable. 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/[USERNAME]/chromable/blob/main/CODE_OF_CONDUCT.md).
|
32
72
|
|
33
73
|
## License
|
34
74
|
|
data/chromable.gemspec
CHANGED
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
33
|
spec.require_paths = ['lib']
|
34
34
|
|
35
|
-
spec.add_dependency 'activesupport', '
|
36
|
-
spec.add_dependency 'chroma-db', '
|
35
|
+
spec.add_dependency 'activesupport', '>= 6.1'
|
36
|
+
spec.add_dependency 'chroma-db', '>= 0.6.0'
|
37
37
|
|
38
38
|
# For more information and examples about making a new gem, check out our
|
39
39
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/lib/chromable/version.rb
CHANGED
data/lib/chromable.rb
CHANGED
@@ -19,7 +19,7 @@ module Chromable
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class_methods do
|
22
|
-
def chromable(document
|
22
|
+
def chromable(collection_name: nil, document: nil, metadata: nil, embedder: nil)
|
23
23
|
self.collection_name = (collection_name.presence || name.underscore.pluralize)
|
24
24
|
self.document = document
|
25
25
|
self.metadata = metadata
|
@@ -41,9 +41,9 @@ module Chromable
|
|
41
41
|
self.class.chroma_collection.upsert(
|
42
42
|
Chroma::Resources::Embedding.new(
|
43
43
|
id: id,
|
44
|
-
document: send(self.class.document),
|
45
|
-
embedding: send(self.class.embedder),
|
46
|
-
metadata: self.class.metadata.index_with { |attribute| send(attribute) }
|
44
|
+
document: self.class.document ? send(self.class.document) : nil,
|
45
|
+
embedding: self.class.embedder ? send(self.class.embedder) : nil,
|
46
|
+
metadata: self.class.metadata ? self.class.metadata.index_with { |attribute| send(attribute) } : nil
|
47
47
|
)
|
48
48
|
)
|
49
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chromable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ali Hamdi Ali Fadel
|
@@ -14,28 +14,28 @@ dependencies:
|
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '6.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: chroma-db
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.6.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.6.0
|
41
41
|
description:
|