I created the Sonic Assistant (SAAPP) to prove I can independently architect, build, and deploy a modern, cloud-native AI system leveraging both RAG and Agentic workflows. It includes and demonstrates:
- Full-stack cloud engineering (React, Vite, FastAPI)
- Cloud-ready architecture (Deployed on Vercel & Render using MongoDB and Google Gemini API)
- Agentic workflows with LangGraph
- Retrieval grading, query rewriting, and multi-step reasoning
- Multi-tenant secure data isolation
- Asynchronous token streaming
- Hybrid retrieval and vector indexing powered by MongoDB
- Frontend: React, Vite, Tailwind/Custom CSS, deployed globally on Vercel (
sonicassistant.com). - Backend: FastAPI service deployed on Render (
https://saapp.onrender.com). - AI Engine: Google Gemini API for high-performance generation and reasoning.
- Database & Vector Store: MongoDB for secure multi-tenant data storage and retrieval.
- Authentication: Clerk integrated with role-based access control (RBAC).
The application implements a multi-tenant security architecture designed to isolate data between different "Affiliates / Knowledge Bases" (e.g., Sonic Lore vs. Dragon Ball Data).
- Identity Context: Authenticated via Clerk, mapping user identities and session states to authorized organization scopes.
- Role-Based Access Control (RBAC): The backend maps users to specific authorized "affiliates" via
/api/affiliatesand checks permissions via/api/user/groups. - Data Isolation: When performing a search or ingestion, the system enforces a strict scope query against MongoDB. Only documents tagged with an affiliate allowed to the current user are retrieved, preventing cross-tenant data leakage at the query level.
- Multi-KB Access: Users with access to multiple knowledge bases can query them simultaneously or scope their responses down to a specific target KB.
The model coordinates its reasoning through a compiled LangGraph workflow that manages conversation flow by routing queries and responses through specialized nodes and edges:
- GraphState: Tracks conversation history, authenticated user identity, permitted affiliate scope, and retrieved documents across every step.
- Workflow Execution:
- Routing:
route_user_querydetermines whether to trigger theretrieve_nodeagent (for document-backed questions) or theconversational_nodeagent (for general chat). - Retrieval & Grading:
retrieve_nodefetches documents based on user scope from MongoDB. Thegrading_nodeevaluates relevance, returning a binary yes/no response. - Rewrite & Generate: If retrieval quality is low,
rewrite_query_noderephrases the question before trying again. Finally,generate_nodesynthesizes the final response using Gemini.
- Routing:
The system uses a unified search service designed to adapt its strategy based on query intent:
- Intelligent Routing: Analyzes query text to pick the optimal retrieval strategy:
- Lexical: Triggered by temporal or keyword markers (e.g., "latest", "date", "timeline").
- Hybrid: Triggered by comparative keywords (e.g., "compare", "analyze", "connection").
- Vector: Default fallback for semantic queries.
- Graph-Enhanced Context: Integrates with a NetworkX knowledge graph to surface multi-hop entity relationships and enrich retrieved context.
Local development uses a PowerShell script (Windows) to start the app. You need these installed first:
- Python 3.11 or newer, on your
PATH. - Node.js (includes
npm). - An internet connection: the app calls the Google Gemini API and a hosted MongoDB, so it needs your API keys and connection settings to be configured.
Note: If you encounter a script execution policy restriction in your terminal, run
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypassbefore executing.
One script starts everything for local development, first run or not:
./start_saapp.ps1What it does:
- Refuses to start if port 8000 or 8080 is already in use, and says which process holds it, so a leftover server can't keep serving old code.
- Creates the Python virtual environment (
.venv) and installsrequirements.txtif the environment is missing. - Runs
npm installinlocal/iflocal/node_modulesis missing. - Starts the FastAPI backend (http://127.0.0.1:8000, with auto-reload) and the Vite frontend (http://127.0.0.1:8080), each in its own window.
Use -BackendOnly or -FrontendOnly to start just one of them.
The project separates initial bootstrapping from runtime data changes:
Run it by hand to seed the initial documents (it is not part of the start script):
.\.venv\Scripts\python.exe ingest.pyIt purges stale database remnants to prevent vector index collisions, scans the root drop-zones for default data, splits content into 600-token overlapping chunks, and indexes them into MongoDB.
Use the built-in Self-Service page in the web application to upload, ingest, and manage material on the fly.