Notebooks
M
MongoDB
Transaction Compliance Monitoring System With Document Ingestion

Transaction Compliance Monitoring System With Document Ingestion

agentsartificial-intelligencellmspartnersadamongodb-genai-showcasegenerative-airag

AI-Powered Transaction Compliance Monitoring System with Document Ingestion

Open In Colab

Use Case Overview

In today's global financial ecosystem, institutions face the daunting challenge of ensuring every cross-border transaction complies with an increasingly complex web of international regulations. Manual compliance checks create bottlenecks, increase operational costs, and leave organizations vulnerable to costly violations and reputational damage.

In this use case, we are showcasing the foundation of a compliance monitoring system that leverages MongoDB's vector search capabilities, Voyage AI embedding models, and advanced LLMs to automate regulatory checks on financial transactions. This implementation demonstrates how to build a scalable transaction compliance checker with the following components:

Core Components:

  1. Document Ingestion Pipeline
    • PDF, DOC, DOCX, and structured text document processing
    • Automated metadata tagging based on document content
  2. Data Layer (Operational and Vector Database) (MongoDB Atlas)
    • Storage for transaction data and regulatory policies with vector embeddings
    • Vector search index for semantic matching between transactions and applicable regulations
    • Checkpoint storage for LangGraph state management
    • Schema validation using Pydantic models
  3. NLP Processing Pipeline
    • Text embedding generation via Voyage AI
    • Chunking strategies
  4. Compliance Assessment Engine
    • ShieldGemma 9B model for transaction compliance evaluation against policies
    • Confidence scoring system for violation probability using softmax normalization
    • Threshold-based classification (Violation, Reporting Required, Compliant)
  5. Agent Orchestration Framework
    • LangGraph-based workflow for agent coordination and state management
    • Tool-calling pattern for modular assessment capabilities
    • Asynchronous processing with MongoDB checkpointing
[ ]
[2]

Setup Environment Variables

First, we need to set up our environment variables for connecting to MongoDB Atlas and various AI services. You'll need to provide your own API keys and connection strings.

[3]

MongoDB Atlas Connection

Let's establish a connection to MongoDB Atlas and set up our collections.

[4]
Successfully connected to MongoDB!
Created transactions collection with schema validation
Created regulations collection
Created checkpoints collection
Created checkpoint_writes collection
New search index named 'vector_index' is building.
Polling to check if the index is ready. This may take up to a minute.
vector_index is ready for querying.

Document Ingestion Pipeline

Now we'll create a document ingestion pipeline that can process various document formats (PDF, DOC, DOCX, and text) and extract their content for further processing.

[5]

Text Chunking and Embedding Generation

Now we'll implement text chunking strategies and generate embeddings using Voyage AI.

[ ]

Sample Regulatory Documents

Let's create some sample regulatory documents to demonstrate the system.

[7]
Rate limiting: waiting 20.00 seconds before next API call
Stored regulation document with ID: 680a57118cf2059167f7f13a
Processed and stored regulation: Anti-Money Laundering Directive
Rate limiting: waiting 19.84 seconds before next API call
Rate limiting: waiting 20.00 seconds before next API call
Stored regulation document with ID: 680a573a8cf2059167f7f13b
Processed and stored regulation: Sanctions Compliance Framework

Transaction Data Model

Let's define the data model for financial transactions that will be assessed for compliance.

[8]

Compliance Assessment Engine

Now we'll implement the compliance assessment engine that evaluates transactions against regulatory policies.

[9]

Agent Orchestration with LangGraph

Now we'll implement the agent orchestration framework using LangGraph to coordinate the compliance assessment workflow.

[10]

Demonstration: Processing Sample Transactions

Let's demonstrate the system by processing some sample transactions.

[11]
Loading checkpoint shards: 100%|██████████| 2/2 [00:04<00:00,  2.24s/it]
Device set to use mps

Processing transaction TX123456789...
System: Transaction TX123456789 parsed successfully.
System: Retrieved relevant regulations for compliance assessment.
System: Compliance assessment complete. Status: Reporting Required (Confidence: 0.55)
Reasoning: The transaction exceeds €10,000 and involves a cross-border transfer to a high-risk jurisdiction (United States). Therefore, enhanced due diligence is required.
Recommended actions: European Trading Ltd must perform enhanced due diligence on the transaction, including verifying the identity of both the sender and recipient., The transaction should be reported to the relevant authorities in both Germany and the United States.


Final Assessment for TX123456789:
Status: Reporting Required
Confidence: 0.55
Reasoning: The transaction exceeds €10,000 and involves a cross-border transfer to a high-risk jurisdiction (United States). Therefore, enhanced due diligence is required.
Risk Factors: High-risk jurisdiction (United States)
Applicable Regulations: Regulation 1: Anti-Money Laundering Directive, Regulation 2: Sanctions Compliance Framework
Recommended Actions: European Trading Ltd must perform enhanced due diligence on the transaction, including verifying the identity of both the sender and recipient., The transaction should be reported to the relevant authorities in both Germany and the United States.
--------------------------------------------------------------------------------

Processing transaction TX987654321...
System: Transaction TX987654321 parsed successfully.
System: Retrieved relevant regulations for compliance assessment.
System: Compliance assessment complete. Status: Violation (Confidence: 0.58)
Reasoning: The transaction involves a transfer to a sanctioned entity (Tehran Trading Co) in Iran, which is prohibited by the sanctions compliance framework.  Section 2.2 of the sanctions compliance framework explicitly states that transactions with entities in comprehensively sanctioned countries are prohibited without specific OFAC authorization.
Recommended actions: Obtain specific OFAC authorization for the transaction


Final Assessment for TX987654321:
Status: Violation
Confidence: 0.58
Reasoning: The transaction involves a transfer to a sanctioned entity (Tehran Trading Co) in Iran, which is prohibited by the sanctions compliance framework.  Section 2.2 of the sanctions compliance framework explicitly states that transactions with entities in comprehensively sanctioned countries are prohibited without specific OFAC authorization.
Risk Factors: Significant financial penalties, potential reputational damage, legal action
Applicable Regulations: Sanctions Compliance Framework, Regulation 1
Recommended Actions: Obtain specific OFAC authorization for the transaction
--------------------------------------------------------------------------------

Conclusion

In this notebook, we've demonstrated a comprehensive AI-powered transaction compliance monitoring system that leverages MongoDB's vector search capabilities, Voyage AI embeddings, and advanced LLMs to automate regulatory checks on financial transactions.

The system includes:

  1. A document ingestion pipeline for processing regulatory documents
  2. A MongoDB Atlas data layer for storing transactions, regulations, and vector embeddings
  3. An NLP processing pipeline for text chunking and embedding generation
  4. A compliance assessment engine for evaluating transactions against regulations
  5. A LangGraph-based agent orchestration framework for workflow management

This implementation provides a foundation that can be extended with additional features such as:

  • Real-time transaction monitoring
  • Integration with existing financial systems
  • Advanced risk scoring algorithms
  • Customizable compliance rules and thresholds
  • Audit trail and reporting capabilities

By automating compliance checks, financial institutions can reduce operational costs, minimize human error, and ensure consistent application of regulatory requirements across all transactions.