chromable 0.1.2 → 0.1.3
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/README.md +20 -6
- data/lib/chromable/version.rb +1 -1
- data/lib/chromable.rb +4 -4
- metadata +1 -1
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
@@ -4,11 +4,19 @@ Ruby on Rails integration for ChromaDB based on `chroma-db` gem.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
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
|
14
|
+
|
15
|
+
Then, install `chromable` and add to the application's Gemfile by executing:
|
8
16
|
|
9
17
|
$ bundle add chromable
|
10
18
|
|
11
|
-
|
19
|
+
Or, if you are not using bundler, install it by executing:
|
12
20
|
|
13
21
|
$ gem install chromable
|
14
22
|
|
@@ -24,19 +32,25 @@ Chroma.logger = Logger.new($stdout)
|
|
24
32
|
Chroma.log_level = Chroma::LEVEL_ERROR
|
25
33
|
```
|
26
34
|
|
27
|
-
Then,
|
35
|
+
Then, include `Chromable` module in your model and initialize it:
|
28
36
|
|
29
37
|
```ruby
|
30
|
-
|
38
|
+
class Post < ApplicationRecord
|
39
|
+
include Chromable
|
40
|
+
|
41
|
+
chromable document: :content, metadata: %i[author category], embedder: :embed
|
42
|
+
end
|
31
43
|
```
|
32
44
|
|
33
45
|
Where:
|
34
46
|
- `document:` is a callable represents the text content you want to embed and store in ChromaDB.
|
35
|
-
- `metadata:` is the list of attributes to be passed to ChromaDB as metadata.
|
36
|
-
- `embedder:` is
|
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.
|
37
49
|
|
38
50
|
Optionaly you can pass `collection_name:`. If not passed, the plural form of the model name will be used.
|
39
51
|
|
52
|
+
All `chromable` method arguments are optional.
|
53
|
+
|
40
54
|
To interact with the ChromaDB collection, `chromable` provides `Model.collection` method to retrieve the collection instance.
|
41
55
|
Also, `chromable` provides the following methods for each model instance:
|
42
56
|
|
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
|