Package: chat-with-mlx
Native RAG on MacOS and Apple Silicon with MLX 🧑‍💻This repository showcases a Retrieval-augmented Generation (RAG) chat interface with support for multiple open-source models.FeaturesChat with your Data:doc(x), pdf, txtand YouTube video via URL.Multilingual: Chinese 🇨🇳, English🏴, French🇫🇷, German🇩🇪, Indian🇮🇳, Italian🇮🇹, Japanese🇯🇵,Korean🇰🇷, Spanish🇪🇸, Turkish🇹🇷 and Vietnamese🇻🇳Easy Integration: Easy integrate any HuggingFace and MLX Compatible Open-Source Model.Installation and UsageEasy SetupInstall PipInstall:pip install chat-with-mlxNote: Setting up this way is really hard if you want to add your own model (which I will let you add later in the UI), but it is a fast way to test the app.Manual Pip Installationgitclonehttps://github.com/qnguyen3/chat-with-mlx.gitcdchat-with-mlx
pipinstall-e.Manual Conda Installationgitclonehttps://github.com/qnguyen3/chat-with-mlx.gitcdchat-with-mlx
condacreate-nmlx-chatpython=3.11
condaactivatemlx-chat
pipinstall-e.UsageStart the app:chat-with-mlxSupported ModelsGoogle Gemma-7b-it, Gemma-2b-itMistral-7B-Instruct, OpenHermes-2.5-Mistral-7B, NousHermes-2-Mistral-7B-DPOMixtral-8x7B-Instruct-v0.1, Nous-Hermes-2-Mixtral-8x7B-DPOQuyen-SE (0.5B), Quyen (4B)StableLM 2 Zephyr (1.6B)Vistral-7B-Chat, VBD-Llama2-7b-chat, vinallama-7b-chatAdd Your Own ModelsSolution 1This solution only requires you to add your own model with a simple .yaml config file inchat_with_mlx/models/configsexamlple.yaml:original_repo:google/gemma-2b-it# The original HuggingFace Repo, this helps with displayingmlx-repo:mlx-community/quantized-gemma-2b-it# The MLX models Repo, most are available through `mlx-community`quantize:4bit# Optional: [4bit, 8bit]default_language:multi# Optional: [en, es, zh, vi, multi]After adding the .yaml config, you can go and load the model inside the app (for now you need to keep track the download through your Terminal/CLI)Solution 2Do the same as Solution 1. Sometimes, thedownload_snapshotmethod that is used to download the models are slow, and you would like to download it by your own.After the adding the .yaml config, you can download the repo by yourself and add it tochat_with_mlx/models/download. The folder name MUST be the same as the orginal repo name without the username (sogoogle/gemma-2b-it->gemma-2b-it).A complete model should have the following files:model.safetensorsconfig.jsonmerges.txtmodel.safetensors.index.jsonspecial_tokens_map.json- this is optinal by modeltokenizer_config.jsontokenizer.jsonvocab.jsonKnown IssuesYou HAVE TO unload a model before loading in a new model. Otherwise, you would need to restart the app to use a new model, it would stuck at the old one.When the model is downloading by Solution 1, the only way to stop it is to hitcontrol + Con your Terminal.If you want to switch the file, you have to manually hit STOP INDEXING. Otherwise, the vector database would add the second document to the current database.You have to choose a dataset mode (Document or YouTube) in order for it to work.WHY MLX?MLX is an array framework for machine learning research on Apple silicon,
brought to you by Apple machine learning research.Some key features of MLX include:Familiar APIs: MLX has a Python API that closely follows NumPy.  MLX
also has fully featured C++,C, andSwiftAPIs, which closely mirror
the Python API.  MLX has higher-level packages likemlx.nnandmlx.optimizerswith APIs that closely follow PyTorch to simplify building
more complex models.Composable function transformations: MLX supports composable function
transformations for automatic differentiation, automatic vectorization,
and computation graph optimization.Lazy computation: Computations in MLX are lazy. Arrays are only
materialized when needed.Dynamic graph construction: Computation graphs in MLX are constructed
dynamically. Changing the shapes of function arguments does not trigger
slow compilations, and debugging is simple and intuitive.Multi-device: Operations can run on any of the supported devices
(currently the CPU and the GPU).Unified memory: A notable difference from MLX and other frameworks
is theunified memory model. Arrays in MLX live in shared memory.
Operations on MLX arrays can be performed on any of the supported
device types without transferring data.AcknowledgementI would like to send my many thanks to:The Apple Machine Learning Research team for the amazing MLX library.LangChain and ChromaDB for such easy RAG ImplementationPeople from Nous, VinBigData and Qwen team that helped me during the implementation.Star History