├── images ├── overview.webp ├── simple-rag-1.webp ├── simple-rag-1-db.webp └── simple-rag-1-reranker.webp ├── data └── example-1 │ └── Basic-Scientific-Food-Preparation-Lab-Manual.pdf ├── requirements.txt ├── README.md ├── .gitignore ├── notebooks ├── mistral-llamaindex-hf-offline-with-reranker.ipynb ├── mistral-llamaindex-hf-weaviate.ipynb └── mistral-llamaindex-hf-offline.ipynb └── LICENSE /images/overview.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasbt/RAGs/HEAD/images/overview.webp -------------------------------------------------------------------------------- /images/simple-rag-1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasbt/RAGs/HEAD/images/simple-rag-1.webp -------------------------------------------------------------------------------- /images/simple-rag-1-db.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasbt/RAGs/HEAD/images/simple-rag-1-db.webp -------------------------------------------------------------------------------- /images/simple-rag-1-reranker.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasbt/RAGs/HEAD/images/simple-rag-1-reranker.webp -------------------------------------------------------------------------------- /data/example-1/Basic-Scientific-Food-Preparation-Lab-Manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasbt/RAGs/HEAD/data/example-1/Basic-Scientific-Food-Preparation-Lab-Manual.pdf -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ollama # for offline LLMs 2 | llama-index 3 | pytorch 4 | llama-index-llms-ollama # to use offline models 5 | llama-index-embeddings-huggingface # to use offline models 6 | llama-index-llms-huggingface # to use offline models 7 | transformers -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RAGs: Simple Implementations of Retrieval Augmented Generation (RAG) Systems 2 | 3 |   4 | 5 | ![](images/overview.webp) 6 | 7 |   8 | 9 | - [notebooks/mistral-llamaindex-hf-offline.ipynb](notebooks/mistral-llamaindex-hf-offline.ipynb): A simple RAG system that uses a local Mistral 7B model and an in-memory vector database via LlamaIndex. 10 | 11 | - [notebooks/mistral-llamaindex-hf-offline-with-reranker.ipynb](notebooks/mistral-llamaindex-hf-offline-with-reranker.ipynb): Same as above, but adds a reranker model. 12 | 13 | - [notebooks/mistral-llamaindex-hf-weaviate.ipynb](notebooks/mistral-llamaindex-hf-weaviate.ipynb): A simple RAG system that uses a local Mistral 7B model and a Weaviate vector database via LlamaIndex. 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | share/python-wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | MANIFEST 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .nox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | *.py,cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | cover/ 55 | 56 | # Translations 57 | *.mo 58 | *.pot 59 | 60 | # Django stuff: 61 | *.log 62 | local_settings.py 63 | db.sqlite3 64 | db.sqlite3-journal 65 | 66 | # Flask stuff: 67 | instance/ 68 | .webassets-cache 69 | 70 | # Scrapy stuff: 71 | .scrapy 72 | 73 | # Sphinx documentation 74 | docs/_build/ 75 | 76 | # PyBuilder 77 | .pybuilder/ 78 | target/ 79 | 80 | # Jupyter Notebook 81 | .ipynb_checkpoints 82 | 83 | # IPython 84 | profile_default/ 85 | ipython_config.py 86 | 87 | # pyenv 88 | # For a library or package, you might want to ignore these files since the code is 89 | # intended to run in multiple environments; otherwise, check them in: 90 | # .python-version 91 | 92 | # pipenv 93 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 94 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 95 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 96 | # install all needed dependencies. 97 | #Pipfile.lock 98 | 99 | # poetry 100 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 101 | # This is especially recommended for binary packages to ensure reproducibility, and is more 102 | # commonly ignored for libraries. 103 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 104 | #poetry.lock 105 | 106 | # pdm 107 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 108 | #pdm.lock 109 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 110 | # in version control. 111 | # https://pdm.fming.dev/#use-with-ide 112 | .pdm.toml 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | -------------------------------------------------------------------------------- /notebooks/mistral-llamaindex-hf-offline-with-reranker.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# A Simple Mistral 7B Offline RAG with Reranker" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "### 1) Load the embedding model and LLM:" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "application/vnd.jupyter.widget-view+json": { 32 | "model_id": "901c4c15eb2045cfbe8d1419846e3847", 33 | "version_major": 2, 34 | "version_minor": 0 35 | }, 36 | "text/plain": [ 37 | "Loading checkpoint shards: 0%| | 0/3 [00:00" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "### 1) Load the embedding model and LLM:" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "application/vnd.jupyter.widget-view+json": { 32 | "model_id": "62ecf205130442478b85c95584795ef8", 33 | "version_major": 2, 34 | "version_minor": 0 35 | }, 36 | "text/plain": [ 37 | "modules.json: 0%| | 0.00/349 [00:00" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "### 1) Load the embedding model and LLM:" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "application/vnd.jupyter.widget-view+json": { 32 | "model_id": "2d6dd568bd5942aca2b4b1990dced1c0", 33 | "version_major": 2, 34 | "version_minor": 0 35 | }, 36 | "text/plain": [ 37 | "config.json: 0%| | 0.00/596 [00:00