A FastAPI-based solution for matching transactions to users and semantic search of transaction descriptions.
pip install -r requirements.txtuvicorn app.main:app --reloadThe API will be available at http://localhost:8000
Visit http://localhost:8000/docs for interactive Swagger documentation.
GET /api/v1/match/{transaction_id}
Returns users matching the transaction description with fuzzy matching.
Response:
{
"users": [
{"id": "U4NNQUQIeE", "match_metric": 95.24},
{"id": "U4Pps5wQzx", "match_metric": 62.5}
],
"total_number_of_matches": 2
}
Proof : POST /api/v1/semantic-search
Returns transactions with similar descriptions using embeddings.
Example:
curl -X POST http://localhost:8000/api/v1/semantic-search \
-H "Content-Type: application/json" \
-d '{"query": "payment from consultant", "top_k": 5}'Response:
{
"transactions": [
{"id": "txn_001", "embedding": [0.123, -0.456, ...]},
{"id": "txn_002", "embedding": [0.234, -0.567, ...]}
],
"total_number_of_tokens_used": 1523
}
Approach:
- Extracts names from transaction descriptions using regex patterns
- Normalizes names by removing special characters and converting to lowercase
- Uses RapidFuzz library with three similarity metrics:
- ratio: Full string comparison
- partial_ratio: Substring matching (handles extra words)
- token_sort_ratio: Word-order independent matching
- Returns matches above 60% threshold, sorted by relevance
Limitations:
- Name Extraction: Regex patterns may miss non-standard formats or non-Latin characters
- Cultural Names: Multi-part names (e.g., Chinese, Arabic) may not match well
- Nicknames: "Bob" vs "Robert" won't match without a dictionary
- Performance: O(n) complexity for each transaction (scales with user count)
- Threshold Tuning: Fixed 60% threshold may need adjustment per use case
Edge Cases Handled:
- Typos (e.g., "Jhn Smith" → "John Smith")
- Extra spaces and punctuation
- Case sensitivity
- Missing data (empty names)
Approach:
- Uses Sentence-BERT model (
all-MiniLM-L6-v2) for generating embeddings - Computes cosine similarity between query and transaction descriptions
- Returns top-k most similar transactions with their embeddings
- Tracks total token count across all embeddings
Limitations:
- Performance: Encodes every transaction on each request (no caching)
- Memory: Stores full embeddings (384 dimensions) in response payload
- Model Size: ~80MB model download on first run
- Context Length: Limited to 256 tokens per transaction
- Language: Model primarily trained on English text
- Cold Start: First request is slow due to model loading
Potential Improvements:
- Pre-compute and cache transaction embeddings
- Use vector database (Pinecone, Weaviate) for efficient similarity search
- Return similarity scores instead of full embeddings
- Support multilingual models for international transactions
-
Database Integration
- Replace CSV files with PostgreSQL/MongoDB
- Index transaction IDs and user names
- Use connection pooling
-
Caching Layer
- Redis for frequently accessed transactions
- Pre-compute and cache embeddings
- Cache user matching results (with TTL)
-
Vector Database
- Use Pinecone/Weaviate/Qdrant for embedding storage
- Enable ANN (Approximate Nearest Neighbor) search
- Reduce search latency from O(n) to O(log n)
-
Model Optimization
- Use ONNX Runtime for 2-3x faster inference
- Quantize model to reduce size
- Batch process embeddings
- Consider smaller models for latency-critical paths
-
Async Processing
- Make embedding generation async
- Use worker queues (Celery) for batch processing
- WebSocket for real-time updates
-
Horizontal Scaling
- Containerize with Docker
- Deploy on Kubernetes
- Load balancing across multiple instances
- Separate read/write endpoints
-
Monitoring
- Prometheus + Grafana for metrics
- Track match quality, latency, throughput
- Alert on model degradation
- Log failed matches for retraining
-
Name Normalization Pipeline
- Add nickname/alias dictionary
- Handle international name formats
- Phonetic matching (Metaphone/Soundex)
- Entity resolution for duplicates
-
Model Improvements
- Fine-tune on Deel transaction data
- Active learning for edge cases
- A/B test different embedding models
- Ensemble multiple models
-
Authentication
- API key authentication
- OAuth2/JWT tokens
- Rate limiting per client
-
Data Privacy
- PII masking in logs
- Encryption at rest and in transit
- GDPR compliance for user data
- Audit trails