Skip to content

Printf-Hello-World/RAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Simple RAG

πŸš€ About

A simple RAG that uses langchain, Chromadb, fastAPI, and streamlit. Allows the user to upload documents which are stored in a persistent vector database, has a chat bot UI.

inference UI

The project has the following file structure:

.
β”œβ”€β”€ corpus          # create and insert the database file in this folder
β”œβ”€β”€ src                                       
β”‚   β”œβ”€β”€ extracted_text       # folder path specified in conf.yaml      
β”‚   β”œβ”€β”€ pdf_extracted_imgs   # folder path specified in conf.yaml        
β”‚   β”œβ”€β”€ uploaded_docs        # folder path specified in conf.yaml    
β”‚   β”œβ”€β”€ vector_store         # folder path specified in conf.yaml 
β”‚   β”œβ”€β”€ utils
β”‚   β”‚   └── config.py
β”‚   β”œβ”€β”€ backend.py
β”‚   β”œβ”€β”€ dataloader.py
β”‚   β”œβ”€β”€ embedder.py
β”‚   β”œβ”€β”€ frontend.py
β”‚   β”œβ”€β”€ generator.py
β”‚   β”œβ”€β”€ retriever.py
β”‚   └── vectorstore.py     
β”œβ”€β”€ conf.yaml               # config files for running the pipeline
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── .env                    # keep all api keys here    

πŸ“ Installation & Usage

To install and run,

# create a virtual environment and activate it
python -m venv venv

# install dependencies
pip install -r requirements.txt

# to start the front end, in a terminal, 
streamlit run frontend.py

# to start the back end, in a terminal, 
uvicorn backend:app --reload

# open http://127.0.0.1:8501 to access the frontend

πŸ“š Pipeline Description

dataloader.py:
This module contains the Dataloader class which handles the loading and processing of raw data into text data ready for embedding. This class requires the folder paths of the data sources and output directories for processed data as well as the vision model to process the images

embedder.py:
This module contains the Embedder class which handles the embeding of text data that was processed by the dataloader. The get_embeddings method returns a the embedded data to be stored in the vectorstore.

vectorstore.py:
This module contains the Vectorstore class which connects to a persistent chromadb vector database and stores all the embeddings from the embedder inside. To reuse the vectorstore, the collection name and folder path for the vectorstore has to be same in the conf.yaml file.

retriever.py:
This module contains the Retriever class. This class takes an input query and connects to the Vectorstore to retreive all the relevant documents related to the query, only the top 3 relevant documents will be returned. Will be made as a user configurable parameter in future.

generator.py:
This module contains the Generator class which takes in the user query and relevant documents from the retriever to provide a response from the user specified LLM model.

frontend.py:
This module contains the streamlit integration for the front end. It contains an interface for the user to upload documents and a chatbot like UI

backend.py:
This module contains the fastAPI integration which connects to the front end. It contains the backend logic for updating the vector database using the modules above and the prediction logic based on a user query

βš™οΈ TODO

  • Add support for more LLMs and models
  • Add support for other raw data sources such as audio and csv
  • Improve the streamlit UI, add features like loading indicators when the vector DB is updating"# RAG"

About

Simple RAG Implementation using LangChain and Unstructured

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages