--- title: MiniCPM Financial RAG sdk: gradio sdk_version: 5.34.0 python_version: "3.11" app_file: app.py pinned: false tags: - track:backyard - sponsor:openbmb - sponsor:modal - achievement:offbrand - achievement:fieldnotes --- # 💰 MiniCPM Financial RAG ### 📊 Financial Document Intelligence Powered by Retrieval-Augmented Generation **Real-world Problem** Financial reports, insurance documents, annual reports, SEC filings, balance sheets, and investment documents often contain hundreds of pages of complex information. Finding specific financial insights manually is time-consuming and error-prone. **MiniCPM Financial RAG** enables users to upload financial PDF documents and ask questions in natural language. The system retrieves the most relevant information from the document and generates accurate, context-aware answers using MiniCPM models. --- ## Build Small Hackathon Submission Space: https://huggingface.co/spaces/build-small-hackathon/MiniCPM_Financial_RAG Demo: https://youtu.be/0z1i5ESbgYk Social: https://x.com/gajanand2004/status/2066422082725163265 Article: https://huggingface.co/blog/build-small-hackathon/minicpm-financial-rag --- ## 👥 Team | Name | Hugging Face Username | |------|----------------------| | Gajanan Deshmukh | Gaju19 | --- ## RAG architecture ![kids-education-ai](./Architecture.png) # 🤖 Models Used | Task | Model | Parameters | Purpose | |------|--------|------------|---------| | Financial Question Answering | openbmb/MiniCPM-2B-128K | 2B | Financial reasoning and answer generation | | Embedding Generation | openbmb/MiniCPM-Embedding-Light | Lightweight | Semantic retrieval and vector search | --- # 🧠 Why MiniCPM? | Model | Benefits | |---------|----------| | MiniCPM-2B-128K | Lightweight, fast inference, long-context understanding | | MiniCPM-Embedding-Light | Efficient embeddings with strong retrieval performance | --- # 🚀 Features | Feature | Description | |----------|-------------| | 📄 PDF Upload | Upload financial reports and PDF documents | | ✂️ Smart Chunking | Automatically split documents into meaningful chunks | | 🔎 Semantic Search | Retrieve the most relevant financial information | | 🧠 Financial Question Answering | Ask questions in natural language | | 📚 Retrieval-Augmented Generation | Generate context-grounded answers | | ⚡ GPU Acceleration | Fast inference using Modal GPU infrastructure | | 📊 Financial Analysis | Analyze revenue, expenses, assets, and liabilities | | 🎯 High Accuracy Retrieval | FAISS-based vector similarity search | --- ## 🎯 Example Questions - What is the company's total revenue? - What is the net income for this period? - What are the major risk factors? - Summarize the financial outlook. - What liabilities are reported? - What is the operating cash flow? --- # 📚 Knowledge Pipeline | Stage | Purpose | |--------|----------| | PDF Parsing | Extract text from PDF documents | | Text Chunking | Break large documents into manageable sections | | Embedding Generation | Convert text chunks into vector representations | | FAISS Storage | Store vectors efficiently for retrieval | | Similarity Search | Retrieve the most relevant document chunks | | LLM Generation | Generate grounded answers from retrieved context | --- # ⚙️ Tech Stack | Layer | Technology | |--------|------------| | Frontend | Gradio | | Backend | Modal | | LLM | MiniCPM-2B-128K | | Embeddings | MiniCPM-Embedding-Light | | Vector Database | FAISS | | Framework | LangChain | | PDF Processing | PyPDFLoader | | Deep Learning | PyTorch | | Deployment | Hugging Face Spaces | --- # 📈 Monitoring The application is continuously monitored to ensure reliability and performance. | Component | Monitoring Method | |------------|------------------| | Hugging Face Space | Build Logs & Runtime Logs | | Modal Backend | Endpoint Monitoring | | Retrieval Pipeline | Context Validation | | Vector Search | Similarity Search Accuracy | | Question Answering | Response Validation | | System Health | Runtime Monitoring | --- # 🌐 Deployment Architecture ```text Hugging Face Spaces │ ▼ Gradio Frontend │ ▼ Modal Backend │ ┌──────┴──────┐ ▼ ▼ MiniCPM QA FAISS Retrieval ``` --- # 📂 Project Structure ```text MiniCPM_Financial_RAG/ ├── app.py │ ├── requirements.txt ├── Architecture.png └── README.md ``` --- # 💻 Installation ## Create Virtual Environment ```bash python -m venv venv ``` ## Activate Environment ### Windows ```bash venv\Scripts\activate ``` ### Linux / Mac ```bash source venv/bin/activate ``` ## Install Dependencies ```bash pip install -r requirements.txt ``` --- # 🚀 Run Application ```bash python app.py ``` Application URL: ```text http://localhost:8000 ``` --- # 🎯 Target Users | User Type | Use Case | |------------|----------| | Financial Analysts | Analyze reports and statements | | Investors | Extract investment insights | | Accountants | Review financial data quickly | | Auditors | Validate financial information | | Researchers | Analyze large financial documents | | Students | Learn financial concepts interactively | --- # 📊 Benefits | Benefit | Description | |----------|-------------| | Faster Analysis | Reduce manual document review time | | Accurate Retrieval | Retrieve the most relevant financial information | | Context-Aware Answers | Grounded responses from document content | | Scalable Architecture | Handles large financial reports efficiently | | Cost Effective | Uses lightweight MiniCPM models | ---