Throughout the project, LLMs are used for two purposes :
SummarizationandCoherency
This project provides an end-to-end pipeline for scraping, preprocessing, and querying documents from the IIT Indore website using Pathway, LLMs, and a Streamlit-based GUI.
IITI-DOC-QA/
│
├── app/ # Flask API and LLM response generation
│ ├── batch_processor.py
│ ├── flask_api_expose_cookies_storage.py
│ └── flask_api_expose_redis_storage.py (optional)
│
├── core/ # Core backend functionalities
│ ├── loader.py
│ ├── query_classifier.py
│ ├── rag_chain_builder.py
│ └── vector_store_client.py
│
├── pathway_server/ # Pathway-based retrieval and QA pipeline
│ ├── PathwayServerExpose.py
│ └── helpers.py
│
├── Streamlit/ # Streamlit GUI
│ └── app.py
│
├── requirements.lock # Python dependencies (UV based)
└── README.md # Documentation
uv pip install -r requirements.lockpython3 pathway_server/PathwayServerExpose.py
python3 app/flask_api_expose_cookies_storage.py-
GET
/- Returns model info and a live status message.
-
POST
/-
Phase-1: Intent Classification
- Input:
messages - Output:
status = label_selection_needed,probable_labels
- Input:
-
Phase-2: RAG Generation
- Input:
messages,selected_label - Output:
status = processing_with_label,request_id
- Input:
-
-
GET
/status/<request_id>-
Output:
status = processing | completed | errormessage
-
pip install streamlitstreamlit run Streamlit/app.py-
Source: https://iiti.ac.in
-
Formats: PDFs, Images, Text
-
Collection Phases:
- Extracted using Selenium
- Organized by categories
- OCR & Summarization using
layout-parser
-
Cleaning:
- Removed non-English text
- Lowercased
- Removed repetitions and broken phrases
-
Access:
-
Intent Classification (Phase-1) :
- Upon receiving a new user query (without a
selected_label), thequery_classifiercomponent analyses the query to determine probable intent categories (labels). - The application responds by presenting these probable labels to the user, prompting them to select the most relevant one.
- Upon receiving a new user query (without a
-
RAG response generation (Phase-2):
- When a
selected_labelis provided by the user (indicating they've chosen an intent category), the system proceeds with generating a RAG-based response. - The
rag_buildercomponent is utilized to construct a formatted prompt, incorporating the original user message, conversational history, and the selected label. - Uses
Asynchronousprocessing with batching - `batch_processor.
- When a
-
Result Retrieval (Phase-3):
- Clients can poll this endpoint using the
request_idreceived from the initial/POST request. - Returns
completedonce the response is ready, along with the generated response. - Return
errorif an issue occured during processing.
- Clients can poll this endpoint using the
-
Intermediate Global Memory (Sits between the Frontend and the RAG-Backend): (Future Improvements)
Requirement- Most of the user queries will be of similar typeObjective- Mechanism that checks if the similar kindquestionis queried in the past and is cached or not.Purpose- Avoid LLM triggers all the time which will reduce the latency of the response.
-
Memory Management :
- User chat history (
HumanMessageandAIMessage) is persistently stored within the Flask session (session['chat_messages']). - The
langchain.memory.ConversationBufferMemoryis used to manage and format the chat history for input to the language model. get_user_memory(): Retrieves the chat history from the session and populates aConversationBufferMemoryobject.save_user_memory_to_session(): Serializes theConversationBufferMemorymessages back into a list and saves them to the Flask session after each interaction.
- User chat history (
-
LLM Inference Optimization :
Latency: UsesKV-Cachefor the response generation for the user query and intent.Throughput: Uses batch processing (Assuming that the bot gets multiple requests at a time) -Not needed for our usecase but implemented
-
Rule-Based Greeting/Send-Off :
- Identifies common greeting and send-off keywords in user queries.
- Provides randomized, predefined responses for such conversational turns, avoiding unnecessary LLM calls.
- Updates the session memory directly for these immediate responses.
FLASK_HOST,FLASK_PORT,FLASK_SECRET_KEYMODEL_CHOICE,EMBEDDING_MODELSYSTEM_PROMPT,PROMPT_TEMPLATEMAX_BATCH_SIZE,BATCH_TIMEOUT_SECONDS
- Retrieval Augmented Generation (RAG)
- Real-time ETL streaming
- OCR
- Prompt Engineering
- Caching (KV)
- Batching
- Session Management
- Clustering
- Web scraping
- LLMs
asyncio- For asynchronous processingthreading- For handling batches and multi requestspathway- For real time streamingLangchain: Used for creating PipelinesFlask: Used for creating the endpointsStreamlit: Used for creating the user interfaceSelenium: Scraping the data from WebsitesHDBScan: Clustering approach used for document segregationSentence-Transformer: Used as an embeddin model in the Document Clustering phaseTfidfVectorizer: For deciding on naming of the labels based on the most frequently used wordsNLTK: For removal of stop words from the documents in the Data segregation phaseKeyBert: For keyword and key-phrase extraction from the text-documents usingBERTLayout-Parser: An open-sourcedeep learning libraryfor performing OCR on PDFsunstructuredfor better extraction of data from PDF documentsPrompt Engineering: For Summarizing the pdfs containingunstructured data,noisy dataandtabular dataOLLAMA: UsedLLAMA2as a Summarization model as it balances bothuser_requestsand theone-shot contextprovided
QueuesListsDictionaries
For questions, feature requests, or contributions, feel free to:
- Open a GitHub issue
- Submit a pull request
Happy coding! 🚀