The best way to interact with a MongoDB database in a FastAPI application is to use an asynchronous MongoDB driver, such as motor. It integrates seamlessly with FastAPI and allows for non-blocking database operations, which is important to maintain the responsiveness of your application.

MongoDB Schema Design

This schema will support the plans for the front end

User Document
Chat Message Document
Chat Window Document
Chat Configs

Manage config details for a specific chat session (eg, LLM settings)

  • Design: Embed these configurations directly in the chat_window document.
Results

Stores details about LLM responses and metadata

  • Design: Embed result data in the chat_message document, as it is tightly coupled with each message.
 

users stores user data, preferences, and linked chats
chat_messages stores individual messages and their associated results
chat_windows stores high-level chat session info


motor mongodb backend development research webapp fastapi python