September 24, 20245 minute read
Hybrid Search over California Embeddings with Modal, MongoDB, and Clay

Data APIs, foundation models, serverless infrastructure from Modal, and the MongoDB Atlas data platform make a potent combination.

I used that stack for my first RAG chatbot app back in January of 2023. But the strength of this combination is deeper than just the latest tech fads.

To demonstrate the general power of this stack, I put together a very different kind of hybrid search app: search over the state of California based on timestamps, geolocation data, and satellite image embeddings (using a foundation model from Clay and Development Seed). Try it here, or check out the code and run it for yourself here.

search-california user interface

How does it work?

At a high level, here’s how signals from a satellite become results of a hybrid search query run by MongoDB and rendered in your browser, all orchestrated by Modal:

  1. Every few days, the European Space Agency’s Sentinel satellites collect images of the entire Earth. The images are uploaded to cloud storage and made available via an API.
  2. Every day, we query that API for new images in a specific area-of-interest — here, the state of California. Areas-of-interest defined in GeoJSON format are available for free on the Internet. We cache them in MongoDB.
  3. The responses of that API, also formatted as JSON documents, are uploaded to a MongoDB Atlas cluster.
  4. Asynchronously, that database is queried to find entries that do not have an associated embedding.
  5. Any entries without embeddings are communicated to a serverless embedding service running the Clay v1 foundation model for satellite imagery. We run the model’s forward pass on hundreds of sub-regions at once on A10 GPUs and merge them into a single embedding with a bit of custom PyTorch code.
  6. These embeddings are communicated back to the MongoDB Atlas cluster for storage.
  7. A small Alpine JS frontend client for querying this data in a UI is served via a simple static FastAPI server.
  8. That client sends hybrid search requests based on geo-location, image embedding, and timestamp to the MongoDB Atlas cluster.

This entire application — from API queries and data persistence to GPU inference and hybrid search — is delivered using nothing but Modal and MongoDB Atlas. Setting it up for yourself requires only credentials on these platforms and a few commands. See the full code for details.

Why Modal and MongoDB Atlas?

This hybrid satellite image search application is intended as a novel demonstration of the emerging category of applications that rely on data APIs and foundation models to drive compelling new experiences.

For these applications, Modal and MongoDB Atlas make for a natural pair due to their shared strengths.

  1. Versatility & Developer Experience

    Modal makes it easy to run heterogeneous Python workloads in the cloud. In our demo, we used it for everything from running small scheduled jobs to serving a database client to accelerating neural networks with GPUs.

    MongoDB Atlas also makes it easy to run diverse cloud storage and search services supporting diverse applications. The JSON document model reduces impedance mismatch between data APIs and data storage and provides a unified interface.

    Together, they enable iteration at the speed of thought.

  2. Scalability

    Modal’s serverless infrastructure scales with your workloads, so you only pay for the resources you need — and you have them when you need them. Customers like Suno serve applications at scale with Modal.

    MongoDB Atlas is built for scale, with built-in data tiering, point-in-time recovery, and rich telemetry. And like the Sentinel satellites, Atlas is worldwide: global data distribution, multi-cloud reach, and multi-region replication.

    Together, they ensure your compute and data infrastructure match your needs at any scale.

  3. AI and ML Capabilities

    Modal provides on-demand access to powerful GPUs, like NVIDIA H100s, that can run the latest foundation models. We back them up with easy-to-use but powerful cloud-native development primitives, like distributed dictionaries & queues and remote storage designed for large files.

    MongoDB Atlas provides flexible search (text, geospatial, vector) that can both power and be powered by contemporary foundation models. Atlas ties these capabilities to operational data, ensuring freshness and reliability.

    Together, they connect the most powerful hardware and intelligent models to your application and its data.

Ship your first app in minutes

with $30 / month free compute