Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/ /
Atlas Architecture Center
/ / /

Unified Commerce with Smart Search

Use cases: Intelligent Search, Single View, Catalog

Industries: Retail

Products: MongoDB Atlas, MongoDB Atlas Search, MongoDB Atlas Vector Search, Voyage AI Embeddings

Activating data is a challenge in many industries. Unified Commerce combines data across multiple channels into an operational layer to deliver accurate, and accessible information to internal teams and customer applications.

A unified commerce strategy requirements

Figure 1. Unified commerce strategy

With this solution, you can build a store associate application with MongoDB as the ODL for a Unified Commerce strategy. This solution delivers better customer experiences and enables inventory visibility, advanced search, and geospatial queries.

To achieve these benefits, you first need first to break down siloed systems.

Retailers often use siloed systems, meaning that data is stored in different platforms and technologies. This fragmentation limits visibility and makes it difficult for store associates to access real-time information. As a result, answering customers' questions relies on other departments and outdated systems.

Store associates also have to manually check the stockroom, leading to delays and incorrect information. These inefficiencies erode customer trust and damage the customer experience.

An ODL combines data from existing systems like inventory, orders, and customer profiles, and makes it available in a unified layer. MongoDB Atlas serves as the ODL. Its flexible document model handles diverse, complex data structures from different systems and evolves as the business changes. This capacity unifies data without rigid schemas or complex transformations.

Storing your data in MongoDB drives innovation in the following ways:

  • Built-in search and AI capabilities: Native full-text, vector, and hybrid search capabilities enable in-house innovation, such as smart product discovery and personalized recommendations. This data foundation also powers RAG, LLM-based assistants and multi-agent systems.

  • The tech stack gets simplified: MongoDB stores both operational data and vector embeddings in a single place, reducing complexity and eliminating single-purpose tools like vector databases or search engines.

  • Real-time access to unified data: Applications can easily connect to MongoDB Atlas to consume real-time, synchronized data for store associates.

A unified commerce strategy requirements

Figure 2. The three layers in every application

Retail environments are dynamic, with product details and inventory changing constantly. MongoDB’s flexible document model easily manages store configurations, including geospatial, time-series, and hierarchical data. This creates a strong foundation for unified commerce.

Essential capabilities for an ODL include a flexible model, live sync and smart search

Figure 3. ODL essentials: Flexible model, live sync, smart search

This solution balances simplicity and performance, allowing you to model operational and search data for retail use cases. Here’s how data is modeled:

  • A canonical inventory collection tracks real-time stock data for each product across stores, optimized for high-frequency writes.

  • A read-optimized products collection embeds a lightweight inventorySummary array with store-level availability. This is ideal for fast filtering, UI rendering, and search queries.

  • A trigger-based sync keeps inventory summaries fresh in real time, using MongoDB Atlas Triggers.

Product schema: text, metadata and vectors

Figure 4. Product schema: Text, metadata and vectors

This schema is validated for performance in the 50-store range. For larger scale scenarios, you can adapt the model as follows:

  • Fetch store-level inventory dynamically as part of the query.

  • Restructure write and read paths with other modeling strategies.

This demo uses a main application in Next.js and a dedicated advanced search microservice. The demo contains the following components:

  • MongoDB Atlas: Centralizes all data, enables real-time sync, and provides the infrastructure for performance, availability, and security.

  • Main application with Next.js: Full-stack app that handles the UI and geospatial querying to find nearby stores with available stock.

  • Advanced search microservice with FastAPI: A dedicated backend that handles all search types, such as text, semantic, and hybrid, and coordinates query embedding.

  • Embedding provider with Voyage AI: Generates vector embeddings for semantic search.

System diagram of store associate app with MongoDB and Voyage AI

Figure 5. Behind the demo: System diagram of store associate app with MongoDB and Voyage AI

In particular, the advanced search microservice makes the demo logic clearer and adaptable. This setup offers the following benefits:

  • Layered design: This solution uses a microservice that is composed of interfaces for the API, an application for the business logic, and infrastructure for integration with MongoDB and Voyage AI. This structure keeps the codebase modular, making it easier to test, scale, and adapt. You can also replace external services, such as switching from Voyage AI to Bedrock, by updating only the infrastructure layer.

  • AI flexibility: The ability to switch between providers such as Voyage AI or Bedrock using one adapter.

  • Multichannel compatibility: A single API that supports all frontend platforms, including web, mobile and chatbots, bringing channels online with minimal effort.

The search microservice provides one unified API to handle multiple retrieval mechanisms, including:

  • Regex search: Basic pattern matching used as a baseline to compare against MongoDB’s advanced search features.

  • Full-text search: Uses MongoDB Atlas Search for fuzzy matches, boosted fields, and store-level filtering.

  • Semantic vector search: Finds conceptually-similar products using Voyage AI embeddings.

  • Hybrid search: Blends text and vector results using RRF. Adjusts the weight of text and semantic relevance based on search context.

Search strategy breakdown: Text, vectors, and hybrid search

Figure 6. Search strategy breakdown: Text, vectors, and hybrid search

You can learn how to use the aggregation framework to customize search capabilities by reviewing these files.

With MongoDB, you unify search capabilities in one platform, combining precision, semantic understanding, and real-time data. As a result, you serve shoppers faster, empower store teams, and scale across all channels.

To reproduce this demo in your own environment, follow these steps:

1

Sign in to MongoDB Atlas.

Spin up a Free Tier cluster.

Create a database named retail-unified-commerce, or update your .env if you're using another name.

2

Clone this GitHub repository by running the command below.

git clone https://github.com/mongodb-industry-solutions/retail-unified-commerce.git
3

After cloning the repo, navigate to the folder with the sample data.

cd retail-unified-commerce/docs/setup/collections

There, you find the JSON files to import into MongoDB Atlas — a sample dataset of 500 grocery products with store-level inventory and vectors embedding from Voyage AI:

  • inventory.json

  • products.json

  • stores.json

In Atlas, go to Browse Collections. Create each collection, then click Add Data to insert your documents from the JSON files.

4

On the products collection, create:

On the stores collection, create a geospatial index.

5

Add the inventory_sync and the daily_inventory_simulation Atlas Triggers to integrate real-time updates in your inventory collection. These features simulate live transactions and keep the data in sync with the products collection.

6

Copy each .env.example file to .env in both the frontend and advanced-search-ms directories.

Paste your Atlas connection string and add your VoyageAI API key in the advanced-search-ms/.env file to enable embedding-based search.

VOYAGE_API_KEY=your_voyage_api_key

To ensure accurate and meaningful vector comparisons, use the same embedding provider for both your data and user queries. If you switch providers, you must re-generate vectors, create a new index, update the .env file with the new API key, and adjust the implementation of the embedding port in the infrastructure layer.

7

Verify that you have Docker and Docker Compose installed, and that you're in the root of the project folder retail-unified-commerce. From there, start the app with the command below.

make build

After the app is running:

You can use these commands to control your Docker deployment:

  • Stop your app: Stop all containers and remove images with the following command:

    make clean
  • View logs: Track your app deployment and visualize how your data moves across layers with the following command:

    make logs
  • Unified commerce builds trust in-store: MongoDB enables real-time access to shelf status, stock location, and replenishment data. By combining intelligent search with cross-channel visibility, you give store associates the tools to deliver consistent and informed services that drive trust and customer conversion.

  • An ODL turns fragmented data into actionable insights: MongoDB acts as the ODL, consolidating siloed data into one real-time source. Its flexible document model adapts to diverse retail structures, and its built-in security, availability, and performance make it enterprise-grade.

  • Unified data enables advanced search and AI applications: MongoDB unifies full-text, semantic, and geospatial search in one place. You can also store your live data and embeddings together, enabling real-time discovery and powering intelligent AI use cases for the future.

  • Prashant Juttukonda, MongoDB

  • Florencia Arin, MongoDB

  • Angie Guemes, MongoDB

  • Diego Canales, MongoDB

Back

RFID Product Tracking

On this page