chromable 0.1.2 → 0.1.3

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: 5695e34925255a187cf2cdca8337c8cb408e688b905984f28af08f43a12b8ffc
4
- data.tar.gz: 5cbb179745647c0fd4fb982a4890570f6dbdf7e9d269f3af6b468949829cf83b
3
+ metadata.gz: a6d73bbad7320d850d166f26242c6dda3e66d953c8fce98ff6f7ccc442ba79be
4
+ data.tar.gz: 8d5c5bf8082c3736715f11c79d68d95781917e86c511e09a148293758d4bba4d
5
5
  SHA512:
6
- metadata.gz: e281b9fd661de160e7c4c27a0333f7db04b57971a87cba74b8aaa4ff2eb1d5e12f4cb7683692b6ad26e8f048cb2e78ace7113e16f07c420fb3962e2259f3b8db
7
- data.tar.gz: 73531acad9fecd1eea5da410e3191994bea0a7ff149da71f1f630b0c3770b8594af900c4efd86d64f0db02be2d8193d07d8c31f60790ae92233b578fc2595933
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
- Install the gem and add to the application's Gemfile by executing:
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
- If bundler is not being used to manage dependencies, install the gem by executing:
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, add the following line to your Rails model:
35
+ Then, include `Chromable` module in your model and initialize it:
28
36
 
29
37
  ```ruby
30
- chromable document: :content, metadata: %i[author category], embedder: :embed
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 the method that returns the embedding representation for the current instance.
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chromable
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
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:, metadata:, embedder:, collection_name: nil)
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Hamdi Ali Fadel