{"slug": "building-ask-leya-lessons-learned-from-local-onnx-embeddings-prisma-migrations", "title": "Building Ask Leya: Lessons Learned from Local ONNX Embeddings, Prisma Migrations, and Express Async Handlers", "summary": "A developer detailed the architecture of Ask Leya, a chatbot that answers from a business's own content and hands off to a human when needed. The project uses local ONNX embeddings to avoid per-query costs and keep data on the server, but faces challenges such as cold starts and a 90-second production hang from a macOS binary. Other hurdles include managing a shared database with unreleased modules via Prisma and handling Express 4's lack of async rejection forwarding, which caused /chat to hang for 90 seconds per request.", "body_md": "Why build another chat widget? Because every widget I tried either followed a rigid script or confidently made things up. Ask Leya answers from a business's own content and hands off to a human when it can't.\n\nHere are three core architectural hurdles I ran into and how I solved them:\n\nNo translation step, no API call, no per-query embedding cost, and nothing leaves the server to be embedded. The chat model then only has to phrase the answer back in Arabic, which is the easy half.\n\nThe trade: A cold start while the model loads, and it pulls in sharp, which cost me a 90-second production hang when a macOS binary got rsynced onto a Linux box.\n\nManaging a database shared with unreleased modules\n\nThe database is shared with the rest of my broader app under development — 67 tables total right now, many of which belong to unreleased modules. Since Prisma migrate tries to treat unreleased tables as drift, every migration currently requires hand-filtering additive statements via prisma migrate diff until the full suite ships.\n\nExpress 4 doesn't forward async rejections\n\nAn unguarded async handler that throws gives you no response at all — the caller just hangs until it times out. That took /chat down for 90 seconds a request before I tracked it down.\n\nThe Stack\n\nFrontend: Next.js App Router, React (with a dependency-free vanilla JS iframe widget so it can't collide with customer CSS).\n\nBackend: Node.js, Express.\n\nDatabase: Postgres (Neon) + pgvector.\n\nReal-time & AI: Socket.IO for live human handoff, gpt-4o-mini via OpenRouter for replies.\n\nFree tier, no credit card required. Features like WhatsApp, Instagram, and Messenger integrations are built out but kept behind the scenes until fully polished for self-serve.", "url": "https://wpnews.pro/news/building-ask-leya-lessons-learned-from-local-onnx-embeddings-prisma-migrations", "canonical_source": "https://dev.to/mhk_sameera/building-ask-leya-lessons-learned-from-local-onnx-embeddings-prisma-migrations-and-express-async-29e4", "published_at": "2026-09-08 09:14:30+00:00", "updated_at": "2026-09-08 09:31:51.485997+00:00", "lang": "en", "topics": ["artificial-intelligence", "developer-tools", "ai-products", "machine-learning", "natural-language-processing"], "entities": ["Ask Leya", "Prisma", "Express", "Next.js", "React", "Postgres", "Neon", "pgvector"], "alternates": {"html": "https://wpnews.pro/news/building-ask-leya-lessons-learned-from-local-onnx-embeddings-prisma-migrations", "markdown": "https://wpnews.pro/news/building-ask-leya-lessons-learned-from-local-onnx-embeddings-prisma-migrations.md", "text": "https://wpnews.pro/news/building-ask-leya-lessons-learned-from-local-onnx-embeddings-prisma-migrations.txt", "jsonld": "https://wpnews.pro/news/building-ask-leya-lessons-learned-from-local-onnx-embeddings-prisma-migrations.jsonld"}}