├── .python-version ├── .env.example ├── requirements.txt ├── app.py ├── readme.md └── .gitignore /.python-version: -------------------------------------------------------------------------------- 1 | 3.9 2 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY= 2 | 3 | QDRANT_HOST= 4 | QDRANT_API_KEY= 5 | QDRANT_COLLECTION_NAME= 6 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | langchain 2 | python-dotenv 3 | streamlit 4 | openai 5 | qdrant-client 6 | tiktoken 7 | 8 | 9 | # uncomment to use huggingface llms 10 | # huggingface-hub==0.14.1 11 | 12 | # uncomment to use instructor embeddings 13 | # InstructorEmbedding==1.0.1 14 | # sentence-transformers==2.2.2 -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from dotenv import load_dotenv 2 | import streamlit as st 3 | 4 | from langchain.chains import RetrievalQA 5 | from langchain.llms import OpenAI 6 | from langchain.vectorstores import Qdrant 7 | from langchain.embeddings.openai import OpenAIEmbeddings 8 | import qdrant_client 9 | import os 10 | 11 | def get_vector_store(): 12 | 13 | client = qdrant_client.QdrantClient( 14 | os.getenv("QDRANT_HOST"), 15 | api_key=os.getenv("QDRANT_API_KEY") 16 | ) 17 | 18 | embeddings = OpenAIEmbeddings() 19 | 20 | vector_store = Qdrant( 21 | client=client, 22 | collection_name=os.getenv("QDRANT_COLLECTION_NAME"), 23 | embeddings=embeddings, 24 | ) 25 | 26 | return vector_store 27 | 28 | def main(): 29 | load_dotenv() 30 | 31 | st.set_page_config(page_title="Ask Qdrant") 32 | st.header("Ask your remote database 💬") 33 | 34 | # create vector store 35 | vector_store = get_vector_store() 36 | 37 | # create chain 38 | qa = RetrievalQA.from_chain_type( 39 | llm=OpenAI(), 40 | chain_type="stuff", 41 | retriever=vector_store.as_retriever() 42 | ) 43 | 44 | # show user input 45 | user_question = st.text_input("Ask a question about your PDF:") 46 | if user_question: 47 | st.write(f"Question: {user_question}") 48 | answer = qa.run(user_question) 49 | st.write(f"Answer: {answer}") 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # App Boilerplate with GUI for Qdrant Managed Cloud Service 2 | 3 | > This repository accompanies the [App Boilerplate with GUI for Qdrant Managed Cloud Service](https://youtu.be/1X6QX6Z6Zq8) video tutorial on YouTube. 4 | 5 | This repository contains an app boilerplate with a graphical user interface (GUI) that connects to a remote database hosted in Qdrant's Managed Cloud Service. The purpose of this boilerplate is to provide a starting point for building applications that interact with a Qdrant vector database. 6 | 7 | ## Features 8 | 9 | - Graphical user interface (GUI) for easy interaction with the Qdrant vector database. 10 | - Seamless integration with Qdrant's Managed Cloud Service. 11 | - Simple setup process by cloning the repository and adding your credentials to the `.env` file. 12 | - Comes with a comprehensive set of requirements specified in the `requirements.txt` file. 13 | 14 | ## Prerequisites 15 | 16 | Before using this app boilerplate, make sure you have the following: 17 | 18 | - Python 3.x installed on your system. 19 | - An active Qdrant Managed Cloud Service account. 20 | - Your Qdrant Managed Cloud Service credentials. 21 | 22 | ## Installation 23 | 24 | To install and run the app boilerplate, follow these steps: 25 | 26 | 1. Clone this repository to your local machine: 27 | 28 | ```shell 29 | git clone https://github.com/alejandro-ao/qdrant-cloud-app.git 30 | ``` 31 | 32 | 2. Change into the project directory: 33 | 34 | ```shell 35 | cd qdrant-cloud-app 36 | ``` 37 | 38 | 3. Install the required Python packages using pip: 39 | 40 | ```shell 41 | pip install -r requirements.txt 42 | ``` 43 | 44 | ## Configuration 45 | 46 | To configure the app boilerplate to work with your Qdrant Managed Cloud Service account, you need to add your credentials to the `.env` file. Follow these steps: 47 | 48 | 1. Copy the `.env.example` file and rename it to `.env`: 49 | 50 | ```shell 51 | cp .env.example .env 52 | ``` 53 | 54 | 2. Open the `.env` file in a text editor and provide your Qdrant Managed Cloud Service and OpenAI credentials: 55 | 56 | ```plaintext 57 | OPENAI_API_KEY= 58 | 59 | QDRANT_HOST= 60 | QDRANT_API_KEY= 61 | QDRANT_COLLECTION_NAME= 62 | ``` 63 | 64 | ## Usage 65 | 66 | Once you have completed the installation and configuration steps, you can run the app boilerplate using the following command: 67 | 68 | ```shell 69 | streamlit run app.py 70 | ``` 71 | 72 | This command will start the application. 73 | 74 | ## Contributing 75 | 76 | This repository does not accept contributions unless they are aimed at fixing errors in the original code. The code is intentionally maintained as-is to support the accompanying YouTube video tutorial. 77 | 78 | If you discover any errors or issues in the original code, please feel free to open an issue on the GitHub repository, and we will address it accordingly. 79 | 80 | ## License 81 | 82 | The code in this repository is available under the [MIT License](LICENSE). Feel free to modify and use it for your own projects. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ --------------------------------------------------------------------------------