BBC-Esq / VectorDB-Plugin-for-LM-Studio

Plugin that lets you ask questions about your documents including audio and video files.
https://www.youtube.com/@AI_For_Lawyers
291 stars 36 forks source link

Installation on Windows with Conda #85

Closed hayjohnny2000 closed 10 months ago

hayjohnny2000 commented 11 months ago

Hi,

Thank you for this excellent plugin and project. I had a few problems installing the plugin with Pip so I created this issue to explain how I installed it using the Conda virtual environment/package manager for Python (instead of Pip) on Windows, in case it's helpful for others. Here are the steps I followed:

  1. conda create -p D:\ProgramData\.conda_envs\lmstudio_chromadb python=3.11
  2. conda activate D:\ProgramData\.conda_envs\lmstudio_chromadb
  3. conda install mamba -c conda-forge
  4. mamba install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
  5. mamba install -c conda-forge pyside6
  6. mamba install -c "nvidia/label/cuda-11.8.0" cuda-nvcc
  7. mamba install -c conda-forge hnswlib

Steps (1) and (2) create and activate the Conda/Python virtual environment. Step (3) installs mamba, which is much faster for installing/managing packages than default conda is. Step (4) installs PyTorch and some of the CUDA dependencies. Step (5) installs the pyside6 dependency. Step (6) installs the cuda-nvcc package which is required for the setup script to recognise that CUDA is installed. Step (7) installs the hnswlib, and I think avoids the need to install the Microsoft Visual C++ build tools for Visual Studio separately. If the hnswlib package fails to install with compilation errors, it might still be necessary to install the build tools from https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#visual-studio-2015-2017-2019-and-2022.

Hope this is helpful.

hayjohnny2000 commented 11 months ago

Hi,

Thank you for this excellent plugin and project. I had a few problems installing the plugin with Pip so I created this issue to explain how I installed it using the Conda virtual environment/package manager for Python (instead of Pip) on Windows, in case it's helpful for others. Here are the steps I followed:

  1. conda create -p D:\ProgramData\.conda_envs\lmstudio_chromadb python=3.11
  2. conda activate D:\ProgramData\.conda_envs\lmstudio_chromadb
  3. conda install mamba -c conda-forge
  4. mamba install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
  5. mamba install -c conda-forge pyside6
  6. mamba install -c "nvidia/label/cuda-11.8.0" cuda-nvcc
  7. mamba install -c conda-forge hnswlib

Steps (1) and (2) create and activate the Conda/Python virtual environment. Step (3) installs mamba, which is much faster for installing/managing packages than default conda is. Step (4) installs PyTorch and some of the CUDA dependencies. Step (5) installs the pyside6 dependency. Step (6) installs the cuda-nvcc package which is required for the setup script to recognise that CUDA is installed. Step (7) installs the hnswlib, and I think avoids the need to install the Microsoft Visual C++ build tools for Visual Studio separately. If the hnswlib package fails to install with compilation errors, it might still be necessary to install the build tools from https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#visual-studio-2015-2017-2019-and-2022.

Hope this is helpful.

Update after loading the application with python gui.py:

For some reason, PySide6 is not automatically finding the paths to the platform plugin and QT WebEngine dependencies, so I ran the following command to install it with Pip: pip install --ignore-installed pyside6.

However, I still received the following error when I ran python gui.py:

qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: direct2d, minimal, offscreen, windows.

I did some research and found I would have to set a few environment variables so the QT platform would be initialised properly. After a few iterations of other missing path errors, I managed to run the GUI. Unfortunately, this means some hacks added to the top of the gui.py module. The lines at the top of the file for importing libraries have been replaced as follows:

import os
import sys

import PySide6
from PySide6.QtWidgets import QApplication
pyqt = os.path.dirname(PySide6.__file__)
QApplication.addLibraryPath(os.path.join(pyqt, 'plugins'))

os.environ['QTWEBENGINEPROCESS_PATH'] = pyqt
os.environ['QTWEBENGINE_RESOURCES_PATH'] = os.path.join(pyqt, 'resources')
os.environ['QTWEBENGINE_LOCALES_PATH'] = os.path.join(pyqt, 'translations\qtwebengine_locales')

from PySide6.QtWidgets import (
    QWidget, QPushButton, QVBoxLayout, QTabWidget,
    QTextEdit, QSplitter, QFrame, QStyleFactory, QLabel, QGridLayout, QMenuBar, QCheckBox, QHBoxLayout, QMessageBox
)
from PySide6.QtCore import Qt, QTimer
from pathlib import Path
import torch
import yaml
import platform
import threading
from initialize import main as initialize_system
from metrics_bar import MetricsBar
from download_model import download_embedding_model
from select_model import select_embedding_model_directory
from choose_documents import choose_documents_directory, see_documents_directory
import create_database
from gui_tabs import create_tabs
from gui_threads import CreateDatabaseThread, SubmitButtonThread
import voice_recorder_module
from utilities import list_theme_files, make_theme_changer, load_stylesheet
from bark_module import BarkAudio
from constants import CHUNKS_ONLY_TOOLTIP, SPEAK_RESPONSE_TOOLTIP

Not sure if this is being caused by installation of PySide6 through Conda, which is entirely possible. It does seem to be missing some environment variables or config somewhere. Hopefully when the issues with the library file paths in the package installation is resolved, this code can be removed from my gui.py. Till then, I will enjoy experimenting with RAG!

Thanks!

BBC-Esq commented 11 months ago

Wow, thank you, I know others have asked about conda. I've never used it. Can you confirm that everything in your messages up to this point is workable? I'd like to eventually test it and add instructions for a conda installation.

BBC-Esq commented 11 months ago

On second thought, can we do a screenshare sometime of just you installing it with conda? I learn quicker visually with someone showing me the first time, if you don't mind. Also, do you have any experience with something called "poetry?"

hayjohnny2000 commented 11 months ago

No problem, glad it was helpful. I can confirm that the following revised steps work:

  1. conda create -p D:\ProgramData\.conda_envs\lmstudio_chromadb python=3.11
  2. conda activate D:\ProgramData\.conda_envs\lmstudio_chromadb
  3. conda install mamba -c conda-forge
  4. mamba install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
  5. mamba install -c conda-forge pyside6
  6. mamba install -c "nvidia/label/cuda-11.8.0" cuda-nvcc
  7. mamba install -c conda-forge hnswlib
  8. pip install --ignore-installed pyside6
  9. cd D:\ProgramData\code_projects
  10. git clone https://github.com/BBC-Esq/ChromaDB-Plugin-for-LM-Studio.git ChromaDB-Plugin-for-LM-Studio
  11. cd ChromaDB-Plugin-for-LM-Studio\src
  12. python setup.py
  13. [edit gui.py to include the environment variables and reorder some import statements as in comment above]
  14. python gui.py

I have uploaded a video of the installation process to https://ufile.io/hvz4h50e that is valid for 30 days; it's 680MB but I found the slow download was fine and completed after a few minutes. I would be happy to screenshare sometime, just going to be tricky to find the time that we're both available.

It occurred to me that I already have Pandoc installed globally, but other people might not, so an additional step might be needed prior to running the python setup.py in (12), which would be mamba install -c conda-forge pandoc, i.e. from the Pandoc Conda package.

I have not used Poetry yet, but judging by the support docs it looks very handy, thanks for the suggestion!

P.S. I have had some success with the GUI, creating the vector DB with my documents and running queries against the LMStudio API - looking forward to seeing what I can do - thanks again 😊

BBC-Esq commented 11 months ago

Let's do a screenshare sometime...I'd be easier to do that. Are you on Discord?