Why build a Kenyan conversational AI engine?
Most AI application development begins with an external model API. That is a perfectly valid way to ship useful products, but I wanted to understand what happens underneath the application layer: how models are loaded, how inference is executed, how GPU memory is allocated, and how distributed services communicate.
That curiosity led me to build an experimental Kenyan Conversational AI Engine designed around Kenyan English, Kiswahili, and English-Swahili code-switching.
The project is an exploration of a broader engineering question: what does it take to move from integrating an AI API to understanding and operating the infrastructure that serves AI models?
This article explains the architecture, GPU allocation, model-serving approach, and lessons from the experiment.
1. The architecture: separate orchestration from inference
The system uses a distributed architecture that separates the user-facing application from GPU-intensive model execution.
The project configuration includes:
| Layer | Technology | Responsibility |
|---|---|---|
| Frontend | Next.js | User interface and interaction |
| Application backend | Express.js + TypeScript on Bun | API orchestration and business logic |
| Database | PostgreSQL on Neon | Application data |
| Inference worker | FastAPI + Uvicorn | Model execution endpoints |
| GPU compute | Two NVIDIA Tesla T4 GPUs | Language and speech workloads |
| Worker connectivity | Static ngrok domain | Connectivity to the experimental worker |
| Speech-to-text | Whisper Large V3 Turbo through Groq | Audio transcription |
| Language model | Self-hosted Qwen3.5–4B | Text generation |
| Text-to-speech | Sauti V2, based on Chatterbox with a LoRA adapter | Speech generation |
The central architectural principle is simple:
The application layer orchestrates. The inference layer computes.
The backend communicates with inference providers through stable interfaces. This keeps hardware and runtime details out of the application layer and makes it possible to change inference providers without redesigning the entire product.
The separation also creates operational boundaries. The application backend can handle authentication, validation, and user state while inference workers focus on model execution.
2. GPU computing and CUDA device allocation
One of the most interesting parts of the experiment was working with GPU resources.
The reported setup used two NVIDIA Tesla T4 GPUs provisioned through Kaggle, each with approximately 15 GB of VRAM available to the workload.
Instead of loading both models onto one device, I separated the language-model and text-to-speech workloads.
GPU 0: Sauti V2 text-to-speech
- CUDA device:
cuda:0 - Precision: FP32
- Reported allocated VRAM: approximately 3.1 GB
- Reported peak VRAM: approximately 3.2 GB
GPU 1: Qwen3.5–4B language model
- CUDA device:
cuda:1 - Precision: FP16
- Context window configured: 8,192 tokens
- Reported allocated VRAM: approximately 7.8 GB
- Reported peak VRAM: approximately 7.9 GB
Why separate the workloads?
GPU memory is finite. Language generation and speech synthesis have different memory and compute patterns. Running both on the same device can introduce contention and increase the risk of CUDA out-of-memory errors.
Explicit device placement makes resource allocation easier to reason about. It does not guarantee higher throughput by itself; that still needs to be measured under concurrent load.
Precision also matters. FP16 can reduce memory use compared with FP32 and is commonly used for inference on supported hardware. The T4 supports FP16 acceleration, while BF16 support and performance should be checked against the specific GPU and software stack rather than assumed.
3. Model serving and inference
The GPU worker exposes two internal endpoints:
POST /completefor language-model inference.POST /synthesizefor speech generation.
The worker runs FastAPI and Uvicorn and communicates with the main application over authenticated HTTP. The experimental connectivity setup uses a static ngrok domain and an X-Worker-Key header.
The application and worker boundary is important. The application should not depend on CUDA device identifiers, model-loading details, or the inference runtime's internal response format.
The worker integration also needs to account for:
- Request timeouts and cancellation.
- Input validation and context-window limits.
- Model availability and readiness.
- Stable error codes.
- GPU out-of-memory conditions.
- Authentication between services.
- Health checks and operational monitoring.
A production design should keep the inference worker on a private network where possible, rotate secrets, apply rate limits, and avoid exposing an experimental tunnel as a permanent production architecture.
4. Why distributed inference changes the engineering problem
Once application orchestration and model execution run in separate services, the system becomes a distributed system.
Network calls can fail. Workers can restart. Models can take time to load. Requests can arrive faster than GPUs can process them. A successful application API request does not guarantee that inference completed.
This means the architecture needs explicit timeouts, bounded queues, overload responses, retry rules, and correlation IDs. Retries should be designed carefully: a generation request may be safe to retry in some contexts, while a tool action that changes business state may not be.
The system should distinguish liveness from readiness. A worker process can be alive while its model is still loading or unavailable. A readiness endpoint should reflect whether the service can actually accept inference requests.
For a system with multiple model workers, a gateway or scheduler can route requests according to model availability, workload, and resource capacity. The scheduler should have visibility into queue depth and worker health.
5. Building for Kenyan English and code-switching
The project is designed around a linguistic reality that generic language interfaces can overlook: people do not always communicate in one language at a time.
A conversation may move between Kenyan English, Kiswahili, and English-Swahili code-switching. A useful conversational engine needs to be evaluated against how people actually speak and write, including informal phrasing, spelling variation, local references, and context.
A model's general benchmark score is not enough to establish quality for this use case. Evaluation should use representative, consented examples and assess:
- Meaning preservation across language switches.
- Appropriate responses in the requested language.
- Recognition of local expressions and context.
- Robustness to spelling and transcription variation.
- Consistency across multi-turn conversations.
- Safety and refusal behaviour.
- Latency and cost for realistic audio and text workloads.
Speech introduces another layer. Transcription quality affects everything downstream, while speech generation needs to be assessed for intelligibility, pronunciation, naturalness, and latency. A pipeline can fail even if the language model itself performs well.
6. What would be required for production deployment?
The experiment demonstrates an architecture and a way to explore GPU-backed inference. A production deployment would require additional work beyond connecting the services.
Capacity and scheduling: Benchmark throughput, time to first token, tokens per second, queue behaviour, and peak memory under realistic concurrency. Establish admission control and capacity limits.
Availability: Use managed or dedicated compute with predictable uptime, worker supervision, health checks, deployment automation, and recovery procedures. Ephemeral notebook or research environments are useful for experimentation but should not be treated as production infrastructure.
Security: Use private networking where possible, strong service authentication, secrets rotation, least-privilege access, request validation, and data-retention controls. Do not log sensitive prompts or audio by default.
Monitoring: Track GPU utilisation, VRAM, worker health, queue depth, latency, error rates, model-load events, and task quality. Keep enough tracing to connect an application request to the inference operation without exposing sensitive content.
Evaluation: Maintain test datasets for language quality, transcription, speech generation, tool use, and safety. Re-run evaluations when changing a model, quantisation method, prompt, or inference runtime.
Cost management: Measure cost per successful conversation, not only the hourly price of a GPU. Include idle time, storage, network, model-loading overhead, engineering operations, and fallback providers.
The bigger lesson
Building an AI application and operating the infrastructure that runs its models are different engineering challenges.
The application layer is concerned with product behaviour, user experience, business rules, and integrations. The inference layer introduces hardware constraints, GPU memory management, model serving, scheduling, distributed networking, and operational reliability.
This project has been a practical way to explore those boundaries, from CUDA device placement to service contracts between a TypeScript backend and Python inference workers.
My longer-term focus is on LLM infrastructure engineering, agentic AI, and forward-deployed systems: building AI that does useful work inside real organisations, with the engineering discipline required to operate it reliably.
At Baseline44, this is the kind of systems thinking we bring to AI engineering: not just connecting a model, but designing the application, infrastructure, integrations, and controls around it.
Interested in building an AI system beyond a prototype? Explore Baseline44 AI solutions or contact the team.
Sources and further reading
- Project architecture and measurements: supplied by the author for this article; verify against the current implementation before publication.
- NVIDIA CUDA documentation
- Ollama concurrency and queue behaviour
- vLLM documentation
- OWASP GenAI Security Project
Need this for your business?
Book a free consultation and we'll map it to your situation.
Book a consultationI'm Alex Njoroge, an AI and software engineer at Baseline44. I build grounded AI systems, retrieval pipelines and production software for organisations in Kenya, and I write about the engineering decisions behind projects like Sheria Bot.
