Class: LangchainrbRails::Generators::PgvectorGenerator
- Inherits:
-
BaseGenerator
- Object
- Rails::Generators::Base
- BaseGenerator
- LangchainrbRails::Generators::PgvectorGenerator
show all
- Defined in:
- lib/langchainrb_rails/generators/langchainrb_rails/pgvector_generator.rb
Overview
Usage:
rails generate langchainrb_rails:pgvector --model=Product --llm=openai
Constant Summary
BaseGenerator::LLMS
Instance Method Summary
collapse
#after_generate, #post_install_message
Instance Method Details
#add_to_gemfile ⇒ Object
32
33
34
35
36
|
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pgvector_generator.rb', line 32
def add_to_gemfile
gem "neighbor"
gem "ruby-openai"
end
|
#add_to_model ⇒ Object
26
27
28
29
30
|
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pgvector_generator.rb', line 26
def add_to_model
inject_into_class "app/models/#{model_name.underscore}.rb", model_name do
" vectorsearch\n\n after_save :upsert_to_vectorsearch\n\n"
end
end
|
#copy_migration ⇒ Object
13
14
15
16
|
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pgvector_generator.rb', line 13
def copy_migration
migration_template "enable_vector_extension_template.rb", "db/migrate/enable_vector_extension.rb", migration_version: migration_version
migration_template "add_vector_column_template.rb", "db/migrate/add_vector_column_to_#{table_name}.rb", migration_version: migration_version
end
|
#create_initializer_file ⇒ Object
18
19
20
|
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pgvector_generator.rb', line 18
def create_initializer_file
template "pgvector_initializer.rb", "config/initializers/langchainrb_rails.rb"
end
|
#migration_version ⇒ Object
22
23
24
|
# File 'lib/langchainrb_rails/generators/langchainrb_rails/pgvector_generator.rb', line 22
def migration_version
"[#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}]"
end
|