Rag System Mongodb Atlas
Captured source
source ↗Building Enterprise-Scale RAG Systems with Fireworks AI and MongoDB Atlas
GLM 5.2 is live! Opus-level intelligence at open-source rates. Pay per token on serverless. Try it today.
Blog
RAG System Mongodb Atlas Building Enterprise-Scale RAG Systems with Fireworks AI and MongoDB Atlas
PUBLISHED 4/9/2025
Table of Contents Why Enterprises Need RAG High-Level Architecture Performance & Fireworks Metrics Future Additions & Scalability Advantages of the Fireworks + MongoDB Atlas Stack Conclusion & Call-to-Action
Table of Contents
This project is completely open-source, including all documentation, code, and tests, which can be found at: https://github.com/shubcodes/earnings-ai-demo
In the fast-paced world of enterprise data, extracting actionable insights from vast amounts of unstructured information is a challenge many organizations face. Whether it’s earnings calls, financial reports, legal documents, or technical specifications, the ability to retrieve, synthesize, and act on this information quickly can make or break a company’s competitive edge. Enter Retrieval-Augmented Generation (RAG) – a cutting-edge solution combining Large Language Models (LLMs) with powerful retrieval systems to deliver contextually rich, actionable insights in real time. Why Enterprises Need RAG
Let’s face it: traditional search systems just don’t cut it anymore. They’re limited to keyword matching and fail to grasp the semantic and contextual relationships necessary for enterprise-scale decision-making. Here’s why RAG stands out: Multi-Format Analysis : RAG handles data from PDFs, Word documents, spreadsheets, and even audio recordings, breaking silos between formats. Cross-Document Insights : It synthesizes information across multiple documents, answering complex queries like “How has our AI strategy evolved over the last three earnings calls?” Real-Time Results : Sub-second query responses empower businesses to act on insights immediately. Natural Language Interaction : With RAG, asking questions feels intuitive, like speaking to a knowledgeable colleague.
High-Level Architecture
Our enterprise RAG system is built using Fireworks AI for inference and MongoDB Atlas for vector storage. Here’s an overview of the pipeline: Document Processing Pipeline The ability to process diverse document formats is the cornerstone of any robust RAG system. Without this capability, organizations are left with data silos and limited insights. The document processing pipeline ensures that content from PDFs, DOCX files, and plain text is not only extracted but also enriched with metadata for better querying. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 class DocumentExtractor : def extract_text ( self , file_path : str ) - > Dict : path = Path ( file_path ) if path . suffix . lower ( ) == '.pdf' : text = self . _extract_pdf ( path ) elif path . suffix . lower ( ) == '.docx' : text = self . _extract_docx ( path ) else : text = path . read_text ( encoding = 'utf-8' )
return { "text" : text , "metadata" : { "filename" : path . name , "file_type" : path . suffix . lower ( ) [ 1 : ] , "file_size" : path . stat ( ) . st_size } }
Key Features : • Format-Specific Processing : Handles PDFs, DOCX, and text files with tailored methods. • Metadata Preservation : Retains file context for better querying. • Error Handling : Detects and logs corrupt or unsupported files.
Audio Transcription with Fireworks Whisper V3 Turbo
Efficient transcription of audio content is another vital component. Fireworks’ Whisper V3 Turbo can transcribe one hour of audio in just 3 seconds, making it 20x faster than competing solutions such as OpenAI Whisper. This speed advantage significantly reduces latency and enhances user experiences. 1 2 3 4 5 6 7 8 9 10 11 class AudioTranscriber : def __init__ ( self , api_key : str , base_url : str = "https://api.fireworks.ai/audio/v3-turbo" ) : self . client = AudioInference ( api_key = api_key , base_url = base_url )
def transcribe_audio ( self , file_path : str ) - > Dict : with open ( file_path , 'rb' ) as audio_file : response = self . client . transcribe ( audio = audio_file . read ( ) ) return { "transcription" : response . text , "duration" : response . metadata . duration }
Key Advantages :
• Speed : Processes audio up to 900x faster than real-time. • Cost Efficiency : 10x cheaper than most alternatives. • Feature Completeness : Includes transcription alignment, translation, and preprocessing capabilities.
Vector Embedding
Once the content is extracted, converting it into vector embeddings allows the system to understand and process queries semantically. This step is critical for enabling similarity searches and advanced data retrieval. 1 2 3 4 5 6 7 8 def generate_document_embedding ( self , text : str , prefix : str = "" , method : str = "mean" ) - > List [ float ] : chunks = self . _chunk_text ( text ) chunk_embeddings = self . generate_embeddings_batch ( chunks , prefix )
if method == "mean" : return np . mean ( chunk_embeddings , axis = 0 ) . tolist ( ) elif method == "max" : return np . max ( chunk_embeddings , axis = 0 ) . tolist ( )
Why This Works :
Chunking : Splits documents into manageable parts while maintaining context. Batch Processing : Optimizes GPU utilization. Aggregation : Combines embeddings for holistic document representation.
MongoDB Atlas for Vector Search
Efficient storage and retrieval of vector embeddings ensure that enterprise systems can handle queries at scale without compromising performance. MongoDB Atlas provides a scalable, high-performance solution for this task. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 def query_similar ( self , query_embedding : List [ float ] , limit : int = 5 , filters : Dict = None ) - > List [ Dict ] : pipeline = [ { "$vectorSearch" : { "index" : "vector_index" , "queryVector" : query_embedding , "path" : "embeddings" , "numCandidates" : limit * 10 , "limit" : limit } } ]
if filters : pipeline . append ( { "$match" : filters } )
pipeline . append ( { "$project" : { "text" : 1 , "metadata" : 1 , "score" : { "$meta" : "vectorSearchScore" } } }
Fireworks AI: The Intelligence Layer
The intelligence of the RAG pipeline lies in its ability to synthesize information and generate coherent, actionable answers. Fireworks AI powers this layer, ensuring low-latency, high-accuracy responses. By integrating with MongoDB Atlas for semantic retrieval, Fireworks AI orchestrates an...
Excerpt shown — open the source for the full document.
Notability
notability 5.0/10Substantive RAG system post by Fireworks AI.