Skip to content

Using MongoDB Atlas Vector Search to determine issues with wind turbines

License

Notifications You must be signed in to change notification settings

mongodb-industry-solutions/wind-turbine-diagnostics

 
 

Repository files navigation

Wind Turbine Diagnostics using MongoDB Vector Search

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.

Architecture

Table of Contents

  1. Prerequisites
  2. Setup Options
    • Unified .env File
    • Option 1: Run with Docker Compose
    • Option 2: Run Without Docker
  3. MongoDB Atlas Configuration
  4. Atlas Charts
  5. Troubleshooting

Prerequisites

  1. Node.js (tested with v20.8.0)

    • 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
  2. Python 3.8+

    • 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
  3. A MongoDB Atlas Account

    • 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.
  4. FFmpeg

    • 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
  5. wget

    • 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
  6. Docker

    • 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

Setup Options

Choose one of the following two ways to set up and run the demo.

Unified .env File

A default .env file has been created in the root directory of the project. To set it up:

  1. Open the .env file located in the root directory.
  2. Edit the line for MONGODB_URI to include your MongoDB Atlas connection string:
    MONGODB_URI="mongodb+srv://<your-atlas-connection-string>"
    

Option 1: Run with Docker Compose

  1. Clone the repository and navigate to the project folder.
  2. 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
  3. Start Docker Compose by running:
    docker-compose up --build
  4. Access the frontend at http://localhost:3000 in your browser.

Option 2: Run Without Docker

Backend Setup (Port: 8000)

  1. Navigate to the api/ directory.
  2. Create a virtual environment:
    python3 -m venv venv
  3. Activate the virtual environment:
    source venv/bin/activate
  4. Install dependencies:
    python3 -m pip install -r requirements.txt
  5. 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
  6. Run the backend service:
    uvicorn main:app --reload --port 8000

Frontend Setup (Port: 3000)

  1. Navigate to the frontend/ directory.
  2. Install dependencies:
    npm install
  3. Start the frontend:
    npm run dev
  4. Access the frontend at http://localhost:3000.

MongoDB Atlas Configuration

First time accessing the project:

  1. Choose your number of training samples and hit "Start Recording" on the frontend.

  2. Once recording for all stages is complete, go to your MongoDB Atlas dashboard and create a search index in the audio database and sounds collection using the following content:

    {
      "mappings": {
        "dynamic": true,
        "fields": {
          "emb": {
            "dimensions": 2048,
            "similarity": "cosine",
            "type": "knnVector"
          }
        }
      }
    }
  3. 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.


Atlas Charts

  1. In Atlas, go to Charts and click the down arrow next to "Add Dashboard", then click "Import Dashboard".
  2. Select the file Sounds.charts and click "Next".
  3. Click on the pencil icon and ensure the database and collection match audio and results.
  4. Click "Save", and then "Save" again.
  5. Click the new dashboard "Sounds" to see analytics on the sounds that are being detected by the microphone.

Troubleshooting

  • 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.
  • 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.

About

Using MongoDB Atlas Vector Search to determine issues with wind turbines

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 52.9%
  • Python 32.8%
  • HTML 4.6%
  • Dockerfile 3.5%
  • CSS 3.4%
  • TypeScript 2.8%