Skip to content

A FastAPI application that connects to the Notion API and provides RAG (Retrieval-Augmented Generation) capabilities using MongoDB Atlas Vector Search and Google AI Studio.

License

Notifications You must be signed in to change notification settings

azis14/cloud-brain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

35 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cloud Brain

Sponsor codecov License: MIT Python FastAPI MongoDB Notion WAHA

A FastAPI application that connects to the Notion API and provides RAG (Retrieval-Augmented Generation) capabilities using MongoDB Atlas Vector Search and Google AI Studio.

Features

Notion Integration

  • ๐Ÿ”— Connect to Notion API
  • ๐Ÿ“Š Fetch data from Notion databases
  • ๐Ÿ“‹ Simplified data extraction

RAG & Vector Search

  • ๐Ÿง  Sync Notion content to MongoDB Atlas as vector embeddings
  • ๐Ÿ” Vector similarity search using sentence transformers
  • ๐Ÿค– Question answering with Google AI Studio (Gemini)
  • ๐Ÿ’ฌ Chat interface for natural language queries

Setup

1. Environment Variables

Create a .env file in the project root with the following configuration:

# Notion API Configuration
NOTION_API_KEY=your_notion_integration_token_here
NOTION_DATABASE_IDS=your_comma_separated_database_ids_here

# MongoDB Atlas Configuration
MONGODB_URI=your_url_to_mongodb_atlas_cluster_here
MONGODB_DATABASE=your_database_name_here
MONGODB_COLLECTION=your_collection_name_here

# Google AI Studio Configuration
GOOGLE_API_KEY=your_google_ai_studio_api_key (optional, could use another LLM)
GOOGLE_MODEL=(gemini-2.5-flash or other model)

# Vector Database Configuration (Optional - defaults provided)
EMBEDDING_MODEL=all-MiniLM-L6-v2
MAX_CHUNK_TOKENS=500
CHUNK_OVERLAP_TOKENS=50
MAX_CONTEXT_CHUNKS=5
MIN_SIMILARITY_SCORE=0.7

# Other Configurations
CORS_ALLOW_ORIGINS=could be '*' or specific origins here
API_SECRET_KEY=generate_random_string_here

# WAHA configuration
WHITELISTED_NUMBERS=your_comma_separated_phone_numbers_here
WAHA_API_URL=your_url_to_waha_api_here
WAHA_API_KEY=your_waha_api_key_here
WAHA_SESSION_NAME=your_waha_session_name_here

2. MongoDB Atlas Setup

  1. Create a MongoDB Atlas cluster
  2. Create a database
  3. Create a collection
  4. Important: Create a vector search index:
    • Index name: vector_index
    • Field path: embedding
    • Dimensions: 384 (for all-MiniLM-L6-v2 model)
    • Similarity: cosine

3. Install Dependencies

pip install -r requirements.txt

4. Run the Application

uvicorn main:app --reload

The API will be available at http://localhost:8000

API Documentation

Once the server is running, visit:

  • Interactive API docs: http://localhost:8000/docs
  • ReDoc documentation: http://localhost:8000/redoc

Notion Integration Setup

  1. Go to Notion Integrations
  2. Click "New integration"
  3. Give it a name and select your workspace
  4. Copy the "Internal Integration Token" - this is your NOTION_API_KEY
  5. Share your databases with the integration:
    • Open the database in Notion
    • Click "Share" โ†’ "Invite"
    • Search for your integration name and invite it

WAHA (WhatsApp HTTP API) Setup

WAHA enables WhatsApp integration, allowing your application to receive and respond to WhatsApp messages with AI-generated answers based on your Notion content.

Quick Setup

  1. Install and run WAHA using Docker:

    docker pull devlikeapro/waha
    docker run -it --rm -p 3000:3000 --name waha devlikeapro/waha
  2. Connect WhatsApp: Open http://localhost:3000, create a session, and scan the QR code with your phone.

  3. Configure environment variables in your .env file:

    WAHA_API_URL=http://localhost:3000
    WAHA_API_KEY=your_waha_api_key_here
    WAHA_SESSION_NAME=default
    WHITELISTED_NUMBERS=1234567890,9876543210
  4. Set webhook URL in WAHA dashboard to: http://your-app-domain.com/waha/webhook

How it works

  • Incoming WhatsApp messages are sent to your application via webhook
  • Only whitelisted numbers can interact with the bot
  • Messages are processed through the RAG system and responses are sent back via WhatsApp

For detailed installation, configuration, and production deployment instructions, visit the WAHA official documentation.

Host Waha on Sumopod

Instead of running WAHA locally, you can host WAHA+ on SumoPod, which offers low cost hosting (starts from IDR20K/month) for small projects like this one. Follow these steps:

  • Sign up for an account on SumoPod
  • Deploy your WAHA instance by clicking the "Deploy Now" button below.
  • Once deployed, follow the setup guide above to configure your WAHA instance.

Development

Running Tests

# Install test dependencies
pip install pytest pytest-asyncio httpx

# Run tests (when test files are created)
pytest

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is open source and available under the MIT License.

Example Usage

Example 1

๐Ÿ“ฎ Support

Buy Me A Coffee More About Me

If you encounter any issues or have questions, please open an issue on GitHub.

If you like this repo or think it useful, please leave a โญ๏ธ on it.


Made with โค๏ธ by the open-source community

About

A FastAPI application that connects to the Notion API and provides RAG (Retrieval-Augmented Generation) capabilities using MongoDB Atlas Vector Search and Google AI Studio.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Languages