fynnfluegge / codeqai

Local first semantic code search and chat powered by vector embeddings and LLMs
Apache License 2.0
385 stars 46 forks source link

Error running `codeqai search , app` and `chat` : Unexpected keyword argument `token` in `INSTRUCTOR._load_sbert_model()` #34

Closed TeomanEgeSelcuk closed 6 months ago

TeomanEgeSelcuk commented 6 months ago

Description

When attempting to run the codeqai app command on my project directory, I encountered a TypeError related to an unexpected keyword argument 'token' in the INSTRUCTOR._load_sbert_model() method. This occurred after configuring codeqai to use local embedding models (Instructor-Large) and selecting gpt-4 as the remote LLM for chat functionalities.

Steps to Reproduce

  1. Installed codeqai using pip.
  2. Ran codeqai configure and configured the tool as follows:
    • Selected "y" for using local embedding models.
    • Chose "Instructor-Large" for the local embeddings model.
    • Selected "N" for using local chat models and chose "OpenAI" with "gpt-4" as the remote LLM.
  3. Attempted to start the codeqai search by running codeqai search in the terminal.
  4. Encountered the following error:
  Traceback (most recent call last):
    File "/usr/local/bin/codeqai", line 8, in <module>
      sys.exit(main())
               ^^^^^^
    File "/usr/local/lib/python3.11/site-packages/codeqai/__main__.py", line 5, in main
      app.run()
    File "/usr/local/lib/python3.11/site-packages/codeqai/app.py", line 121, in run
      embeddings_model = Embeddings(
                         ^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/codeqai/embeddings.py", line 42, in __init__
      self.embeddings = HuggingFaceInstructEmbeddings()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/langchain_community/embeddings/huggingface.py", line 149, in __init__
      self.client = INSTRUCTOR(
                    ^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/sentence_transformers/SentenceTransformer.py", line 194, in __init__
      modules = self._load_sbert_model(
                ^^^^^^^^^^^^^^^^^^^^^^^
  TypeError: INSTRUCTOR._load_sbert_model() got an unexpected keyword argument 'token'

Expected Behavior

I expected the codeqai search to launch successfully and allow me to interact with my codebase through the bash terminal.

Actual Behavior

The application failed to start due to a TypeError in the INSTRUCTOR._load_sbert_model() method.

Environment

Additional Context

The issue seems to be related to the integration between codeqai, the langchain-community package, and sentence-transformers. Given that all components are up to date, it appears there might be an incompatibility or a bug in the way codeqai is utilizing the sentence-transformers library, specifically with the INSTRUCTOR model configuration.


fynnfluegge commented 6 months ago

Hey @TeomanEgeSelcuk thanks for the detailed report! I think something got messed up here https://github.com/fynnfluegge/codeqai/commit/7f15456c430408c959f0944ef33d37fbeab8d895

Will have a closer look asap!

TeomanEgeSelcuk commented 6 months ago

No worries, take your time excited to use codeqai. I tried to implement it after this YouTuber made the video: https://www.youtube.com/watch?v=RA_jYH05avk&t=23s&ab_channel=WorldofAI

matcon commented 6 months ago

I have the same problem when trying to run codeqai I get the same problem, try downgrading to the library "sentence-transformers==2.2.2" but I couldn't get it to work.

shreyahegde18 commented 6 months ago

experienced same error even with sentence-transformers. then, this worked for me from langchain_community.embeddings import HuggingFaceEmbeddings embeddings = HuggingFaceEmbeddings(model_name="hkunlp/instructor-xl")

fynnfluegge commented 6 months ago

Hey @shreyahegde18 thanks for suggesting the solution! I am a bit under water this week, would appreciate it a lot if you don't mind to raise a PR with this fix 🙂

shreyahegde18 commented 6 months ago

@fynnfluegge I will surely give it a try :)

shreyahegde18 commented 6 months ago

Hey @fynnfluegge I have opened a PR with a fix that resolved this issue. I hope it's going to work fine for everyone who wants to use codeqai :)

fynnfluegge commented 6 months ago

Reopen, found this https://github.com/PromtEngineer/localGPT/issues/722

The sentence-transformers version 2.2.2 must be specified explicitly.

fynnfluegge commented 6 months ago

Fixed in https://github.com/fynnfluegge/codeqai/commit/526d50c6ccbca6f535255ceb18f9617f2ff51870

Thanks @shreyahegde18 for suggesting HuggingFaceEmbeddings(model_name="hkunlp/instructor-xl")