Implement batch processing for LLM-based tax analysis and enhance match confidence scoring
This commit is contained in:
@@ -25,11 +25,36 @@ class MatchingEngine:
|
||||
receipts, transactions
|
||||
)
|
||||
|
||||
# Apply rules and enhance matches
|
||||
enhanced_matches = []
|
||||
# Apply traditional rules first (lightweight, no API calls)
|
||||
for match in ai_matches:
|
||||
enhanced_match = self._enhance_match_with_rules(match, user_location)
|
||||
enhanced_matches.append(enhanced_match)
|
||||
rule_results = self.rules_engine.apply_rules(
|
||||
match.receipt, match.transaction
|
||||
)
|
||||
|
||||
# Apply confidence boost from traditional rules
|
||||
if rule_results["confidence_boost"] > 0:
|
||||
match.confidence_score = min(
|
||||
1.0, match.confidence_score + rule_results["confidence_boost"]
|
||||
)
|
||||
|
||||
# Auto-approve if rules say so
|
||||
if rule_results["auto_approve"]:
|
||||
match.confidence_score = 1.0
|
||||
match.match_reason += " (Auto-approved by rules)"
|
||||
|
||||
# Now apply LLM-based tax analysis in a SINGLE batch call
|
||||
try:
|
||||
enhanced_matches = self.llm_tax_analyzer.analyze_and_apply_tax_rules_batch(
|
||||
ai_matches, user_location
|
||||
)
|
||||
except Exception as e:
|
||||
# If batch LLM analysis fails, log it and continue with matches as-is
|
||||
import logging
|
||||
|
||||
logging.error(f"Batch LLM tax analysis failed: {str(e)}")
|
||||
for match in ai_matches:
|
||||
match.match_reason += " (Note: Advanced tax analysis unavailable)"
|
||||
enhanced_matches = ai_matches
|
||||
|
||||
return enhanced_matches
|
||||
|
||||
|
||||
Reference in New Issue
Block a user