Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: uninitialized class variable @@provider #103

Open
andreibondarev opened this issue Sep 6, 2024 · 3 comments
Open

NameError: uninitialized class variable @@provider #103

andreibondarev opened this issue Sep 6, 2024 · 3 comments

Comments

@andreibondarev
Copy link
Collaborator

andreibondarev commented Sep 6, 2024

I ran into an issue when attempting to run 'SupportArticle.embed!' via the Rails console.

I get the following error:

SupportArticle Load (9.3ms)  SELECT "support_articles".* FROM "support_articles" ORDER BY "support_articles"."id" ASC LIMIT $1  [["LIMIT", 1000]]
NameError: uninitialized class variable @@provider in SupportArticle

from /Users/williamahlering/.gem/ruby/3.2.2/gems/langchainrb_rails-0.1.10/lib/langchainrb_rails/active_record/hooks.rb:52:in `class_variable_get'

I followed the setup instructions to add pgvector and successfully migrated the db to add the 'embedding' vector column to my model 'SupportArticle'. I've also set my ENV["OPENAI_API_KEY"] which I can see correctly in the rails console, as well.

My gemfile includes the following:

gem 'pgvector'
gem 'neighbor'
gem "langchainrb_rails", "~> 0.1.10"
gem "ruby-openai", "~> 7.1"
gem 'ollama-ai', '~> 1.3.0'
@sergiobayona
Copy link
Contributor

just some notes of minor issues that need to address but can be fixed manually:

doing:

rails generate langchainrb_rails:pgvector --model=SupportArticle --llm=openai

didn't underscore the table name:

class AddVectorColumnToSupportarticles < ActiveRecord::Migration[7.1]
  def change
    add_column :supportarticles, :embedding, :vector,
      limit: LangchainrbRails
        .config
        .vectorsearch
        .llm
        .default_dimensions
  end
end

didn't add the openai gem either.

@rickbenavidez
Copy link

If anyone else runs into the @@Provider exception message that @andreibondarev mentions here, double check that you've also explicitly added vectorsearch to the corresponding model file where your embedding column has been added. This error occurs when that piece is missing and you attempt to run any of the embeddings commands against it. I'm not sure if this helps with the original issue, but wanted to share where I saw it while getting things set up.

@andreibondarev
Copy link
Collaborator Author

If anyone else runs into the @@Provider exception message that @andreibondarev mentions here, double check that you've also explicitly added vectorsearch to the corresponding model file where your embedding column has been added. This error occurs when that piece is missing and you attempt to run any of the embeddings commands against it. I'm not sure if this helps with the original issue, but wanted to share where I saw it while getting things set up.

I'm wondering if there's a way to gracefully handle this error, like rescue-ing and then raising a specific error that points out that your model file is missing the vectorsearch line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants