Skip to main content

MongoDB AI Playground

MongoDB AI Playground is a set of interactive widgets for to explore, test, and visualize MongoDB-powered AI capabilities in notebooks, including Retrieval-Augmented Generation (RAG) and GraphRAG workflows, using modern LLM and vector search integrations.


Overview

Screenshot MongoDB AI Playground

Built as a set of AnyWidget Jupyter widgets, this playground is designed for rapid prototyping, learning, and demonstration of GenAI + MongoDB workflows.

Prerequisites

  • An Atlas account with a cluster running MongoDB version 6.0.11, 7.0.2, or later (including release candidates). Ensure your IP address is included in your Atlas project's access list. To learn more, see Create a Cluster.
  • An environment to run interactive Python notebooks such as JupyterLab, Jupyter Notebook, Google Colab and VSCode. Make sure you have widget support enabled (it is enabled by default on most platforms).
  • Create a database and collection (if you choose to use an existing collection, usage with the playground will erase the collection's data. Providing a new collection is recommended)
  • Create an Atlas Vector Search index with the correct dimension associated with the embedding model you will use. The field containing the embedding must be named embedding.

Installation

pip install mongodb-ai-playground

Usage

RAG Playground

from mongodb_ai_playground import MongoDBRAGPlayground

# Example: Pass your own loader, embedding model, LLM, and MongoDB collection
widget = MongoDBRAGPlayground(
    loader=...,              # LangChain loader
    embedding_model=...,     # LangChain embedding model 
    llm=...,                 # LangChain Chat Model (LLM) for answering questions (OpenAI, Claude, DeepSeek, etc.)
    mongo_collection=...,    # PyMongo collection for storing vectors
    index_name=...           # Name of your Atlas Vector Search index, you need to create if you don't have one, with the correct dimension (field containing the embedding is 'embedding')
)
widget # Display the playground widget
  • All interactions are performed via the interactive UI in Jupyter-compatible environments.
  • Visualize chunking, embeddings, vector search results, and question answering.

Notebook examples

Description Link
Wikipedia data + Voyage AI embedding + OpenAI LLM Open In Colab

Development

Setup

To set up the environment for development, clone the repository and install the package in editable mode. This allows changes to the Python code and the JavaScript/CSS (via anywidget's live reloading) to be reflected immediately.

# Clone the repository
git clone https://github.com/mongodb-developer/mongodb-ai-playground.git
cd mongodb-ai-playground

# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

# Install in editable mode
pip install -e .

Testing in a Notebook

To test the widget during development:

  1. Start JupyterLab or Jupyter Notebook:
    pip install jupyterlab
    jupyter lab
    
  2. Open the example notebook in examples/mongodb_rag_playground_wiki_voyageai_openai.ipynb.
  3. Ensure you have the necessary environment variables or credentials set up (Atlas connection string, OpenAI API key, etc.) as described in the notebook.
  4. Run the notebook cells to interact with the widget. Changes to mongodb_ai_playground/index.js or mongodb_ai_playground/index.css will be reflected upon refreshing the page or re-running the widget cell.

Building the Package

To build the package for distribution (creating .tar.gz and .whl files):

  1. Install the build tool:
    pip install build
    
  2. Run the build command from the root of the repository:
    python -m build
    
  3. The build artifacts will be generated in the dist/ directory.

Features

  • 📄 Document Chunking: Flexible strategies (fixed, recursive, markdown) for splitting documents.
  • 🧠 Embeddings & Vector Search: Store and search embeddings in MongoDB Atlas using langchain-mongodb.
  • 🔎 RAG Playground UI: Step-by-step interface for chunking, embedding, and querying.
  • 🕸️ Knowledge Graph RAG: Build and visualize entity/relation graphs from docs and run graph-based QA.
  • 🧩 Extensible: Built for experimentation with LangChain so that you can use different loaders, embeddings models, LLMs and more.

Project Structure

mongodb_ai_playground/
├── rag_widget.py         # RAG playground widget (chunking, embedding, RAG)
├── graphrag_widget.py    # Graph RAG playground widget (graph ingest, QA)
├── index.js              # JS frontend for RAG widget
├── graphrag.js           # JS frontend for Graph RAG widget
├── index.css             # Shared widget styles
├── __init__.py           # Exports widgets
...

Requirements

  • Python 3.7+
  • Jupyter widget compatible environments (JupyterLab, Jupyter Notebook, Colab, Marimo, etc.)
  • MongoDB Atlas deployment (for vector/graph storage)
  • Any LLM and embedding model using LangChain components (OpenAI, HuggingFace, etc.)

License

This project is licensed under the MIT License.

Acknowledgments

Additional Resources

Metadata

Release files for mongodb-ai-widgets 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongodb-ai-widgets 0.1.12
File Size Uploaded
mongodb_ai_widgets-0.1.12.tar.gz 611.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongodb-ai-widgets 0.1.12
File Interpreter ABI Platform
mongodb_ai_widgets-0.1.12-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / mongodb_ai_widgets-0.1.12.tar.gz

Download URL mongodb_ai_widgets-0.1.12.tar.gz
Size 611.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fe21801adb37039f1c161159d5e6d8cb5aebeee50ba30d2652135a6195683817
BLAKE2b-256 checksum
How to use checksums
a5c81f2a3ec298b68c891056f39d440ea4d4ec6fdadb92793cf300ba2573ca60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / mongodb_ai_widgets-0.1.12-py3-none-any.whl

Download URL mongodb_ai_widgets-0.1.12-py3-none-any.whl
Size 617.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8ca971c807f2087be796d8647e7ee2261bdf3c1357660be0c9ba003ad7915a6
BLAKE2b-256 checksum
How to use checksums
eca53e12f915e1339e1aa6b4b7128c7c97598a23aba92ae820f0bd9d799ffea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page