Class: LangchainrbRails::Generators::PineconeGenerator

Inherits:
BaseGenerator
  • Object
show all
Defined in:
lib/langchainrb_rails/generators/langchainrb_rails/pinecone_generator.rb

Overview

PineconeGenerator does the following:

  1. Creates the ‘langchainrb_rails.rb` initializer file

  2. Adds necessary code to the ActiveRecord model to enable vectorsearch

  3. Adds ‘pinecone` gem to the Gemfile

Usage:

rails generate langchainrb_rails:pinecone --model=Product --llm=openai

Constant Summary

Constants inherited from BaseGenerator

BaseGenerator::LLMS

Instance Method Summary collapse

Methods inherited from BaseGenerator

#after_generate, #post_install_message

Instance Method Details

#add_to_gemfileObject

Adds ‘pinecone` gem to the Gemfile



31
32
33
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pinecone_generator.rb', line 31

def add_to_gemfile
  gem "pinecone"
end

#add_to_modelObject

Adds ‘vectorsearch` class method to the model and `after_save` callback that calls `upsert_to_vectorsearch()`



24
25
26
27
28
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pinecone_generator.rb', line 24

def add_to_model
  inject_into_class "app/models/#{model_name.downcase}.rb", model_name do
    "  vectorsearch\n\n  after_save :upsert_to_vectorsearch\n\n"
  end
end

#create_initializer_fileObject

Creates the ‘langchainrb_rails.rb` initializer file



19
20
21
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pinecone_generator.rb', line 19

def create_initializer_file
  template "pinecone_initializer.rb", "config/initializers/langchainrb_rails.rb"
end