Clean, runtime-first rebuild for MenuGreen AI Coach.
- Keep runtime stable and minimal.
- Keep ONNX inference as primary path.
- Isolate training/data-discovery scripts from production runtime.
- Remove overlapping fallback logic and centralize fallback policy.
runtime/: production API service (FastAPI) for chat/coach.tools/: training/export/data scripts (not required for prod startup).research/: experiments, notebooks, ad-hoc validation.infra/: local/devops scripts.docs/: architecture, migration, and contracts.tests/: API + service tests.
- Runtime loads prebuilt ONNX from
runtime/models/intent_onnx. - If ONNX unavailable, fallback occurs in one place only.
- No training/export scripts imported by runtime.
- Runtime dependencies are pinned and separated from dev/training deps.
cd runtime
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements-runtime.txt
uvicorn app.main:app --reload --port 8000Recommended local prerequisites:
- Python
3.11+for runtime work - Node.js
20+fortools/sync-service-nest - PostgreSQL connection string for the runtime DB
- One or more Gemini API keys if you want hybrid rewrite/fallback enabled
Runtime setup from a clean clone:
cd D:\EXE\RAG_AI_MenuGreen\runtime
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements-runtime.txtSingle shared root .env:
POSTGRES_URL=postgresql://username:password@host:5432/dbname
GOOGLE_API_KEY=your_gemini_api_key
GOOGLE_API_KEYS=your_gemini_api_key_1,your_gemini_api_key_2,your_gemini_api_key_3Gemini runtime notes:
GOOGLE_API_KEYSsupports multiple comma-separated keys for automatic failover.GOOGLE_API_KEYis still supported as a single-key fallback.- Runtime caches Gemini rewrites / fallbacks / embeddings in memory to reduce repeated calls.
- Gemini is only called for harder cases such as failed DB matches or ambiguous food queries.
- Gemini keys stay server-side only; do not expose them to frontend code or browser env files.
- Runtime and sync service both read the same root file:
.env
Run the runtime:
cd D:\EXE\RAG_AI_MenuGreen\runtime
.\.venv\Scripts\Activate.ps1
uvicorn app.main:app --reload --port 8000Sync service setup:
cd D:\EXE\RAG_AI_MenuGreen\tools\sync-service-nest
npm install
npm run build
npm run start:devRepository hygiene:
- Commit
package-lock.jsonfiles. - Do not commit
.venv,.venv311,node_modules, ordist. - These local/build folders are already covered by
.gitignore.
- Runtime connects with
POSTGRES_URL. - Runtime can auto-create a local PostgreSQL demo user for non-UUID IDs.
- For fixed demo data, seed PostgreSQL and call
/worker/chatwith that UUID.
- If client sends non-UUID user id (e.g.
user_abc_123), runtime derives a stable internal UUID. - Runtime will auto-create:
rolesdefault row when neededusersrowprofilesrowhealth_profilesrow with default target values
- Port working endpoints from old project into
runtime/appmodules. - Add PostgreSQL repositories for profile + meal logs context.
- Add contract tests before replacing old service.