This demonstration showcases MongoDB's Vector Search capabilities for anomaly detection using sound input. We use a handheld fan as a proxy for a wind turbine, enabling real-time diagnostics of its condition—whether it's operating normally, stopped, or experiencing issues.
- Prerequisites
- Setup Options
- Unified
.env
File - Option 1: Run with Docker Compose
- Option 2: Run Without Docker
- Unified
- MongoDB Atlas Configuration
- Atlas Charts
- Troubleshooting
-
- Usage: Node.js is used to run our frontend, which powers the user interface and interactions of the demo.
- Installation:
- macOS:
- Install using Homebrew:
brew install node
- Install using Homebrew:
- macOS:
-
- Usage: Python is used for our backend. It handles tasks like audio processing, data processing, and interacting with MongoDB Atlas.
- Installation:
- macOS:
- Install using Homebrew:
brew install python
- Install using Homebrew:
- macOS:
-
- Usage: We are using MongoDB Atlas to store sound embeddings and other data, and to facilitate search capabilities via vector similarity.
- Setup:
- Create an account at MongoDB Atlas.
- Once created, set up a cluster, and obtain the connection string which will be used in the
.env
file.
-
- Usage: FFmpeg is used for audio processing, specifically to convert and manipulate audio files, which is a crucial part of diagnosing the wind turbine’s condition.
- Installation:
- macOS:
- Install using Homebrew:
brew install ffmpeg
- Install using Homebrew:
- macOS:
-
- Usage:
wget
is used to download the model files that are essential for audio inference in this project. - Installation:
- macOS:
- Install using Homebrew:
brew install wget
- Install using Homebrew:
- macOS:
- Usage:
-
- Usage: Docker is used to containerize the application, enabling consistent and easy deployment of the entire stack.
- Installation:
- macOS:
- Install using Homebrew:
brew install --cask docker
- Install using Homebrew:
- macOS:
Choose one of the following two ways to set up and run the demo.
A default .env
file has been created in the root directory of the project. To set it up:
- Open the
.env
file located in the root directory. - Edit the line for
MONGODB_URI
to include your MongoDB Atlas connection string:MONGODB_URI="mongodb+srv://<your-atlas-connection-string>"
- Clone the repository and navigate to the project folder.
- Go to the
.env
file in the root directory and add your MongoDB Atlas connection string:- Example:
MONGODB_URI=mongodb+srv://your-atlas-connection-string
- Example:
- Start Docker Compose by running:
docker-compose up --build
- Access the frontend at
http://localhost:3000
in your browser.
- Navigate to the
api/
directory. - Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
source venv/bin/activate
- Install dependencies:
python3 -m pip install -r requirements.txt
- Download the PANNs model checkpoint file and move it to the correct path (add your username in the path below):
wget https://zenodo.org/record/3987831/files/Cnn14_mAP%3D0.431.pth?download=1 -O Cnn14_mAP=0.431.pth mv Cnn14_mAP=0.431.pth /Users/<your_username>/panns_data
- Run the backend service:
uvicorn main:app --reload --port 8000
- Navigate to the
frontend/
directory. - Install dependencies:
npm install
- Start the frontend:
npm run dev
- Access the frontend at
http://localhost:3000
.
First time accessing the project:
-
Choose your number of training samples and hit "Start Recording" on the frontend.
-
Once recording for all stages is complete, go to your MongoDB Atlas dashboard and create a search index in the
audio
database andsounds
collection using the following content:{ "mappings": { "dynamic": true, "fields": { "emb": { "dimensions": 2048, "similarity": "cosine", "type": "knnVector" } } } }
-
You can now return to the frontend on your browser and click on "Start Diagnostics" to see the demo in action.
This step only needs to be done for the very first time that you’re connecting to your MongoDB Atlas cluster.
- In Atlas, go to Charts and click the down arrow next to "Add Dashboard", then click "Import Dashboard".
- Select the file
Sounds.charts
and click "Next". - Click on the pencil icon and ensure the database and collection match
audio
andresults
. - Click "Save", and then "Save" again.
- Click the new dashboard "Sounds" to see analytics on the sounds that are being detected by the microphone.
-
Frontend Not Loading:
- Ensure that both the backend and MongoDB Atlas are running and accessible.
- Check for any errors in the console.
-
Audio Device Issues:
- Use an external microphone if your device's microphone is not functioning properly.
- Ensure that necessary libraries like wget and ffmpeg are installed.
-
Docker Errors:
- If containers fail, try rebuilding them by running:
docker-compose down && docker-compose up --build
- Ensure your
.env
file is properly set up in the root directory.
- If containers fail, try rebuilding them by running:
-
Database Connection Errors:
- Verify the
MONGODB_URI
in your.env
file. - Ensure that your IP address is whitelisted in MongoDB Atlas.
- Confirm that your MongoDB cluster is active and accessible.
- Verify the