### Bundle Install and Migrate Database Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Runs Bundler to install newly added gems and executes database migrations. This step is necessary after adding gem dependencies and creating migration files. ```bash bundle install && rails db:migrate ``` -------------------------------- ### Install Langchainrb Rails Gem with Bundler Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Installs the langchainrb_rails gem into your Rails application using Bundler, adding it to the Gemfile. This is the recommended installation method when using Bundler. ```bash bundle add langchainrb_rails ``` -------------------------------- ### Install Langchainrb Rails Gem via Gem Command Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Installs the langchainrb_rails gem directly using the gem command. Use this method if you are not managing dependencies with Bundler. ```bash gem install langchainrb_rails ``` -------------------------------- ### Use Prompt Model for Rendering Templates Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Demonstrates how to create a Prompt record with a template and render it by passing a hash of variables. This allows dynamic prompt generation. ```ruby prompt = Prompt.create!(template: "Tell me a {adjective} joke about {subject}.") prompt.render(adjective: "funny", subject: "elephants") # => "Tell me a funny joke about elephants." ``` -------------------------------- ### Run Qdrant Generator for ActiveRecord Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Executes the Rails generator to configure an ActiveRecord model for vector search using Qdrant. It adds dependencies, creates an initializer, and modifies the model. ```bash rails generate langchainrb_rails:qdrant --model=Product --llm=openai ``` -------------------------------- ### Run Prompt Generator for Prompt Templating Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Executes the Rails generator to add prompt templating capabilities. It creates a Prompt ActiveRecord model and a migration for the prompts table. ```bash rails generate langchainrb_rails:prompt ``` -------------------------------- ### Generate Langchainrb Rails Assistant (Bash) Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Generates ActiveRecord models, migrations, controllers, views, and a route for Langchain::Assistant in a Rails application. Requires specifying an LLM provider using the `--llm` option. ```bash rails generate langchainrb_rails:assistant --llm=openai ``` -------------------------------- ### Set OpenAI API Key Environment Variable Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Illustrates how to set the OPENAI_API_KEY environment variable, which is required for using OpenAI as the Language Model (LLM) for embeddings and completions. ```ruby ENV["OPENAI_API_KEY"]= ``` -------------------------------- ### Run Pgvector Generator for ActiveRecord Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Executes the Rails generator to configure an ActiveRecord model for vector search using Pgvector. It adds dependencies, creates an initializer, migrations, and modifies the model. ```bash rails generate langchainrb_rails:pgvector --model=Product --llm=openai ``` -------------------------------- ### Run Pinecone Generator for ActiveRecord Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Executes the Rails generator to configure an ActiveRecord model for vector search using Pinecone. It adds dependencies, creates an initializer, and modifies the model. ```bash rails generate langchainrb_rails:pinecone --model=Product --llm=openai ``` -------------------------------- ### Perform Question Answering on ActiveRecord Model Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Uses the ask method on an ActiveRecord model to perform natural language question answering based on the model's data and generated embeddings. It returns a string answer. ```ruby Product.ask("list the brands of shoes that are in stock") ``` -------------------------------- ### Generate Langchain.rb Assistant in Rails (Shell) Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/CHANGELOG.md Command to generate a Langchain.rb assistant within a Rails application using the provided generator. Requires specifying the LLM via the --llm option. ```Shell rails g langchainrb_rails:assistant --llm=... ``` -------------------------------- ### Generate Langchain.rb Prompt in Rails (Shell) Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/CHANGELOG.md Command to generate a Langchain.rb prompt within a Rails application using the provided generator. ```Shell rails g langchainrb_rails:prompt ``` -------------------------------- ### Define Custom as_vector Method for Embedding Generation Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Illustrates how to override the default as_vector method in an ActiveRecord model to customize the data used for generating embeddings. This allows selecting specific attributes. ```ruby def as_vector { name: name, description: description, category: category.name, ... }.to_json end ``` -------------------------------- ### Default as_vector Method for Embedding Generation Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Shows the default method used by langchainrb_rails to generate the text representation of an ActiveRecord record for embedding. It serializes the record to JSON, excluding the embedding column. ```ruby to_json(except: :embedding) ``` -------------------------------- ### Re-generate Embeddings After Customizing as_vector Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Instructs how to regenerate embeddings for all records after modifying the as_vector method. This ensures embeddings reflect the updated data representation. ```ruby Product.embed! ``` -------------------------------- ### Perform Similarity Search on ActiveRecord Model Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Executes a similarity search on an ActiveRecord model using vector embeddings. It returns an ActiveRecord relation containing records that are most semantically similar to the query. ```ruby Product.similarity_search("t-shirt") ``` -------------------------------- ### Generate Embeddings for ActiveRecord Model Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Calls the embed! method on an ActiveRecord model to generate vector embeddings for all records. This process can take significant time depending on the number of records. ```ruby Product.embed! ``` -------------------------------- ### Destroy Langchainrb Rails Assistant (Bash) Source: https://github.com/patterns-ai-core/langchainrb_rails/blob/main/README.md Removes the files generated by the `langchainrb_rails:assistant` generator from a Rails application. ```bash rails destroy langchainrb_rails:assistant ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.