Prerequisites
- Python 3.9+
- A Pinecone API Key (Get one here)
- A Groq API Key (Get one here)
1. Clone the Repository
git clone https://github.com/TorshaMajumder/CanFin-MultiQuarter-RAG.git
cd CanFin-MultiQuarter-RAG2. Install Dependencies
pip install -r requirements.txt3. Data You find all the Shopify 2023 Quartarly and Annual reports in Shopify Investor Relations page.
4. Data Ingestion
Place your Shopify 2023 PDFs (shopify_q1.pdf, shopify_q2.pdf, etc.) in the root directory and run the ingestion pipeline. This script parses the PDFs into Markdown, chunks the text, and upserts vectors to Pinecone.
python ingest.py5. Launch the App
streamlit run app.pyThis application is built to solve the "Temporal Knowledge" problem in RAG systems, specifically for complex financial documents.
- Parsing (Multimodal-Aware): Used
PyMuPDF4LLMto convert financial PDFs into Markdown. This preserves the structural integrity of complex tables (Balance Sheets/Income Statements) which standard text-extractors often corrupt. - Vector Storage: Pinecone (Serverless).
- Temporal Metadata Strategy: Implemented a metadata schema involving
quarter,year, andcompanytags. This allows for Conditional Retrieval, enabling the system to isolate and compare specific fiscal periods using Pinecone's$eqfilters. - Embedding Model:
sentence-transformers/all-MiniLM-L6-v2. This model was chosen for its efficiency in mapping semantic meaning within a 384-dimensional space. - LLM Inference: Llama-3.1-8b-instant via Groq. The model is grounded using a strict "System Prompt" to ensure answers are derived exclusively from the retrieved financial context, minimizing hallucinations.
- UI Framework: Streamlit, designed with a dual-column source viewer to provide transparency into the "Reasoning" phase of the RAG pipeline.
- Table Integrity: Solved the loss of tabular data relationships by utilizing Markdown-based chunking.
- Comparison Logic: Developed a targeted retrieval loop that queries separate namespaces/filters for different quarters, ensuring the LLM receives a balanced context for comparative analysis.