feat(#156): implement AI-driven fraud detection#174
Open
Robinsonchiziterem wants to merge 2 commits intoPulsefy:mainfrom
Open
feat(#156): implement AI-driven fraud detection#174Robinsonchiziterem wants to merge 2 commits intoPulsefy:mainfrom
Robinsonchiziterem wants to merge 2 commits intoPulsefy:mainfrom
Conversation
|
@Robinsonchiziterem Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
This issues is a python issue for ai-service, once the /ai-service is setup. Kindly reimplement |
Author
Working on it right now |
Contributor
|
Please pull main and do your implementation afresh in /ai-service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #156 AI-Driven Fraud Detection (Anomalous Pattern Analysis)
Description
This PR implements anomaly detection for claims to automatically flag suspicious clusters (e.g., identical IPs or repeated evidence submissions). It introduces a new Python-based microservice to process features from claims using scikit-learn and integrates batch detection into the existing NestJS backend.
Key Changes:
Database Schema: Added ipAddress and fraudRiskScore to the Prisma
Claim
model.
NestJS Backend (
FraudModule
):
Modified
CreateClaimDto
and
ClaimsService
to capture the claimant's IP address upon creation.
Added
FraudService
capable of batching up to 100 pending claims alongside 500 historical (scored) claims. Submits the combined payload for clustering to accurately compare new metadata against historical data.
Saves the computed fraudRiskScore back to the respective pending claims without modifying historical ones.
Python ML Service (app/ai-service):
Built a lightweight FastAPI service exposing POST /analyze-batch.
Uses DBSCAN to cluster claim features based on standardized values (amount, IP hash, and evidence hash).
Identifies outliers and abnormally tight clusters. Entities forming clusters with extremely high purity on IP or evidence reference are assigned high-risk fraud scores (0.95 and 0.99).
Testing:
Covered FraudService batching logic with appropriate Jest unit tests overriding PrismaService and HttpService to emulate the historical comparison successfully.
Impacted Areas
app/backend/prisma/schema.prisma
app/backend/src/claims/
app/backend/src/fraud/ (New)
app/backend/src/app.module.ts
app/ai-service/ (New)
Checklist
Database changes logically implemented in schema.prisma.
NestJS structure complies with existing repository conventions.
Unit tests expanded locally on fraud.service.spec.ts.
Model cleanly segregates pure and distinct datasets.
Closes #156