Overview
FinAI uses Google Gemini 2.5 Flash to automatically categorize your transactions. The AI learns from YOUR personal category structure and suggests the most appropriate category with a confidence score.How It Works
The AI categorization engine is powered by Google’s Gemini 2.5 Flash model through the official Google GenAI SDK:The system uses Gemini 2.5 Flash (not 2.0) as specified in
app/ai_service.py:22. This model provides fast, accurate categorization with low latency.Prediction Flow
User Enters Transaction Description
When creating a transaction, you type a description like “Mua xăng ở Petrolimex”
System Fetches User's Categories
The backend retrieves YOUR personal category list (
app/routes/ai.py:36-37):AI Analyzes and Predicts
The AI engine receives the description and your category menu, then predicts the best match.
The Prediction Prompt
The AI receives a carefully crafted prompt that enforces strict categorization rules:Enforcing JSON Response
To ensure consistent parsing, the system uses structured JSON output mode:Safety Checks
The system validates AI predictions to prevent errors:If the AI suggests a category that doesn’t exist in your personal list, the system automatically defaults to “Khác” (Other).
Personalized Learning
Unlike generic expense trackers, FinAI’s AI is personalized to YOUR categories:Example: Two users, different results
Example: Two users, different results
User A’s categories:
User B’s categories:
The AI adapts to each user’s personal categorization system, providing more relevant suggestions.
Ăn uống, Xăng xe, Học phíTransaction: “Mua sách lập trình”AI prediction: “Học phí” (95% confidence)User B’s categories:
Ăn uống, Xăng xe, Sách vở, Học phíTransaction: “Mua sách lập trình”AI prediction: “Sách vở” (98% confidence)The AI adapts to each user’s personal categorization system, providing more relevant suggestions.
Integration with Transactions
When you create a transaction, the AI prediction is stored alongside your final choice:AI Accuracy Tracking
The system includes anAILog model to track prediction accuracy:
Error Handling
If the AI service fails, the system gracefully degrades:- The API returns
{"status": "no_match"}(app/routes/ai.py:61) - Users can manually select a category
- The transaction still saves successfully
API Reference
Predict Category
Configuration
The AI service requires a Google Gemini API key in your environment:python-dotenv (app/ai_service.py:13).
Performance Characteristics
Model
Google Gemini 2.5 Flash
Response Time
~200-500ms average
Output Format
Structured JSON
Context Length
User categories + description
Best Practices
Create Descriptive Categories
Create Descriptive Categories
The more specific your categories, the better the AI can distinguish between them.Good:
Cafe, Nhà hàng, Siêu thịLess effective: Ăn uống (too broad)Provide Clear Descriptions
Provide Clear Descriptions
Include specific details in transaction descriptions:Good: “Mua xăng tại Petrolimex Q1”Less effective: “Đổ xăng”
Review AI Suggestions
Review AI Suggestions
Always review the AI’s suggestion before confirming. The confidence score helps you gauge reliability:
- 90-100%: Very likely correct
- 70-89%: Probably correct, worth reviewing
- Below 70%: Less certain, should verify
Related Features
- Transactions - Where AI predictions are applied
- Chatbot - Natural language financial assistant
- Reports - Analyze categorized spending patterns
