langchainrb_rails 0.1.4 → 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: 54ab2d33d89929b9222202d42cc5616aac73ca65fa81c3e4f2bc3d516a3a05c6
4
- data.tar.gz: 4ce553994a4219904875168369ab598de11162db2cd6810d202af005acb10638
3
+ metadata.gz: 6bb3982f419d252f6e94018548685566d9775993ad6349957211a4d686e9a10c
4
+ data.tar.gz: 783c3d1683d654903f745aa6b1fd973787b03581792a1292a0d5724c6983eda8
5
5
  SHA512:
6
- metadata.gz: bd93a8976a54120bcec4f8c10ff5bfc5c36d8bccd9f172b071a7732d675ade00ddc3021f93ecb080f508728fdb06b45e5c086933b0bd5522dd094b08d9334d93
7
- data.tar.gz: 0fd5d062e69a441c50c4963749e31c6773f38ba3e063d21574983b5fd4579c495c3e1b95d340540754c8f89b110c4e1f6ea3f0399265bcf315a0d26f5b6b8e36
6
+ metadata.gz: f1fe4ad36c5c12c7260cff5bf29046330d2e649a0f8d96707b13831f09c2c185cf88c5a202f3621eb03cb87fae1df6f7bb75a6bdac5cd9471a4e4637daaafa5f
7
+ data.tar.gz: f0effcbf9679194a32ece6ff84cc26cf0c5cea5956c9a51ee1a33ba3e32bf4ea56807bba9a463b9edc227d1cb572508bfad70e3a1e8063c5f374e12e1e97d834
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.5] - 2023-11-30
4
+ - Qdrant vectorsearch generator
5
+
3
6
  ## [0.1.4] - 2023-11-20
4
7
  - Bugfix AR integration when using vectorsearch other than Pgvector
5
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- langchainrb_rails (0.1.4)
4
+ langchainrb_rails (0.1.5)
5
5
  langchainrb (~> 0.7.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -115,6 +115,11 @@ rails generate langchainrb_rails:pgvector --model=Product --llm=openai
115
115
  rails generate langchainrb_rails:pinecone --model=Product --llm=openai
116
116
  ```
117
117
 
118
+ ### Qdrant Generator - adds vectorsearch to your ActiveRecord model
119
+ ```bash
120
+ rails generate langchainrb_rails:qdrant --model=Product --llm=openai
121
+ ```
122
+
118
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.
119
124
 
120
125
  The `--model` option is used to specify which ActiveRecord model vectorsearch capabilities will be added to.
@@ -112,7 +112,7 @@ module LangchainrbRails
112
112
  # @return [String] The answer to the question
113
113
  def ask(question, k: 4, &block)
114
114
  class_variable_get(:@@provider).ask(
115
- question,
115
+ question: question,
116
116
  k: k,
117
117
  &block
118
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.4"
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.4
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-20 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