{"id":28715183,"url":"https://github.com/arifazim/financial_ai_assistant","last_synced_at":"2026-04-11T19:02:45.165Z","repository":{"id":290325560,"uuid":"974049046","full_name":"arifazim/financial_ai_assistant","owner":"arifazim","description":"AI-powered assistant for financial services that uses Retrieval Augmented Generation (RAG) to provide accurate financial information and advice through multiple communication channels","archived":false,"fork":false,"pushed_at":"2025-05-21T06:50:22.000Z","size":910,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T07:44:35.236Z","etag":null,"topics":["chat-application","docker","faiss","faiss-vector-database","fastapi","pandas","pydantic","rag","sentence-transformers","transformer","twilio","whatsapp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arifazim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-28T07:19:50.000Z","updated_at":"2025-05-21T06:50:26.000Z","dependencies_parsed_at":"2025-04-28T08:43:23.808Z","dependency_job_id":null,"html_url":"https://github.com/arifazim/financial_ai_assistant","commit_stats":null,"previous_names":["arifazim/financial_ai_assistant"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arifazim/financial_ai_assistant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifazim%2Ffinancial_ai_assistant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifazim%2Ffinancial_ai_assistant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifazim%2Ffinancial_ai_assistant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifazim%2Ffinancial_ai_assistant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arifazim","download_url":"https://codeload.github.com/arifazim/financial_ai_assistant/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifazim%2Ffinancial_ai_assistant/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259910633,"owners_count":22930699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat-application","docker","faiss","faiss-vector-database","fastapi","pandas","pydantic","rag","sentence-transformers","transformer","twilio","whatsapp"],"created_at":"2025-06-15T02:01:02.679Z","updated_at":"2025-12-30T21:07:17.739Z","avatar_url":"https://github.com/arifazim.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Financial AI Agent\n\nA powerful AI-powered assistant for financial services that uses Retrieval Augmented Generation (RAG) to provide accurate financial information and advice through multiple communication channels.\n\n## Project Objective\n\nThe Financial AI Agent aims to provide instant, accurate responses to customer inquiries about financial products, services, and general financial knowledge. By leveraging modern AI technologies and a knowledge base of financial information, this agent helps financial institutions:\n\n- Reduce customer support workload\n- Provide 24/7 automated assistance\n- Deliver consistent and accurate financial information\n- Reach customers through their preferred communication channels (WhatsApp, Email, Live Chat)\n\n## How This Project Helps\n\n### For Financial Institutions\n- **Cost Reduction**: Automates routine customer inquiries, reducing support staff requirements\n- **Improved Customer Experience**: Provides instant responses at any time of day\n- **Scalability**: Handles multiple customer inquiries simultaneously\n- **Consistency**: Ensures all customers receive the same accurate information\n- **Multi-channel Support**: Reaches customers through WhatsApp, Email, and Live Chat\n\n### For Customers\n- **Instant Answers**: Get immediate responses to financial questions\n- **Convenience**: Access information through preferred communication channels\n- **24/7 Availability**: Get assistance outside of business hours\n- **Personalized Information**: Receive relevant information based on specific queries\n\n## System Architecture \u0026 Workflow\n\nThe Financial AI Agent follows this workflow:\n\n1. **Knowledge Base Creation** (`knowledge_base.py`):\n   - Financial information is stored in structured format\n   - Documents are embedded using sentence transformers\n   - Vector database is created for semantic search\n\n2. **Query Processing \u0026 Retrieval** (`retrieval.py`):\n   - User query is received through API\n   - Query is embedded and semantically searched against knowledge base\n   - Most relevant information is retrieved\n\n3. **Response Generation** (`fin_engine.py`):\n   - Retrieved context is combined with user query\n   - AI model generates natural language response\n   - Response is validated for accuracy and compliance\n\n4. **API \u0026 Integration** (`main.py`, `integrations.py`):\n   - FastAPI server handles incoming requests\n   - Response is delivered through appropriate channel (WhatsApp, Email, Chat)\n   - Conversation history can be maintained for context\n\n## Project Structure\n\n```\nfinancial_ai_agent/\n│── models/                  # Stores the AI model (if using local LLM)\n│── data/                    # Stores FAQs, PDFs, Help Articles\n│── embeddings/              # Vectorized knowledge base\n│── src/\n│   ├── main.py              # (4) API Server with FastAPI\n│   ├── retrieval.py         # (2) Retrieve Relevant Data (RAG)\n│   ├── knowledge_base.py    # (1) Load and Embed Knowledge Base\n│   ├── fin_engine.py        # (3) Generate AI Response using RAG + LLM\n│   ├── integrations.py      # (5) WhatsApp, Email, Live Chat Integration\n│   ├── security.py          # AI safety and compliance checks\n│── packages.txt         # Python dependencies\n│── config.yaml              # Configuration file\n│── README.md                # Documentation\n│── Dockerfile               # Docker configuration\n│── docker-compose.yml       # Docker Compose configuration\n```\n\n## Technical Architecture\n\n### Embedding Model: all-MiniLM-L6-v2\n\nThe Financial AI Assistant uses the `all-MiniLM-L6-v2` model for generating text embeddings, which offers an optimal balance of performance and efficiency:\n\n#### Why all-MiniLM-L6-v2?\n\n- **Efficiency**: Produces 384-dimensional embeddings (compared to larger models with 768+ dimensions)\n- **Performance**: Achieves 80.2% accuracy on the Semantic Textual Similarity Benchmark (STS-B)\n- **Speed**: 2-3x faster than larger models like BERT-base\n- **Size**: Only 80MB, making it suitable for deployment in resource-constrained environments\n- **Versatility**: Trained on over 1 billion sentence pairs across multiple domains\n\n```\n┌─────────────────────────────────────┐\n│         all-MiniLM-L6-v2            │\n├─────────────────────────────────────┤\n│ ┌───────────────┐  ┌───────────────┐│\n│ │  6 Layers of  │  │ 384-dimension ││\n│ │ Transformer   │→ │   Embedding   ││\n│ │ Architecture  │  │    Vectors    ││\n│ └───────────────┘  └───────────────┘│\n└─────────────────────────────────────┘\n```\n\nThe model was created using knowledge distillation from larger models, preserving semantic understanding while reducing computational requirements. This makes it ideal for our financial assistant which needs to quickly understand and match user queries with relevant knowledge base entries.\n\n### FAISS Vector Indexing for RAG\n\nFAISS (Facebook AI Similarity Search) provides efficient similarity search and clustering of dense vectors. Our implementation uses it to power the Retrieval Augmented Generation (RAG) system:\n\n#### How FAISS Indexing Works in Our System\n\n```\n┌───────────────────────────────────────────────────────────────────────┐\n│                       FAISS Vector Indexing Process                   │\n├───────────────────────────────────────────────────────────────────────┤\n│                                                                       │\n│  ┌──────────────┐    ┌──────────────┐    ┌──────────────────────┐     │\n│  │ Knowledge    │    │ all-MiniLM   │    │ FAISS IndexFlatL2    │     │\n│  │ Base Entries │ →  │ Embedding    │ →  │ (L2 Distance Index)  │     │\n│  │              │    │ Model        │    │                      │     │\n│  └──────────────┘    └──────────────┘    └──────────────────────┘     │\n│         ▲                                           │                 │\n│         │                                           ▼                 │\n│  ┌──────────────┐                       ┌──────────────────────┐      │\n│  │ New Financial│                       │ Serialized Index     │      │\n│  │ Knowledge    │ ◄───────────────────  │ Stored on Disk       │      │\n│  │              │                       │                      │      │\n│  └──────────────┘                       └──────────────────────┘      │\n│                                                                       │\n└───────────────────────────────────────────────────────────────────────┘\n```\n\n#### RAG Query Process\n\n```\n┌───────────────────────────────────────────────────────────────────────┐\n│                       RAG Query Process                               │\n├───────────────────────────────────────────────────────────────────────┤\n│                                                                       │\n│  ┌──────────────┐    ┌──────────────┐    ┌──────────────────────┐     │\n│  │ User Query   │    │ all-MiniLM   │    │ FAISS Vector Search  │     │\n│  │ (e.g., fees) │ →  │ Embedding    │ →  │ (Find similar        │     │\n│  │              │    │ Model        │    │  vectors)            │     │\n│  └──────────────┘    └──────────────┘    └──────────────────────┘     │\n│                                                     │                 │\n│                                                     ▼                 │\n│  ┌──────────────────────────┐            ┌──────────────────────┐     │\n│  │ Response Generation      │            │ Top-K Most Similar   │     │\n│  │ (Format and combine      │ ◄────────  │ Knowledge Base       │     │\n│  │  retrieved information)  │            │ Entries              │     │\n│  └──────────────────────────┘            └──────────────────────┘     │\n│                │                                                      │\n│                ▼                                                      │\n│  ┌──────────────────────────┐                                         │\n│  │ Final Response to User   │                                         │\n│  └──────────────────────────┘                                         │\n│                                                                       │\n└───────────────────────────────────────────────────────────────────────┘\n```\n\n#### Key FAISS Implementation Details\n\n1. **IndexFlatL2**: We use a flat index with L2 (Euclidean) distance metric\n   - Pros: Exact search with highest accuracy\n   - Cons: Linear time complexity O(n) with the number of vectors\n\n2. **Vector Dimension**: 384 dimensions from the all-MiniLM-L6-v2 model\n\n3. **Distance Threshold**: The system uses a configurable distance threshold (currently set to 20.0) to determine relevance\n\n4. **Preprocessing**: For FAQ entries, we combine questions and answers before embedding to capture the full semantic context\n\n5. **Fallback Mechanism**: If vector search fails to find relevant entries, the system falls back to keyword-based search\n\nThis architecture enables our financial assistant to quickly find the most semantically relevant information from the knowledge base, even when user queries don't exactly match the wording in our knowledge base.\n\n## Setup and Installation\n\n### Prerequisites\n- Python 3.8+\n- pip (Python package manager)\n- Docker (for containerized deployment)\n\n### Local Development Setup\n\n1. **Clone the repository**\n   ```bash\n   git clone https://github.com/arifazim/financial_ai_agent.git\n   cd financial_ai_agent\n   ```\n\n2. **Create and activate a virtual environment**\n   ```bash\n   python -m venv venv\n   source venv/bin/activate  # On Windows: venv\\Scripts\\activate\n   ```\n\n3. **Install dependencies**\n   ```bash\n   pip install -r packages.txt\n   ```\n\n4. **Configure the application**\n   - Edit `config.yaml` to set up your:\n     - API keys\n     - Twilio credentials for WhatsApp\n     - Email settings\n     - Model preferences\n\n5. **Prepare knowledge base**\n   - Add your financial FAQs, documents, and help articles to the `data/` directory\n   - Format should follow the existing JSON structure in `data/knowledge_base.json`\n\n6. **Run the application**\n   ```bash\n   uvicorn src.main:app --host 127.0.0.1 --port 8000\n   ```\n\n7. **Access the API**\n   - API documentation: http://127.0.0.1:8000/docs\n   - Test endpoint: http://127.0.0.1:8000/\n\n## Using the API\n\n### Modern UI Interface\n\nWe've included a modern web interface to test the Financial AI Assistant without using command line tools:\n\n```\n# Start the API server\nuvicorn src.main:app --host 127.0.0.1 --port 8000\n\n# Open the UI in your browser\nopen ui/index.html\n```\n![Financial AI Assistant UI](./images/fin-chat.png)\n\n# Synced with knowledge base indexed in FAISS\n![Financial AI Assistant UI with FAISS](./images/sync-with-chat.png)\n\nThe UI provides:\n- A chat-like interface for sending queries\n- Channel selection (Chat, WhatsApp, Email)\n- Recipient input for WhatsApp and Email channels\n- API URL configuration\n- Real-time responses from the Financial AI Assistant\n\n### Example \n```bash\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/ask' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"query\": \"What happens if the market crashes?\",\n  \"channel\": \"chat\"\n}'\n{\"response\":\"Here's what I found about 'What happens if the market crashes?':\\n\\nWe recommend a diversified long-term investment strategy. Our advisory team is available to help you adjust your portfolio as needed during market volatility.\\n\\nWe offer a comprehensive range of investment services including: stocks and bonds trading, mutual funds, ETFs, retirement planning (401k, IRA), wealth management, and personalized portfolio advisory services.\\n\\nTo start investing: 1) Create an account online or talk to an advisor, 2) Choose your investment strategy, 3) Fund your account, 4) Begin investing with our guidance.\\n\\nSource: FAQ\"}\n```\n\n### Making Requests\n\n```bash\n# Chat channel example\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/ask' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"query\": \"What are the benefits of a Roth IRA?\",\n  \"channel\": \"chat\"\n}'\n\n# WhatsApp channel example\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/ask' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"query\": \"What are your investment services?\",\n  \"channel\": \"whatsapp\",\n  \"recipient\": \"+1234567890\"\n}'\n\n# Email channel example\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/ask' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"query\": \"How do I open an account?\",\n  \"channel\": \"email\",\n  \"recipient\": \"customer@example.com\"\n}'\n```\n\n## Docker Deployment\n\n1. **Build the Docker image**\n   ```bash\n   docker build -t financial_ai_agent .\n   ```\n\n2. **Run with Docker**\n   ```bash\n   docker run -d -p 8000:8000 --name financial_ai_agent financial_ai_agent\n   ```\n\n3. **Using Docker Compose**\n   ```bash\n   docker-compose up -d\n   ```\n\n4. **Scaling with Docker Compose**\n   ```bash\n   docker-compose up -d --scale financial_ai_agent=3\n   ```\n\n## Cloud Deployment Options\n\n### AWS Deployment\n1. Push Docker image to Amazon ECR\n2. Deploy using ECS or EKS\n3. Set up API Gateway and load balancer\n\n### Google Cloud Deployment\n1. Push Docker image to Google Container Registry\n2. Deploy using Google Cloud Run or GKE\n3. Set up Cloud Endpoints for API management\n\n### Azure Deployment\n1. Push Docker image to Azure Container Registry\n2. Deploy using Azure Container Instances or AKS\n3. Set up API Management\n\n## Enhancement Opportunities\n\n### Short-term Improvements\n1. **Conversation Memory**: Add session management to remember context from previous questions\n2. **User Authentication**: Implement secure authentication for personalized responses\n3. **Response Templates**: Create customizable templates for different types of financial queries\n4. **Feedback Loop**: Add user feedback mechanism to improve responses over time\n5. **Analytics Dashboard**: Track usage patterns and common questions\n\n### Medium-term Enhancements\n1. **Multi-language Support**: Add capability to handle queries in multiple languages\n2. **Voice Interface**: Integrate with voice assistants or phone systems\n3. **Personalization Engine**: Tailor responses based on user profile and history\n4. **Advanced Security**: Implement additional security measures for handling sensitive financial data\n5. **A/B Testing Framework**: Test different response formats for effectiveness\n\n### Long-term Vision\n1. **Predictive Capabilities**: Anticipate customer needs based on patterns and data\n2. **Financial Planning Tools**: Integrate calculators and planning tools into responses\n3. **Omnichannel Experience**: Seamless transition between channels while maintaining context\n4. **Regulatory Compliance Engine**: Automated checks for financial advice compliance\n5. **Integration with Core Banking Systems**: Direct access to customer account information\n\n## Monitoring and Maintenance\n\n### Logging\n- Application logs are stored in the `logs/` directory\n- Use log rotation to manage log files\n\n### Monitoring\n- Implement health checks at `/health` endpoint\n- Set up alerts for error rates and response times\n\n### Updating the Knowledge Base\n1. Add new content to the data files\n2. Run the embedding process to update the vector database\n3. Restart the application to load the updated knowledge base\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Contact\n\nFor any questions or support, please contact [your-email@example.com](mailto:your-email@example.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farifazim%2Ffinancial_ai_assistant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farifazim%2Ffinancial_ai_assistant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farifazim%2Ffinancial_ai_assistant/lists"}