Inspiration
Lots of people take herbal supplements alongside prescription medicine and never mention it to their pharmacist. St. John's wort and an antidepressant is the classic example. The information exists, but it is scattered, and a misspelled name or a brand name can make a quick lookup fail. I wanted a small tool that is honest about what it knows and what it doesn't.
What it does
You enter herbs and medications. HerbCheck returns plain-language interaction flags, each with an attention level, the mechanism, the evidence type and a confidence score.
The safety behavior matters most to me:
- Unknown names are only suggested. If you type "gingko", it asks "did you mean ginkgo?" and waits for you. It never silently swaps the name.
- Weak evidence goes to review. If a finding rests on mixed or thin evidence, the whole result is marked needs review, with the reasons shown.
- "Not found" never means "safe". An empty result says exactly that and nothing more.
How I built it
- IBM Db2 12.1 holds the herbs, drugs, drug classes and interaction rules. Interactions are matched by drug class with a SQL join. Names are stored with
VECTOR(384)embeddings so Db2 can find near-matches for typos. - Vector distance. Name suggestions use cosine distance in Db2:
$$d(a,b) = 1 - \frac{a \cdot b}{\lVert a \rVert \, \lVert b \rVert}$$
A suggestion is shown only if $d$ is under a cut-off tuned for the embedding model.
- LangChain runs the pipeline as a chain of steps: normalize, resolve names, find interactions, retrieve supporting evidence, gate, explain, audit. Evidence passages are indexed with the
langchain-db2vector store. - Confidence gate. Each rule's evidence type maps to a confidence score. Anything below $0.80$ sends the result to review.
- FastAPI serves the API and a single-page interface. A "What Db2 did" panel shows every stage and its timing.
- fastembed (bge-small, 384 dimensions) provides the embeddings. A built-in hashing fallback means the demo still works if a model can't be downloaded.
- Audit log. Every check is logged in Db2 as counts and a digest only, with no personal information.
Challenges
- Hosting Db2. IBM's free hosted Db2 asked for a payment card, so I ran Db2 Community Edition in Docker inside GitHub Codespaces instead.
- Filters after top-k. The Db2 vector store applies metadata filters after it picks the top results, so I retrieve more candidates than I need and then filter.
- Tuning the cut-offs. Different embedding models spread similarity scores differently, so each one needed its own "did you mean" threshold.
- Failing safely. The hardest design question was what to do when the app doesn't know something. Guessing is easy. Refusing to guess takes more care.
What I learned
In a health tool, how it fails matters more than how much it covers. Showing the reasoning, such as the stage table, the confidence and the audit, makes a small reference set far more trustworthy than a bigger one that hides its uncertainty.
What's next
HerbCheck is an educational research prototype. It uses a small, unreviewed starter set (25 herbs, 160 drugs, 44 rules) with synthetic reference data only, and it is not medical advice or a medical device. Next steps are clinician-reviewed content, more herbs and sources, and a proper evaluation.
