This is a simple chatbot that uses the RAG model to answer questions. The RAG model is a retrieval-augmented generation model that uses a retriever to find relevant documents and a generator to generate answers. This chatbot uses the transformers
library to load a pre-trained RAG model and interact with it.
The RAG model is a retrieval-augmented generation model that uses a retriever to find relevant documents and a generator to generate answers. The retriever is a dense passage retriever that uses a pre-trained model to find relevant documents. The generator is a language model that uses the retrieved documents to generate answers.
The way the RAG model works is as follows:
- A parser PyMuPDF converts the input pdf file into a list of sections.
- An embedding model BGE Small En v1.5 converts the list of sections into embeddings, which are then stored in an embedding database ( qdrant in our case )
- The user asks a question, which is converted into an embedding using the same embedding model.
- The embedding database is queried to find the most similar embeddings to the question embedding. We retrieve the top-k most similar embeddings.
- The retrieved embeddings are converted back into sections using the parser.
- The sections are concatenated and passed to the generator to generate an answer.
To install the dependencies, run:
pip install -r requirements.txt
To run the chatbot, run:
python chatbot.py
You can upload a pdf file by clicking on the "Upload PDF" button. The chatbot will then parse the pdf file and store the embeddings in the embedding database. You can then ask questions to the chatbot, and it will generate answers based on the pdf file.
The chatbot will prompt you to ask a question. Type your question and press Enter. The chatbot will then generate an answer.