langchainrb_rails 0.1.3 → 0.1.5

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: 37760a671cfe732f12ddb79769997ae325240b5c1b0bb96ee3e13786d605cc6a
4
- data.tar.gz: 89b9aa5c04ffb28823836cfef7428990e27e1d38dc231240fb4e7004ab3db614
3
+ metadata.gz: 6bb3982f419d252f6e94018548685566d9775993ad6349957211a4d686e9a10c
4
+ data.tar.gz: 783c3d1683d654903f745aa6b1fd973787b03581792a1292a0d5724c6983eda8
5
5
  SHA512:
6
- metadata.gz: 78c3d36d67ace05932ef36bc9e9136837bb350e5698aad55836f3d6dea0602228f461f2ae1aafc10ec050151d7f6b71e5a7cca21357b1a5f6bf2410f38596a69
7
- data.tar.gz: fa5a1bdd97e82d71f9b4b35d0c1f15245c87966cdef60117364174f8306a7df72848dda3b52e2635844a5ae05d25a9e1c6166bf7a25b9ccd52565ae787c8fc86
6
+ metadata.gz: f1fe4ad36c5c12c7260cff5bf29046330d2e649a0f8d96707b13831f09c2c185cf88c5a202f3621eb03cb87fae1df6f7bb75a6bdac5cd9471a4e4637daaafa5f
7
+ data.tar.gz: f0effcbf9679194a32ece6ff84cc26cf0c5cea5956c9a51ee1a33ba3e32bf4ea56807bba9a463b9edc227d1cb572508bfad70e3a1e8063c5f374e12e1e97d834
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.5] - 2023-11-30
4
+ - Qdrant vectorsearch generator
5
+
6
+ ## [0.1.4] - 2023-11-20
7
+ - Bugfix AR integration when using vectorsearch other than Pgvector
8
+
3
9
  ## [0.1.3] - 2023-11-01
4
10
  - Pgvector vectorsearch generator
5
11
 
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in langchainrb_rails.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake", "~> 13.1"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
data/Gemfile.lock CHANGED
@@ -1,76 +1,77 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- langchainrb_rails (0.1.3)
4
+ langchainrb_rails (0.1.5)
5
5
  langchainrb (~> 0.7.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (7.1.1)
11
- actionpack (= 7.1.1)
12
- activesupport (= 7.1.1)
10
+ actioncable (7.1.2)
11
+ actionpack (= 7.1.2)
12
+ activesupport (= 7.1.2)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
15
  zeitwerk (~> 2.6)
16
- actionmailbox (7.1.1)
17
- actionpack (= 7.1.1)
18
- activejob (= 7.1.1)
19
- activerecord (= 7.1.1)
20
- activestorage (= 7.1.1)
21
- activesupport (= 7.1.1)
16
+ actionmailbox (7.1.2)
17
+ actionpack (= 7.1.2)
18
+ activejob (= 7.1.2)
19
+ activerecord (= 7.1.2)
20
+ activestorage (= 7.1.2)
21
+ activesupport (= 7.1.2)
22
22
  mail (>= 2.7.1)
23
23
  net-imap
24
24
  net-pop
25
25
  net-smtp
26
- actionmailer (7.1.1)
27
- actionpack (= 7.1.1)
28
- actionview (= 7.1.1)
29
- activejob (= 7.1.1)
30
- activesupport (= 7.1.1)
26
+ actionmailer (7.1.2)
27
+ actionpack (= 7.1.2)
28
+ actionview (= 7.1.2)
29
+ activejob (= 7.1.2)
30
+ activesupport (= 7.1.2)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  net-imap
33
33
  net-pop
34
34
  net-smtp
35
35
  rails-dom-testing (~> 2.2)
36
- actionpack (7.1.1)
37
- actionview (= 7.1.1)
38
- activesupport (= 7.1.1)
36
+ actionpack (7.1.2)
37
+ actionview (= 7.1.2)
38
+ activesupport (= 7.1.2)
39
39
  nokogiri (>= 1.8.5)
40
+ racc
40
41
  rack (>= 2.2.4)
41
42
  rack-session (>= 1.0.1)
42
43
  rack-test (>= 0.6.3)
43
44
  rails-dom-testing (~> 2.2)
44
45
  rails-html-sanitizer (~> 1.6)
45
- actiontext (7.1.1)
46
- actionpack (= 7.1.1)
47
- activerecord (= 7.1.1)
48
- activestorage (= 7.1.1)
49
- activesupport (= 7.1.1)
46
+ actiontext (7.1.2)
47
+ actionpack (= 7.1.2)
48
+ activerecord (= 7.1.2)
49
+ activestorage (= 7.1.2)
50
+ activesupport (= 7.1.2)
50
51
  globalid (>= 0.6.0)
51
52
  nokogiri (>= 1.8.5)
52
- actionview (7.1.1)
53
- activesupport (= 7.1.1)
53
+ actionview (7.1.2)
54
+ activesupport (= 7.1.2)
54
55
  builder (~> 3.1)
55
56
  erubi (~> 1.11)
56
57
  rails-dom-testing (~> 2.2)
57
58
  rails-html-sanitizer (~> 1.6)
58
- activejob (7.1.1)
59
- activesupport (= 7.1.1)
59
+ activejob (7.1.2)
60
+ activesupport (= 7.1.2)
60
61
  globalid (>= 0.3.6)
61
- activemodel (7.1.1)
62
- activesupport (= 7.1.1)
63
- activerecord (7.1.1)
64
- activemodel (= 7.1.1)
65
- activesupport (= 7.1.1)
62
+ activemodel (7.1.2)
63
+ activesupport (= 7.1.2)
64
+ activerecord (7.1.2)
65
+ activemodel (= 7.1.2)
66
+ activesupport (= 7.1.2)
66
67
  timeout (>= 0.4.0)
67
- activestorage (7.1.1)
68
- actionpack (= 7.1.1)
69
- activejob (= 7.1.1)
70
- activerecord (= 7.1.1)
71
- activesupport (= 7.1.1)
68
+ activestorage (7.1.2)
69
+ actionpack (= 7.1.2)
70
+ activejob (= 7.1.2)
71
+ activerecord (= 7.1.2)
72
+ activesupport (= 7.1.2)
72
73
  marcel (~> 1.0)
73
- activesupport (7.1.1)
74
+ activesupport (7.1.2)
74
75
  base64
75
76
  bigdecimal
76
77
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -83,8 +84,8 @@ GEM
83
84
  addressable (2.8.5)
84
85
  public_suffix (>= 2.0.2, < 6.0)
85
86
  ast (2.4.2)
86
- baran (0.1.9)
87
- base64 (0.1.1)
87
+ baran (0.1.10)
88
+ base64 (0.2.0)
88
89
  bigdecimal (3.1.4)
89
90
  brakeman (6.0.1)
90
91
  builder (3.2.4)
@@ -97,9 +98,9 @@ GEM
97
98
  concurrent-ruby (1.2.2)
98
99
  connection_pool (2.4.1)
99
100
  crass (1.0.6)
100
- date (3.3.3)
101
+ date (3.3.4)
101
102
  diff-lcs (1.5.0)
102
- drb (2.1.1)
103
+ drb (2.2.0)
103
104
  ruby2_keywords
104
105
  erubi (1.12.0)
105
106
  globalid (1.2.1)
@@ -107,13 +108,13 @@ GEM
107
108
  i18n (1.14.1)
108
109
  concurrent-ruby (~> 1.0)
109
110
  io-console (0.6.0)
110
- irb (1.8.3)
111
+ irb (1.9.0)
111
112
  rdoc
112
113
  reline (>= 0.3.8)
113
114
  json (2.6.3)
114
115
  json-schema (4.0.0)
115
116
  addressable (>= 2.8)
116
- langchainrb (0.7.1)
117
+ langchainrb (0.7.5)
117
118
  baran (~> 0.1.9)
118
119
  colorize (~> 0.8.1)
119
120
  json-schema (~> 4.0.0)
@@ -138,13 +139,13 @@ GEM
138
139
  mini_mime (1.1.5)
139
140
  mini_portile2 (2.8.5)
140
141
  minitest (5.20.0)
141
- mutex_m (0.1.2)
142
- net-imap (0.4.2)
142
+ mutex_m (0.2.0)
143
+ net-imap (0.4.4)
143
144
  date
144
145
  net-protocol
145
146
  net-pop (0.1.2)
146
147
  net-protocol
147
- net-protocol (0.2.1)
148
+ net-protocol (0.2.2)
148
149
  timeout
149
150
  net-smtp (0.4.0)
150
151
  net-protocol
@@ -170,8 +171,8 @@ GEM
170
171
  pry (>= 0.13, < 0.15)
171
172
  psych (5.1.1.1)
172
173
  stringio
173
- public_suffix (5.0.3)
174
- racc (1.7.1)
174
+ public_suffix (5.0.4)
175
+ racc (1.7.3)
175
176
  rack (3.0.8)
176
177
  rack-session (2.0.0)
177
178
  rack (>= 3.0.0)
@@ -180,20 +181,20 @@ GEM
180
181
  rackup (2.1.0)
181
182
  rack (>= 3)
182
183
  webrick (~> 1.8)
183
- rails (7.1.1)
184
- actioncable (= 7.1.1)
185
- actionmailbox (= 7.1.1)
186
- actionmailer (= 7.1.1)
187
- actionpack (= 7.1.1)
188
- actiontext (= 7.1.1)
189
- actionview (= 7.1.1)
190
- activejob (= 7.1.1)
191
- activemodel (= 7.1.1)
192
- activerecord (= 7.1.1)
193
- activestorage (= 7.1.1)
194
- activesupport (= 7.1.1)
184
+ rails (7.1.2)
185
+ actioncable (= 7.1.2)
186
+ actionmailbox (= 7.1.2)
187
+ actionmailer (= 7.1.2)
188
+ actionpack (= 7.1.2)
189
+ actiontext (= 7.1.2)
190
+ actionview (= 7.1.2)
191
+ activejob (= 7.1.2)
192
+ activemodel (= 7.1.2)
193
+ activerecord (= 7.1.2)
194
+ activestorage (= 7.1.2)
195
+ activesupport (= 7.1.2)
195
196
  bundler (>= 1.15.0)
196
- railties (= 7.1.1)
197
+ railties (= 7.1.2)
197
198
  rails-dom-testing (2.2.0)
198
199
  activesupport (>= 5.0.0)
199
200
  minitest
@@ -201,21 +202,21 @@ GEM
201
202
  rails-html-sanitizer (1.6.0)
202
203
  loofah (~> 2.21)
203
204
  nokogiri (~> 1.14)
204
- railties (7.1.1)
205
- actionpack (= 7.1.1)
206
- activesupport (= 7.1.1)
205
+ railties (7.1.2)
206
+ actionpack (= 7.1.2)
207
+ activesupport (= 7.1.2)
207
208
  irb
208
209
  rackup (>= 1.0.0)
209
210
  rake (>= 12.2)
210
211
  thor (~> 1.0, >= 1.2.2)
211
212
  zeitwerk (~> 2.6)
212
213
  rainbow (3.1.1)
213
- rake (13.0.6)
214
- rb_sys (0.9.82)
215
- rdoc (6.5.0)
214
+ rake (13.1.0)
215
+ rb_sys (0.9.83)
216
+ rdoc (6.6.0)
216
217
  psych (>= 4.0.0)
217
218
  regexp_parser (2.8.2)
218
- reline (0.3.9)
219
+ reline (0.4.0)
219
220
  io-console (~> 0.5)
220
221
  rexml (3.2.6)
221
222
  rspec (3.12.0)
@@ -231,29 +232,28 @@ GEM
231
232
  diff-lcs (>= 1.2.0, < 2.0)
232
233
  rspec-support (~> 3.12.0)
233
234
  rspec-support (3.12.1)
234
- rubocop (1.56.4)
235
- base64 (~> 0.1.1)
235
+ rubocop (1.57.2)
236
236
  json (~> 2.3)
237
237
  language_server-protocol (>= 3.17.0)
238
238
  parallel (~> 1.10)
239
- parser (>= 3.2.2.3)
239
+ parser (>= 3.2.2.4)
240
240
  rainbow (>= 2.2.2, < 4.0)
241
241
  regexp_parser (>= 1.8, < 3.0)
242
242
  rexml (>= 3.2.5, < 4.0)
243
243
  rubocop-ast (>= 1.28.1, < 2.0)
244
244
  ruby-progressbar (~> 1.7)
245
245
  unicode-display_width (>= 2.4.0, < 3.0)
246
- rubocop-ast (1.29.0)
246
+ rubocop-ast (1.30.0)
247
247
  parser (>= 3.2.1.0)
248
248
  rubocop-performance (1.19.1)
249
249
  rubocop (>= 1.7.0, < 2.0)
250
250
  rubocop-ast (>= 0.4.0)
251
251
  ruby-progressbar (1.13.0)
252
252
  ruby2_keywords (0.0.5)
253
- standard (1.31.2)
253
+ standard (1.32.0)
254
254
  language_server-protocol (~> 3.17.0.2)
255
255
  lint_roller (~> 1.0)
256
- rubocop (~> 1.56.4)
256
+ rubocop (~> 1.57.2)
257
257
  standard-custom (~> 1.0.0)
258
258
  standard-performance (~> 1.2)
259
259
  standard-custom (1.0.2)
@@ -264,13 +264,13 @@ GEM
264
264
  rubocop-performance (~> 1.19.1)
265
265
  standardrb (1.0.1)
266
266
  standard
267
- stringio (3.0.8)
267
+ stringio (3.0.9)
268
268
  thor (1.3.0)
269
269
  tiktoken_ruby (0.0.6)
270
270
  rb_sys (~> 0.9.68)
271
271
  tiktoken_ruby (0.0.6-x86_64-darwin)
272
272
  tiktoken_ruby (0.0.6-x86_64-linux)
273
- timeout (0.4.0)
273
+ timeout (0.4.1)
274
274
  to_bool (2.0.0)
275
275
  tzinfo (2.0.6)
276
276
  concurrent-ruby (~> 1.0)
@@ -296,7 +296,7 @@ DEPENDENCIES
296
296
  langchainrb_rails!
297
297
  pry-byebug (~> 3.10.0)
298
298
  rails (> 6.0.0)
299
- rake (~> 13.0)
299
+ rake (~> 13.1)
300
300
  rspec (~> 3.0)
301
301
  rubocop
302
302
  standardrb
data/README.md CHANGED
@@ -2,11 +2,14 @@
2
2
  ---
3
3
  The fastest way to sprinkle AI ✨ on top of your Rails app. Add OpenAI-powered question-and-answering in minutes.
4
4
 
5
+ Available for paid consulting engagements! [Email me](mailto:andrei@sourcelabs.io).
6
+
5
7
  ![Tests status](https://github.com/andreibondarev/langchainrb_rails/actions/workflows/ci.yml/badge.svg?branch=main)
6
8
  [![Gem Version](https://badge.fury.io/rb/langchainrb_rails.svg)](https://badge.fury.io/rb/langchainrb_rails)
7
9
  [![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/langchainrb_rails)
8
10
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/andreibondarev/langchainrb_rails/blob/main/LICENSE.txt)
9
11
  [![](https://dcbadge.vercel.app/api/server/WDARp7J2n8?compact=true&style=flat)](https://discord.gg/WDARp7J2n8)
12
+ [![X](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Follow%20%40rushing_andrei)](https://twitter.com/rushing_andrei)
10
13
 
11
14
  ## Dependencies
12
15
 
@@ -96,7 +99,7 @@ end
96
99
  Re-generate embeddings after modifying this method:
97
100
 
98
101
  ```ruby
99
- product.embed!
102
+ Product.embed!
100
103
  ```
101
104
 
102
105
  ## Rails Generators
@@ -112,6 +115,11 @@ rails generate langchainrb_rails:pgvector --model=Product --llm=openai
112
115
  rails generate langchainrb_rails:pinecone --model=Product --llm=openai
113
116
  ```
114
117
 
118
+ ### Qdrant Generator - adds vectorsearch to your ActiveRecord model
119
+ ```bash
120
+ rails generate langchainrb_rails:qdrant --model=Product --llm=openai
121
+ ```
122
+
115
123
  Available `--llm` options: `cohere`, `google_palm`, `hugging_face`, `llama_cpp`, `ollama`, `openai`, and `replicate`. The selected LLM will be used to generate embeddings and completions.
116
124
 
117
125
  The `--model` option is used to specify which ActiveRecord model vectorsearch capabilities will be added to.
@@ -76,9 +76,8 @@ module LangchainrbRails
76
76
  # Pgvector-specific configuration
77
77
  if LangchainrbRails.config.vectorsearch.is_a?(Langchain::Vectorsearch::Pgvector)
78
78
  has_neighbors(:embedding)
79
+ LangchainrbRails.config.vectorsearch.model = self
79
80
  end
80
-
81
- LangchainrbRails.config.vectorsearch.model = self
82
81
  end
83
82
 
84
83
  # Iterates over records and generate embeddings.
@@ -113,7 +112,7 @@ module LangchainrbRails
113
112
  # @return [String] The answer to the question
114
113
  def ask(question, k: 4, &block)
115
114
  class_variable_get(:@@provider).ask(
116
- question,
115
+ question: question,
117
116
  k: k,
118
117
  &block
119
118
  ).completion
@@ -4,7 +4,7 @@ module LangchainrbRails
4
4
  module Generators
5
5
  #
6
6
  # Usage:
7
- # rails g langchain:pgvector -model=Product -llm=openai
7
+ # rails generate langchainrb_rails:pgvector --model=Product --llm=openai
8
8
  #
9
9
  class PgvectorGenerator < LangchainrbRails::Generators::BaseGenerator
10
10
  desc "This generator adds Pgvector vectorsearch integration to your ActiveRecord model"
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LangchainrbRails
4
+ module Generators
5
+ #
6
+ # PineconeGenerator does the following:
7
+ # 1. Creates the `langchainrb_rails.rb` initializer file
8
+ # 2. Adds necessary code to the ActiveRecord model to enable vectorsearch
9
+ # 3. Adds `qdrant-ruby` gem to the Gemfile
10
+ #
11
+ # Usage:
12
+ # rails generate langchainrb_rails:qdrant --model=Product --llm=openai
13
+ #
14
+ class QdrantGenerator < LangchainrbRails::Generators::BaseGenerator
15
+ desc "This generator adds Qdrant vectorsearch integration to your ActiveRecord model"
16
+ source_root File.join(__dir__, "templates")
17
+
18
+ # Creates the `langchainrb_rails.rb` initializer file
19
+ def create_initializer_file
20
+ template "qdrant_initializer.rb", "config/initializers/langchainrb_rails.rb"
21
+ end
22
+
23
+ # Adds `vectorsearch` class method to the model and `after_save` callback that calls `upsert_to_vectorsearch()`
24
+ def add_to_model
25
+ inject_into_class "app/models/#{model_name.downcase}.rb", model_name do
26
+ " vectorsearch\n\n after_save :upsert_to_vectorsearch\n\n"
27
+ end
28
+ end
29
+
30
+ # Adds `qdrant-ruby` gem to the Gemfile
31
+ # TODO: Can we automatically run `bundle install`?
32
+ def add_to_gemfile
33
+ gem "qdrant-ruby"
34
+ end
35
+
36
+ private
37
+
38
+ # @return [String] Name of the model
39
+ def model_name
40
+ options["model"]
41
+ end
42
+
43
+ # @return [String] LLM provider to use
44
+ def llm
45
+ options["llm"]
46
+ end
47
+
48
+ # @return [Langchain::LLM::*] LLM class
49
+ def llm_class
50
+ Langchain::LLM.const_get(LLMS[llm])
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ LangchainrbRails.configure do |config|
4
+ config.vectorsearch = Langchain::Vectorsearch::Qdrant.new(
5
+ llm: <%= llm_class %>.new(api_key: ENV["<%= llm.upcase %>_API_KEY"]),
6
+ url: ENV["QDRANT_URL"],
7
+ api_key: ENV["QDRANT_API_KEY"],
8
+ index_name: ""
9
+ )
10
+ end
@@ -12,6 +12,7 @@ module LangchainrbRails
12
12
  require_relative "generators/langchainrb_rails/chroma_generator"
13
13
  require_relative "generators/langchainrb_rails/pinecone_generator"
14
14
  require_relative "generators/langchainrb_rails/pgvector_generator"
15
+ require_relative "generators/langchainrb_rails/qdrant_generator"
15
16
  end
16
17
  end
17
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LangchainrbRails
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -19,6 +19,7 @@ module LangchainrbRails
19
19
  autoload :BaseGenerator, "langchainrb_rails/generators/langchainrb_rails/base_generator"
20
20
  autoload :ChromaGenerator, "langchainrb_rails/generators/langchainrb_rails/chroma_generator"
21
21
  autoload :PgvectorGenerator, "langchainrb_rails/generators/langchainrb_rails/pgvector_generator"
22
+ autoload :QdrantGenerator, "langchainrb_rails/generators/langchainrb_rails/qdrant_generator"
22
23
  end
23
24
 
24
25
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langchainrb_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-01 00:00:00.000000000 Z
11
+ date: 2023-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: langchainrb
@@ -90,11 +90,13 @@ files:
90
90
  - lib/langchainrb_rails/generators/langchainrb_rails/chroma_generator.rb
91
91
  - lib/langchainrb_rails/generators/langchainrb_rails/pgvector_generator.rb
92
92
  - lib/langchainrb_rails/generators/langchainrb_rails/pinecone_generator.rb
93
+ - lib/langchainrb_rails/generators/langchainrb_rails/qdrant_generator.rb
93
94
  - lib/langchainrb_rails/generators/langchainrb_rails/templates/add_vector_column_template.rb.tt
94
95
  - lib/langchainrb_rails/generators/langchainrb_rails/templates/chroma_initializer.rb.tt
95
96
  - lib/langchainrb_rails/generators/langchainrb_rails/templates/enable_vector_extension_template.rb.tt
96
97
  - lib/langchainrb_rails/generators/langchainrb_rails/templates/pgvector_initializer.rb.tt
97
98
  - lib/langchainrb_rails/generators/langchainrb_rails/templates/pinecone_initializer.rb.tt
99
+ - lib/langchainrb_rails/generators/langchainrb_rails/templates/qdrant_initializer.rb.tt
98
100
  - lib/langchainrb_rails/railtie.rb
99
101
  - lib/langchainrb_rails/version.rb
100
102
  - sig/langchainrb_rails.rbs