This tutorial was written by Shashank Pandey and Utsav Talwar of MongoDB.
As financial institutions and fintech companies look to enhance customer interactions, AI-powered chatbots have emerged as a crucial tool for automating and streamlining banking services. This guide walks through the implementation of a small business loan agent chatbot leveraging MongoDB Atlas, AWS, and Confluent Cloud to deliver intelligent, real-time customer assistance.
Why MongoDB Atlas?
MongoDB Atlas provides a scalable, cloud-native database with powerful capabilities like MongoDB Atlas Vector Search, making it an ideal choice for storing and retrieving structured and unstructured data efficiently. By leveraging MongoDB Atlas Vector Search, this chatbot can perform advanced semantic search, allowing for context-aware retrieval of loan documents and customer queries.
Architecture overview
This chatbot solution is designed to handle real-time customer queries, retrieve relevant loan information, and provide insightful responses using MongoDB Atlas, AWS Lambda, Confluent Cloud, and Anthropic Claude AI models. Below is an overview of how these components interact:
1. Document indexing with MongoDB Atlas
Data sources: The system can ingest loan-related data from multiple sources, including financial institutions, customer applications, and regulatory filings. These sources provide a mix of structured and unstructured data on which this application operates.
Summarization: Since loan-related documents are often lengthy and contain redundant information, AWS Bedrock’s Claude AI is used to summarize them. This step ensures that only the most relevant insights are retained for retrieval.
Vectorization: Summarised loan documents are converted into dense vector representations (embeddings) using Amazon Titan-Embed models to enhance search and retrieval. These embeddings capture the semantic meaning of the text, enabling:
-Contextual search beyond keyword-based matching.
-Similarity detection to find related documents, such as those with similar risk profiles or terms.
-Enhanced query understanding when users search for loan-related insights.
- Storage in MongoDB Atlas: Once the summarized data is transformed into embeddings, it is stored in MongoDB Atlas and queried using MongoDB Atlas Vector Search, which is optimized for high-speed, semantic retrieval of loan-related information. It enables:
-Fast similarity searches across millions of documents.
-Hybrid queries combining metadata filtering and vector search.
-Efficient indexing for scalable performance.
2. Chatbot query handling
User input: Customers interact with a chatbot embedded in a front-end application (e.g., a website, mobile app, or messaging platform). The chatbot serves as an intelligent assistant, handling loan-related queries such as loan eligibility criteria, application status tracking, interest rate comparisons, personalized loan recommendations, general financial guidance, etc.
Real-time processing via Confluent Cloud: User queries are sent as Apache Kafka® data streams for event-driven processing. The pipeline ensures:
-Asynchronous, event-driven processing, enabling real-time scalability.
-Fault tolerance, ensuring messages are processed reliably.
-Decoupling between components, making it easy to add new features without disrupting existing services.
Vector search in MongoDB Atlas: Once received, the user’s query undergoes vectorization using Amazon Titan-Embed models. This step converts the text into a dense numerical representation, allowing semantic search instead of simple keyword matching.
AI-powered response: Once received, the user’s query undergoes vectorization using Amazon Titan-Embed models. This step converts the text into a dense numerical representation, allowing semantic search instead of simple keyword matching.
Delivery to user: Responses are sent back in real-time using AWS API Gateway WebSockets.
Key technologies used
MongoDB Atlas
MongoDB Atlas Vector Search: Enables efficient semantic retrieval of loan documents.
Scalability: Handles large volumes of financial data with auto-scaling.
Security: Provides built-in encryption, access control, and auditing.
AWS
AWS Lambda: Serverless compute for processing chatbot requests.
Amazon Bedrock AI: Enables Claude AI for text summarization and response generation.
S3 and CloudFront: Used for hosting front-end interfaces and storing documents.
Confluent Cloud
Kafka topics: Handles event-driven processing of chatbot interactions.
Confluent Connector: A component of the Confluent Platform that enables seamless integration between Confluent Cloud and various external systems, such as databases, cloud services, and file systems including MongoDB. It facilitates real-time data streaming by providing pre-built connectors for efficient data ingestion and extraction, ensuring scalability and reliability in data pipelines.
Flink AI: Provides real-time AI inferencing capabilities.
Deployment requirements
Docker
The deployment script automates the entire setup; the only prerequisite is Docker. Follow the Get Docker instructions to install Docker on your system.
Git
You need to have Git installed on your system. Follow the installation guide.
Cloud service provider access keys
To authenticate with various cloud service providers (CSPs), you will need to obtain API keys.
Confluent Cloud
Steps to obtain a cloud resource management API key:
- Log in to your Confluent Cloud account. If you don’t have one, sign up.
- Click the hamburger menu (top-right corner) and select API Keys.
- Click on Add API Key.
- Click My Account and then Next (bottom-right).
- Optionally, enter a name and description for the key.
- Click Create API Key (bottom-right).
- Save the API key securely.
MongoDB Atlas
To authenticate with MongoDB Atlas, you need an API key with Organization Owner access.
Steps to generate an API key:
- Log in to the MongoDB Atlas UI.
- Ensure you have Organization Owner access.
- Navigate to Access Manager from the navigation bar.
- Click Organization Access in the sidebar.
- Select Add New → API Key.
- Enter a description in the API Key Information field.
- Under Organization Permissions, select Organization Owner.
- Make sure to unselect any other roles (e.g., Organization Member).
- Click Next, then copy the public and private keys and store them securely.
- Click Done.
Retrieve your Organization ID:
- Go to the Atlas UI and locate your Organization ID for authentication.
AWS
Enable foundation model access
To use Amazon Bedrock, enable access to the following foundation models via the AWS console:
- amazon.titan-embed-text-v2:0
- anthropic.claude-3-haiku-20240307-v1:0
AWS API keys
AWS credentials are required for Flink AI to connect to Amazon Bedrock and to deploy resources using Terraform. Ensure you have an AWS access key and secret with appropriate IAM permissions.
IAM permissions
For managed policies, attach the following IAM policies to your user/role:
- AmazonAPIGatewayAdministrator → Manages and creates the WebSocket API Gateway.
- CloudFrontFullAccess → Manages CloudFront for front-end exposure.
- IAMFullAccess → Manages roles and policies for AWS Lambda functions.
- AWSLambda_FullAccess → Provides full Lambda function management.
- CloudWatchFullAccess → Handles logs and metrics.
- AmazonS3FullAccess → Manages the S3 bucket for front end and Lambda storage.
- SecretsManagerReadWrite → Manages secrets for Lambda functions.
- AmazonBedrockStudioPermissionsBoundary → Grants access to invoke Bedrock foundation models.
For fine-tuned permissions:
- If you need granular permissions, refer to CloudTrail events to determine the exact resources and actions required.
Useful links:
- AWS API keys
- Bedrock IAM policies
- Lambda IAM policies
- Flink AI: Create model
- Using Bedrock with Flink AI
Run the quickstart
We have a GitHub repository for the gen AI chatbot quickstart.
This repository serves as a comprehensive guide to quickly deploying a fully functional chatbot for small business loan assistance. The solution integrates MongoDB Atlas, Confluent Cloud, AWS, Anthropic, and Flink to provide a scalable, intelligent, and real-time conversational experience.
> git clone https://github.com/confluentinc/mongodb-cflt-genai-quickstart
# Deploy the chatbot infrastructure
>./deploy.sh
→ The deployment script will prompt you to provide the following keys. Ensure that your AWS client is configured with the same region specified in AWS_REGION to avoid any issues.
→ After the deployment is complete, you should see something like this:
Interact with the chatbot
- Access the chatbot via the CloudFront URL generated during deployment.
- You will have a fully functional chatbot, enabling interactions and the following conversations:
Enhancing chatbot performance
To further refine the chatbot, consider:
- Increasing data size: Index more structured loan documents in MongoDB Atlas.
- Tuning AI prompts: Modify prompts used for Claude AI processing.
- Optimizing search queries: Fine-tune vector search parameters in MongoDB Atlas.
Cleanup reminder
Once you have completed testing and no longer need the environment, make sure to destroy it to avoid unnecessary costs and resource usage.
Run the following command to clean up your deployment:
# Destroy the chatbot infrastructure
>./destroy.sh
This will safely remove all resources associated with your deployment. Always ensure you have saved any necessary data before running this command.
Conclusion
By integrating MongoDB Atlas, AWS, and Confluent Cloud, this chatbot delivers an intelligent, real-time loan assistant that enhances financial customer engagement. MongoDB Atlas Vector Search enables fast, context-aware retrieval, while AWS and Confluent Cloud provide scalable compute and streaming capabilities.
Get started today!
Ready to build your own generative AI-powered chatbot? Follow our gen AI quickstart to start developing a chatbot with MongoDB Atlas and Confluent Cloud.
Not yet a MongoDB user? Deploy a free instance of MongoDB Atlas and explore how Atlas can power your AI-driven applications with ease.
Not yet a Confluent customer? Start your free trial of Confluent Cloud today! New users receive $400 to spend during their first 30 days.
Kickstart your journey with MongoDB Atlas and Confluent to unlock the power of real-time, AI-driven financial insights!
About the authors
Shashank is a Solutions Architect at MongoDB, with a focus on Solutions Consulting and Partner Solutions. He specializes in designing innovative, scalable architectures and harnessing MongoDB’s advanced features to deliver impactful solutions that drive success for both partners and clients.
Utsav is a Solutions Architect at MongoDB, blending deep expertise in Gen AI with modern data architectures. He specializes in building intelligent, scalable applications powered by vector search and LLMs.
Top comments (0)