chromable 0.1.2 → 0.1.4

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: 5b0b02fff83da824d9195113352c1d68dfaaa06bde568eba6448fb4cb79e0919
4
+ data.tar.gz: 879ac8e61ba6be8a9490174f13517c509409c0d271fd93e9fd06d6a22cf3f1fe
5
5
  SHA512:
6
- metadata.gz: e281b9fd661de160e7c4c27a0333f7db04b57971a87cba74b8aaa4ff2eb1d5e12f4cb7683692b6ad26e8f048cb2e78ace7113e16f07c420fb3962e2259f3b8db
7
- data.tar.gz: 73531acad9fecd1eea5da410e3191994bea0a7ff149da71f1f630b0c3770b8594af900c4efd86d64f0db02be2d8193d07d8c31f60790ae92233b578fc2595933
6
+ metadata.gz: a5a97a3c29f46ee311eafa1d2ea9d51d032568a2bafa64877d22590403152b623318a93d650328af3db1db005e5315b4a90002185a9bfa0c328fcb81dd374276
7
+ data.tar.gz: cc14d192452c5e4f72ee090f5423c7b78afe1449e1cd1b25009fcb7d4db29394fe50a2093e107c438f9d4b0d60a46ff8f3230f4a6fd9a1aab5f5b33cdc99798e
data/README.md CHANGED
@@ -4,11 +4,11 @@ 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
+ Install `chromable` and add it to the application's Gemfile by executing:
8
8
 
9
9
  $ bundle add chromable
10
10
 
11
- If bundler is not being used to manage dependencies, install the gem by executing:
11
+ Or, if bundler is not being used to manage dependencies, install `chromable` by executing:
12
12
 
13
13
  $ gem install chromable
14
14
 
@@ -24,19 +24,31 @@ Chroma.logger = Logger.new($stdout)
24
24
  Chroma.log_level = Chroma::LEVEL_ERROR
25
25
  ```
26
26
 
27
- Then, add the following line to your Rails model:
27
+ Then, include `Chromable` module in your model and initialize it:
28
28
 
29
29
  ```ruby
30
- chromable document: :content, metadata: %i[author category], embedder: :embed
30
+ class Post < ApplicationRecord
31
+ include Chromable
32
+
33
+ chromable document: :content, metadata: %i[author category], embedder: :embed
34
+
35
+ def embed
36
+ # Call OpenAI now please :)
37
+ end
38
+ end
31
39
  ```
32
40
 
33
41
  Where:
34
42
  - `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.
43
+ - `metadata:` is the list of attributes to be passed to ChromaDB as metadata to be used to filter.
44
+ - `embedder:` is a callable returns the embedding representation for the current instance.
37
45
 
38
46
  Optionaly you can pass `collection_name:`. If not passed, the plural form of the model name will be used.
39
47
 
48
+ All `chromable` method arguments are optional.
49
+
50
+ At this point, `chromable` will create, update, and destroy the ChromaDB embeddings for your objects based on Rails callbacks.
51
+
40
52
  To interact with the ChromaDB collection, `chromable` provides `Model.collection` method to retrieve the collection instance.
41
53
  Also, `chromable` provides the following methods for each model instance:
42
54
 
@@ -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.4'
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
@@ -53,6 +53,6 @@ module Chromable
53
53
  end
54
54
 
55
55
  alias embedding chroma_embedding unless method_defined? :embedding
56
- alias upsert_embedding chroma_embedding unless method_defined? :upsert_embedding
57
- alias destroy_embedding chroma_embedding unless method_defined? :destroy_embedding
56
+ alias upsert_embedding chroma_upsert_embedding unless method_defined? :upsert_embedding
57
+ alias destroy_embedding chroma_destroy_embedding unless method_defined? :destroy_embedding
58
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Hamdi Ali Fadel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2023-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport