Skip to main content

View Source Code

Check out the full source code for this example on GitHub.
This tutorial demonstrates how to build a production-grade Web Scraper that crawls websites, processes content into clean Markdown, generates embeddings using Voyage AI, and stores them in MongoDB Atlas Vector Search.

Overview

This application showcases the power of Tensorlake’s parallel processing capabilities:
  1. Parallel Crawling: Uses Breadth-First Search (BFS) with Tensorlake’s .map() to fetch multiple pages concurrently at each depth level.
  2. Headless Browsing: Utilizes PyDoll (based on Chromium) to render JavaScript-heavy websites.
  3. Content Cleaning: Converts HTML and PDFs to clean Markdown, automatically removing boilerplate like headers, footers, and ads.
  4. Vector Embeddings: Generates high-quality embeddings for document chunks using Voyage AI.
  5. Vector Search: Stores the processed chunks and embeddings directly into MongoDB Atlas for RAG applications.

Prerequisites

  • Python 3.11+
  • Tensorlake Account and CLI installed.
  • MongoDB Atlas cluster URI.
  • Voyage AI API Key.

Implementation

The application is defined in a single file, scraper_to_atlas.py. It defines two custom runtime images: one for scraping (with Chromium) and one for embedding (lightweight).

1. Define Dependencies and Images

2. Main Scraping Logic (scraper_to_atlas.py)

The @application entry point orchestrates the crawling process. It manages the BFS queue and dispatches parallel tasks using fetch_and_convert.map().

3. Page Fetching and Conversion

The fetch_and_convert function runs in the scraper_image and uses PyDoll to render pages.

4. Embedding and Storage

The embed_and_store function runs in the embedding_image and handles interaction with Voyage AI and MongoDB.

Running Locally

  1. Set your environment variables:
  2. Run the application:

Deploying to Tensorlake

Deploy your scalable scraper to the cloud.
Your scraper will now run in the cloud, automatically scaling to handle hundreds of pages in parallel!