| --- |
| 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 |
|
|
|  |
|
|
|
|
| # π€ 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 | |
|
|
| --- |
|
|
|
|
|
|