FirstAidRAG: A Smart Emergency Response Assistant Powered by LlamaIndex
FirstAidRAG is an intelligent first aid assistant that utilizes LlamaIndex and Ollama to process documents, extract relevant first aid information, and provide real-time assistance.
Below is a description of the key scripts used in the project:
-
extract_text.py
: Extracts structured text from a PDF using LlamaParse API. If LlamaParse fails, it falls back to SimpleDirectoryReader. The script processes the PDF, logs results, and prints a preview of the extracted text. -
clean_text.py
: Cleans and formats extracted text, fixing OCR errors, hyphenation issues, and section headers while removing irrelevant content and preserving important terms. -
ingest_data.py
: Extracts text from a PDF, cleans it, and saves the cleaned content into a Markdown file. The script processes each section of the document, filters relevant content, and handles file saving. -
index_data.py
: Creates or loads a FAISS index for vector-based search using Ollama embeddings. This script processes cleaned text from the Markdown file and stores the index for efficient querying. -
evaluate_rag.py
: Evaluates the first aid responses of the LLM based on relevancy and faithfulness scores. Results are saved to a CSV file for further analysis. -
query_engine.py
: Loads a FAISS index, retrieves relevant documents using AutoMergingRetriever, and generates a response based on the first aid prompt. If no relevant documents are found, it returns a default message. -
chat_engine.py
: Creates a chat engine for interactive first aid assistance using a memory buffer. Streams real-time responses to user input and provides an option to exit the conversation.
Clone the repository and navigate into the project folder:
git clone https://github.com/gabbygab1233/firstaid_assistant.git
cd firstaid_assistant
Install the necessary Python packages using pip
:
pip3 install -r requirements.txt
- Signup for LlamaCloud here to get an API key for LlamaParse.
- After signing up, create an API key and paste it in the
config.yaml
file as follows:
LLAMA_CLOUD_API_KEY: put-your-api-key-here
Download Ollama from this link. Once downloaded, pull the necessary models:
ollama pull llama3.1
ollama pull nomic-embed-text
Start the Ollama server in the background to serve the models:
ollama serve
Once Ollama is running, execute the pipeline by running the following command:
python3 main.py
To launch the application, run the following command:
chainlit run app.py -w