assisted-mindfulness/naive-bayes
A lightweight Naive Bayes classifier for PHP and Laravel. Train on labeled text and classify new documents for spam detection, sentiment analysis, or category prediction with a simple, easy-to-use API.
Package: assisted-mindfulness/naive-bayes — a PHP naive Bayes classifier for Laravel, now at 2.0.2.
Architecture fit. This is a self-contained statistical classifier, not an ML platform. It fits where we need lightweight, explainable text/document classification inside the PHP process — spam and abuse triage, ticket routing, intent tagging, sentiment bucketing, lead scoring on tokenized fields. It does not fit as a replacement for a hosted inference service or anything requiring embeddings, deep models, or GPU throughput. The key architectural question is whether classification belongs in the request path (cheap, synchronous, no external dependency) or in a queue worker (preferred if corpora are large). Given the pure-PHP nature, it is an attractive fit for teams that want to avoid adding a Python/sidecar service to an otherwise homogeneous Laravel stack.
Dependency surface. Narrow and well-understood: the package's stated dependency is brick/math, an arbitrary-precision arithmetic library used to keep probability multiplication from underflowing on long token sequences. That is the right technical choice for naive Bayes — naive Bayes multiplies many small probabilities, and native PHP floats degrade quickly. It also means our arithmetic correctness is inherited from a widely used, actively maintained third-party library rather than hand-rolled.
Integration feasibility. Standard Laravel package mechanics: composer require, auto-discovery of the service provider, config publishing, and typical usage of train/predict calls against a model. There is no runtime service to provision, no credentials, no network egress, no schema migration implied by the package itself. Initial feasibility is high — a spike should be days, not weeks.
Technical risk.
Classifier contract) so a future 2.1 or 3.0 does not ripple through domain code.brick/math constraint from ^0.18 to ^0.18 || ^0.20. This is not a code change to the classifier — it is a resolution-policy change. Consequence: two environments running identical package code can resolve different brick/math versions, and therefore different precision/rounding behavior, depending on lockfile age and PHP version. Classifier output on borderline cases could differ between staging and production. This is the single most important thing to pin down.brick/math 0.20 may carry a higher PHP minimum than 0.18. If any of our apps sit on an older PHP minor, the widened constraint can silently push Composer toward a version that breaks the platform requirement. Must be verified against our support matrix, not assumed.Key questions to resolve before commitment.
brick/math 0.20 impose, and does it match our matrix?Stack fit. Excellent for a Laravel monolith. Composer-native, no service to operate, no container images, no secrets management, no added latency budget beyond CPU time. It composes naturally with queued jobs, console commands for retraining, and Artisan scheduling for periodic model refresh. It is a poor fit only if we need sub-millisecond classification at very high volume, streaming feature updates, or model explainability at the token level beyond what naive Bayes natively gives.
Migration path. There is nothing to migrate from if this is greenfield; the package can sit alongside existing rule-based or keyword classifiers so we can shadow-run and compare decisions before cutting over. If replacing an external service, run both in parallel on live traffic, log disagreements, and cut over only when the disagreement rate and the resulting business metric (false positive rate in moderation, misroute rate in support) are acceptable. That shadow period is the real migration work — the code change is trivial, the trust-building is not.
Compatibility.
^0.18 || ^0.20 resolving consistently. Pin brick/math explicitly in each application's composer.json and commit the lockfile. Treat any bump of brick/math as a classifier-affecting change requiring the regression check below.brick/math pin across them, otherwise identical models can score differently per service.Sequencing.
brick/math, capture the resolved version, and record the PHP/Laravel floor that actually works.brick/math drift visible rather than silent.Maintenance. Low day-to-day maintenance, but not zero. Two ongoing costs: (a) dependency churn — Dependabot PRs like the ones in 2.0.2 arrive at the package's cadence and, through it, at ours, so we need a routine to evaluate them rather than auto-merging; (b) model lifecycle — accuracy decays as the world drifts (new spam patterns, new product names, new support topics), so retraining is a recurring operational task with an owner, a schedule, and a quality gate, not a one-off setup step.
Support. There is no commercial support and a single-maintainer profile. Internal support burden is modest because the domain is well-understood and the code footprint is small, but the responsible posture is: assume we may need to maintain a fork. Keeping our usage inside a thin adapter makes that fork survivable. Budget a modest amount of engineering familiarity rather than assuming any given developer can debug precision issues unaided.
Scaling. Two distinct cost curves, and they should be planned separately.
Failure modes.
brick/math version differences — the signature risk of this particular release. Mitigated by the golden-dataset harness; without it, symptoms appear as unexplained shifts in classification rates weeks later.Ramp-up. Fast for competent Laravel developers — an experienced engineer is productive in a day on the API, and the concepts (tokenization, prior, likelihood, smoothing) are standard. The non-obvious part is evaluation discipline: choosing a holdout set, avoiding leakage, reading confusion matrices, and knowing when naive Bayes is simply the wrong model. Plan for a short internal write-up on evaluation methodology alongside the integration work; that documentation will prevent more incidents than any code review of the wrapper.
Verdict on 2.0.2. No functional change, no API change, no deprecation — a dependency-constraint widening plus a routine bump. Adopt without ceremony if brick/math is pinned and the regression harness exists. The release is unremarkable in itself; its value to us is as a reminder that this package's dependency graph is a moving part we must control on our side.
How can I help you explore Laravel packages today?