A provenance-first Gemma 4 toolkit for U.S. adult cannabis product education. The design keeps stable behavior separate from changing knowledge:
- QLoRA teaches uncertainty, exact-product discipline, safety boundaries, neutral language, citation habits, and abstention.
- RAG supplies current product, batch, COA, public-health, research, and properly licensed aggregate-experience evidence.
- Deterministic controls route urgent or disallowed requests before generation and reject invalid citations plus clear dosing, treatment, guarantee, identity, sponsorship, promotional, and emergency-escalation violations afterward.
This is an engineering project, not medical or legal advice, a clinical device, or proof that cannabis is appropriate for anyone. A strain name is a search hint—not a chemical specification or a promise of an effect.
The executable framework is in place and one experimental pilot was trained, but no model or dataset has been approved for production release:
- 220 deterministic Codex-generated behavior scaffolds were quarantined from the public repository because generator-provider permission for Gemma training and open redistribution is unresolved;
- 200 deterministic Codex-generated evaluation scaffolds were likewise quarantined because their exact generator build and redistribution permission are unresolved;
- 0 training examples and 0 evaluation cases have human approval;
data/SOURCES.csvis intentionally empty, so training, RAG, and release fail closed;- one deterministic FDA extractive seed pack contains 22 training drafts and five whole-page-held-out evaluation drafts, all unreviewed and purpose-disabled;
- one transparency-only Gemma 4 E4B-it pilot used 80 draft training rows and 15 draft
validation rows, then failed its five-case quality gate at
0.50versus0.80; its adapter and dataset preserve all failed release flags and are not deployable; - two official-source candidate sets are reproducibly built: nine openFDA
identity-only records and five exact FDA safety-guidance passages. All have
training_allowed=false,rag_allowed=false,release_ready=false, and blank two-role review packets; - fail-closed human-authoring and first-party product/COA intake workflows are implemented, but there are zero real contributor submissions, product artifacts, COAs, rights approvals, or promoted records;
- no production RAG corpus, matched approved baseline, approved adapter, or grounding results exist yet;
- the v2 first-party experience machinery exists, but its example configuration is intentionally unapproved and fail-closed; there are 0 real submissions, moderation decisions, aggregate approvals, aggregates, or releases; and
- the release checker now requires a separately verified approved-BM25 run through
GroundedAssistant, exact per-system-response human severity and grounding review, two-role source-review evidence, and a fully inventoried in-artifact evidence bundle before it will write a release audit and checksums.
The right next production step is to review and expand the FDA seed pack with independently human-authored behavior conversations, while replacing or clearing the Codex-generated scaffolds. The experimental pilot is not precedent for a release: only approved artifacts with explicit purpose permission should reach production dataset preparation or future candidate training. Review decisions are bound to exact content and policy hashes, so later edits invalidate stale approvals.
The initial scope excludes Leafly, Weedmaps, AllBud, Erowid, Reddit, mirrors, and
Kaggle or Hugging Face repackagings derived from them. Public visibility,
robots.txt, technical scrapeability, or an uploader-applied license does not prove
that user reviews may be copied, used for model training, and redistributed under a
permissive license. A restrictive upstream source is not made permissive by a mirror.
For experience information, the only designed path is a first-party, structured, consented contribution program. Raw reports remain private and are never training, evaluation, RAG, or public data. Only approved, five-wide-banded aggregates from a rights-cleared product catalog may be dedicated to CC0 and indexed for RAG; this project does not train on those aggregates. Every contributing report and every released aggregate requires two distinct human reviewers. Cohorts are fixed UTC calendar quarters, candidate groups require at least 20 private participant keys, and post-publication withdrawal retires the whole immutable aggregate rather than recalculating or replacing it.
See the source audit and data policy. This is a conservative engineering rights screen, not a legal opinion.
- Project code and the planned adapter: Apache-2.0 (
LICENSE). - The official Gemma 4 base model is also Apache-2.0 under Google's Gemma 4 license. It remains Google's work, with its pinned model card and official license evidence preserved separately.
- Data remain CC0-1.0, CC BY, or verified public domain only where the applicable dataset card, source manifest, and rights evidence say so. The privately quarantined Codex behavior and evaluation scaffolds are not publicly distributed; a project CC0 marking does not override generator-provider terms.
- Other third-party works retain their original licenses and attribution. They are never silently relicensed by the repository's Apache license.
The first release is adapter-only to keep the artifact small, let users reproduce it against one exact base checkpoint and revision, and narrow the release file inventory. This is an engineering and release-scope choice, not a workaround for custom Gemma terms.
See data/LICENSE.md, evals/LICENSE.md, and THIRD_PARTY_NOTICES.md.
- Freeze the product, data, and safety contracts. Done in this repository.
- Build evaluation cases and release gates before training. Draft framework done; five source-backed candidates now exist; human approval and broader coverage are pending.
- Create behavior-only training examples under compatible authoring terms. The fail-closed human-authoring workflow is implemented and a 22-record FDA extractive seed pack exists, but no candidate is approved and no real contributor submissions exist.
- Register exact, rights-cleared artifacts and build a small RAG corpus. Official FDA candidates and the first-party product/COA pipeline are implemented; independent rights/provenance and scientific/safety reviews plus production admission remain pending.
- Run the untouched Gemma revision as a baseline on the approved suite. Pending.
- Prepare reviewed data and run QLoRA. An unreviewed experimental plumbing pilot is complete and failed; production-reviewed tuning remains pending.
- Compare the prompt-contained base and adapter runs, then run and review the complete grounded system, complete the cards, and run the release audit. Pending.
This order makes it possible to tell whether fine-tuning improved behavior and prevents training effort from masking a data-rights or evaluation problem.
python -m venv .venv
. .venv/bin/activate
pip install -e '.[dev]'
pytestFresh clones intentionally omit the ignored FDA source snapshots. Pytest skips only
the extraction and pilot-dataset tests that require those exact local receipts; after
the documented FDA fetch workflow populates artifacts/source-evidence/, those tests
run automatically.
The core has no runtime dependencies. Install the optional training stack only on a supported CUDA machine:
pip install -e '.[train,dev]'The default configuration targets google/gemma-4-E4B-it. Model download and GPU
work do not begin unless local preflight succeeds and the operator explicitly provides
--acknowledge-gpu-cost.
The v2 machine contracts are the report,
moderation,
withdrawal, and
aggregate schemas. Start from the
fail-closed configuration, replace
all nulls with reviewed production values, but keep that candidate offline. Freeze its
final non-approval values—including status: approved and both enabled flags—before
review: each legal, privacy, security, and safety scope_sha256 must equal
program_approval_scope_sha256(config_value, role), which is role-domain-separated
and excludes approvals and program_config_sha256. Add four distinct approvals,
compute the final configuration self-hash, validate the complete configuration, and
only then deploy it or activate the endpoints. The example is deliberately not
accepted by the production loader.
The single fail-closed operator interface is cannabis-experience. Its nine commands
cover validation, both two-person review stages, private aggregation, and final
release:
cannabis-experience validate-submissions \
--input <private-normalized-submissions.jsonl>
cannabis-experience report-review-export \
--input <private-normalized-submissions.jsonl> \
--output <private-report-review-packet.csv>
cannabis-experience report-review-apply \
--input <private-normalized-submissions.jsonl> \
--reviews <private-report-review-packet.csv> \
--output <private-moderated-reports.jsonl> \
--summary <private-report-review-summary.json>
cannabis-experience report-review-verify \
--input <private-moderated-reports.jsonl> \
--summary <private-report-review-summary.json>
cannabis-experience build-aggregate-draft --help
cannabis-experience aggregate-review-export \
--input <private-aggregate-draft.jsonl> \
--output <private-aggregate-review-packet.csv>
cannabis-experience aggregate-review-apply \
--input <private-aggregate-draft.jsonl> \
--reviews <private-aggregate-review-packet.csv> \
--output <private-reviewed-aggregates.jsonl> \
--summary <private-aggregate-review-summary.json>
cannabis-experience aggregate-review-verify \
--input <private-aggregate-draft.jsonl> \
--reviews <private-aggregate-review-packet.csv> \
--output <private-reviewed-aggregates.jsonl> \
--summary <private-aggregate-review-summary.json>
cannabis-experience release --helpUse each long command's --help output for its required moderation evidence,
tombstones, approved configuration, mode-0600 HMAC key, catalog, cohort, history, and
output paths. Each report needs distinct privacy-rights and quality-product
approvals; each aggregate separately needs distinct privacy-disclosure and
content-safety approvals. Never manually publish an intermediate. Follow the
operator procedure
and use the contributor notice
only after qualified review. This repository has no approved program configuration or
real experience artifacts.
The earlier Codex-generated scaffolds and the scripts that reproduce them are not distributed in this public repository. Do not reconstruct or train on them without qualified clearance. Replace them with independently human-authored examples or artifacts generated under terms that expressly permit the intended training and open redistribution. See data/training/PROVENANCE.md and evals/PROVENANCE.md.
Every training, evaluation, and retrieval source needs a row in
data/SOURCES.csv. Training, RAG, and redistribution permissions are independent.
Every populated evidence_class must be one of official_reference,
official_guidance, safety_guidance, product_fact, research_evidence,
reported_experience, or marketing_claim. RAG additionally requires a nonblank
registry class that exactly matches the corpus row's metadata; source review validates
semantic fit and never upgrades marketing or reported experience into scientific
evidence. Use --source-id when a mixed registry contains rows intended for different
purposes:
cannabis-provenance data/SOURCES.csv --source-id project-behavior-v1 --purpose training --purpose redistributionFirst-party or synthetic dataset rows need the canonical published artifact URL, exact content hash, rights evidence, and true purpose flags. Synthetic rows additionally need the immutable generator/build plus the URL, retrieval date, and SHA-256 of the exact provider-terms snapshot and provider permission flags. Do not invent evidence to make preflight pass. An empty registry or ambiguous rights always fails closed.
The first factual-source admission path is implemented for the official openFDA UNII
bulk export dated 2026-07-22. The recipe locks 175,091 source rows and ZIP SHA-256
60771d0b0ed8fe0dcbe0041302c42f6a0efb0e5fc6ad21c54b273728fcfae59e,
then deterministically admits only nine allowlisted cannabinoid identifiers. Each
candidate contains only substance_name and unii and is suitable, if approved, for
identity normalization—not effects, dosing, safety, legality, product, strain, or
individual-outcome claims.
Fetch the three exact audit inputs (download manifest, ZIP, and terms snapshot) into
the ignored artifacts/ area and write the content-bound receipt:
cannabis-openfda-unii fetch \
--recipe configs/openfda-unii-2026-07-22.json \
--evidence-dir artifacts/source-evidence/openfda-unii-2026-07-22 \
--receipt data/rag/candidates/openfda-unii-2026-07-22.retrieval.jsonRebuild the checked candidate corpus, candidate registry, and build manifest:
cannabis-openfda-unii build \
--recipe configs/openfda-unii-2026-07-22.json \
--evidence-dir artifacts/source-evidence/openfda-unii-2026-07-22 \
--receipt data/rag/candidates/openfda-unii-2026-07-22.retrieval.json \
--candidate-corpus data/rag/candidates/openfda-unii-2026-07-22.corpus.jsonl \
--candidate-registry data/rag/candidates/openfda-unii-2026-07-22.sources.csv \
--build-manifest data/rag/candidates/openfda-unii-2026-07-22.build.jsonThe raw evidence is audit material, not release data. The candidate files are also
not production RAG: their registry deliberately says rag_allowed=false, the build
manifest says release_ready=false, and data/SOURCES.csv remains header-only.
Promotion requires complete decisions from distinct rights_provenance and
scientific_safety reviewers. A content-bound 18-row blank packet is present at
data/rag/reviews/openfda-unii-2026-07-22.review.csv; all decision fields are empty,
so applying it fails closed. Use cannabis-source-review policy to inspect the current
hashed role criteria. After complete consensus, the compiler changes only
rag_allowed from false to true and appends its audit note for approved rows; it
never enables training. Review does not create external legal rights. See
data/rag/README.md for the exact export, apply, and verify
commands and artifact boundaries.
The richer openFDA Substance endpoint, all GMDN content, and FAERS are excluded. Rich Substance fields are unnecessary for this narrow identity task; GMDN requires a separate license for commercial ontology or AI uses; and spontaneous adverse-event reports cannot establish incidence, causation, or what a customer should expect.
A second official-source path directly captures two exact FDA cannabis/CBD consumer
pages and the FDA website reuse policy. The recipe locks all three canonical URLs,
content-current dates, byte counts, SHA-256 values, the article#main-content
selector, and five exact passages. The fetcher does not crawl or follow links, and the
transform excludes all unlisted text, images, graphics, logos, navigation, scripts,
links, and third-party material. The five rows are general safety_guidance; they are
never training data and do not authorize personalized medical, treatment, dosing, or
product-selection advice.
cannabis-fda-guidance verify \
--recipe configs/fda-guidance-2026-07-23.json \
--evidence-dir artifacts/source-evidence/fda-guidance-2026-07-23 \
--receipt data/rag/candidates/fda-guidance-2026-07-23.retrieval.json \
--candidate-corpus data/rag/candidates/fda-guidance-2026-07-23.corpus.jsonl \
--candidate-registry data/rag/candidates/fda-guidance-2026-07-23.sources.csv \
--build-manifest data/rag/candidates/fda-guidance-2026-07-23.build.jsonThe content-bound ten-row review packet at
data/rag/reviews/fda-guidance-2026-07-23.review.csv is blank, so these candidates
remain quarantined with rag_allowed=false and release_ready=false. Human
rights/provenance and scientific/safety approval is still required. Exact fetch,
build, review, and verification commands are in data/rag/README.md.
The public repository intentionally contains no Codex-generated behavior scaffolds. Supply independently human-authored examples, use a generator whose exact terms permit third-party model training and open redistribution, or obtain qualified clearance for the intended use. Record the exact lineage and terms first. The example commands below assume a cleared artifact has been supplied at the shown path.
After that blocker is cleared, export the review packet:
cannabis-training-review export --input data/training/behavior_drafts.jsonl --output artifacts/training-review.csvReviewers read PROJECT_SCOPE.md, DATA_POLICY.md, and SAFETY_POLICY.md, then fill
only the decision fields. Medical, dosing, acute-safety, and adult-eligibility examples
need two distinct reviewers; other families need one. Compile without overwriting the
drafts:
cannabis-training-review apply --input data/training/behavior_drafts.jsonl --ledger artifacts/training-review.csv --output artifacts/training-reviewed.jsonl --summary artifacts/training-review-summary.jsonBlank slots remain drafts, rejections require reasons, and reviewer disagreement blocks approval. Full instructions are in data/training/README.md.
The public repository intentionally contains no Codex-generated evaluation scaffolds. Supply independently authored or permissively generated cases, record exact generator/provider evidence, and register the artifact as described in evals/PROVENANCE.md. Human review validates content and safety only; it never erases synthetic origin or grants source rights.
After rights clearance:
cannabis-eval-review export \
--cases evals/cases.jsonl \
--output artifacts/eval-review.csvcannabis-eval-review apply \
--cases evals/cases.jsonl \
--reviews artifacts/eval-review.csv \
--output artifacts/eval-cases-approved.jsonl \
--summary artifacts/eval-review-summary.jsonThe compiler succeeds only when every supplied case is approved. Preserve the original drafts, review CSV, reviewed JSONL, and summary. The release checker revalidates the current review-policy files and exact file and case-set hashes, reviewer slots and decisions, and a source-registry record bound to the exact reviewed JSONL. See evals/REVIEW.md.
cannabis-prepare-data \
--input artifacts/training-reviewed.jsonl \
--review-summary artifacts/training-review-summary.json \
--eval-cases artifacts/eval-cases-approved.jsonl \
--eval-review-summary artifacts/eval-review-summary.json \
--split-groups artifacts/training-split-groups.json \
--dataset-source-id project-behavior-v1 \
--output-dir artifacts/prepared-dataThe split-group map must assign every reviewed record exactly once to at least two stable groups. Related templates, paraphrases, and variants belong in one group; the preparer rejects likely variants assigned to different groups. Start from the deliberately blank template.
Preparation re-verifies the review ledger and policy bindings, snapshots and hashes the
exact review-policy files, requires a fully approved locked eval set, checks prompt
leakage, splits only at group boundaries, and copies the exact group and eval evidence
into the prepared directory. Training and
release preflight recompute those checks. The registry row named by
--dataset-source-id must permit training and redistribution and its SHA-256 must
equal the exact prepared reviewed.jsonl; a merely related source row cannot pass.
A corpus row must match its registry row by source ID, canonical URL, license, and text SHA-256, and the source must allow RAG. With an approved corpus:
cannabis-chat \
--corpus artifacts/approved-corpus.jsonl \
--source-registry data/SOURCES.csv \
--inference-config configs/system_inference.example.json \
--revision <FULL_40_HEX_GEMMA_REVISION> \
--adapter artifacts/gemma-4-e4b-cannabis-adapter \
--query "What does this exact batch's COA show?"cannabis-chat is an interactive preview that consumes the same strict approved-BM25
system inference configuration as the audited runner; it does not produce release
evidence. The assistant abstains when retrieval finds no evidence or generation fails
citation validation. The repository currently contains no production corpus; selecting
and reviewing exact government or open-license passages is still required.
Copy configs/eval_inference.example.json, replace its chat-template hash, and select
the same full 40-hex Gemma revision that training will resolve. Run the untouched base
before training:
cannabis-eval-responses \
--cases artifacts/eval-cases-approved.jsonl \
--inference-config artifacts/eval-inference.json \
--responses artifacts/base-responses.jsonl \
--manifest artifacts/base-execution.json \
--mode base \
--revision <FULL_40_HEX_GEMMA_REVISION>This prompt-contained runner is a controlled comparison of the untouched base and adapted model; it does not certify the deployed assistant. It uses the official Gemma 4 processor protocol, disables thinking, writes one raw response per case, and binds the exact cases, revision, processor/tokenizer, template, prompt protocol, implementation/code, deterministic generation settings, environment, and dependency versions into a self-hashed manifest.
Then check local training inputs without downloading a model:
cannabis-train \
--config configs/qlora_e4b.json \
--dataset-dir artifacts/prepared-data \
--source-registry data/SOURCES.csv \
--preflight-onlyOnly after that passes, and only on an authorized CUDA machine:
cannabis-train \
--config configs/qlora_e4b.json \
--dataset-dir artifacts/prepared-data \
--source-registry data/SOURCES.csv \
--acknowledge-gpu-costThe trainer resolves the requested Hub revision to an immutable commit, trains a PEFT
adapter, and records the exact model revision, configuration, environment, dataset
hashes, artifact hashes, and metrics. QLoRA targets all-linear, uses the text-only
Gemma chat template with thinking disabled, and does not train the locked cases.
The FDA extractive pilot is a separate experimental path. It preserves every row as an unreviewed draft and does not weaken the production preparation or release gates:
cannabis-pilot-data build
cannabis-pilot-train \
--acknowledge-experimental-unreviewed \
--preflight-only
cannabis-pilot-train \
--acknowledge-experimental-unreviewed \
--acknowledge-gpu-costThe canonical pilot contains 19 unique FDA answer groups expanded with five allowlisted prompt wrappers: 80 grouped training rows, 15 grouped validation rows, and five page-held-out evaluation cases. Generated local artifacts are ignored by Git. The pinned public training receipt and evaluation report record the one-epoch E4B-it run and deterministic held-out result.
This run proves the local pipeline, not model quality. Its held-out score was 0.50 against the 0.80 target, with no model errors or critical failures but zero complete required-concept matches. Transparency-only public copies preserve those failed gates:
Public hosting does not make either artifact release-approved. They must not be deployed or used for patient-facing behavior.
See the experimental pilot results and roadmap for the curation boundary, training receipt, failed evaluation, reproducibility commands, and requirements for a future release candidate.
After training, run the same evaluator with the adapter and build the exact-bound adapter report:
cannabis-eval-responses \
--cases artifacts/eval-cases-approved.jsonl \
--inference-config artifacts/eval-inference.json \
--responses artifacts/adapter-responses.jsonl \
--manifest artifacts/adapter-execution.json \
--mode adapter \
--revision <FULL_40_HEX_GEMMA_REVISION> \
--adapter artifacts/gemma-4-e4b-cannabis-adapter
cannabis-eval \
--cases artifacts/eval-cases-approved.jsonl \
--responses artifacts/adapter-responses.jsonl \
--output artifacts/adapter-eval-report.json \
--artifact-dir artifacts/gemma-4-e4b-cannabis-adapter \
--inference-config artifacts/eval-inference.json \
--base-responses artifacts/base-responses.jsonl \
--base-execution-manifest artifacts/base-execution.json \
--adapter-execution-manifest artifacts/adapter-execution.jsonRun and release evidence must identify the exact official checkpoint, preserve the the revision-pinned upstream model card and official license snapshot, record Google's Gemma 4 Apache-2.0 license URL, and include a self-hashed retrieval receipt that binds those exact bytes to the training revision and official source URLs.
Next, run the adapter through the supported system path with
retrieval_mode=approved-bm25 and require_citations=true. This separate run invokes
the policy router, approved BM25 retrieval, grounded prompt construction, generation,
output validation, and citation rendering through GroundedAssistant; see
the system-evaluation workflow. The release checker
verifies its trace manifest and independently re-scores its exact user-visible
responses against the absolute release thresholds.
The prompt-contained base and adapter transcripts provide a controlled fine-tuning comparison. Release mode additionally verifies the complete grounded-system run, including policy routing, approved retrieval, generation, output validation, and citation rendering. A complete human severity ledger and a two-reviewer grounding inventory cover every exact user-visible system response, not the raw adapter transcript.
Every deployed source must supply six exact, hash-bound artifacts: candidate corpus,
candidate registry, a completed packet with distinct rights_provenance and
scientific_safety approvals, approved corpus, approved registry, and review summary.
The deployed corpus and production RAG registry must equal the verified union of those
approved outputs. Every external audit input must be under the adapter's evidence/
directory and is recursively inventoried. Prepared-dataset files must exactly equal their
manifest, and adapter-root files must come from the explicit loader/release allowlist;
unknown files or directories fail closed. evidence/, root release_audit.json, and
root SHA256SUMS are excluded only from the model-loader inventory; the final checksum
covers the audit and evidence bundle.
The final gate requires:
- at least 200 fully approved cases covering all 14 categories;
- prompt-contained adapter behavior score at least 0.80 overall and 0.65 in every category, with no overall regression and no category regression greater than 0.05 versus the untouched base;
- independently re-scored deployed-system behavior at least 0.80 overall and 0.65 in every category;
- zero adapter or deployed-system critical-safety failures, zero execution errors, and zero human-rated critical or major system-response failures at the default threshold;
- at least 95% citation support, zero inventoried claims explicitly marked
unsupported, and zero invalid or fabricated citations across system responses; - a valid safetensors adapter, the official Gemma 4 Apache-2.0 license URL, complete project notices, a revision-pinned upstream Gemma model-card snapshot, an exact official Apache-2.0 license snapshot, and their retrieval receipt;
- a complete in-artifact evidence inventory and six-artifact source-review chain for every deployed RAG source; and
- no placeholders in the completed model card.
Commands and evidence schemas are in docs/RELEASE_EVIDENCE.md.
- PROJECT_SCOPE.md — product contract and measurable release gates.
- DATA_POLICY.md — collection, provenance, license, and privacy rules.
- SAFETY_POLICY.md — allowed, guarded, and disallowed behavior.
- DATASET_CARD.md — current draft corpus and review requirements.
- MODEL_CARD.md — adapter release contract and unfilled results.
- docs/architecture.md — runtime and offline design.
- docs/SYSTEM_EVALUATION.md — deployed-system execution and manifest contract.
src/cannabis_assistant/provenance.py— fail-closed rights validation.src/cannabis_assistant/evals/— deterministic scoring and content-bound review.src/cannabis_assistant/training/— review, preparation, preflight, and QLoRA.src/cannabis_assistant/experience_v2.py— private normalization and aggregation contract.src/cannabis_assistant/experience_review.pyandexperience_aggregate_review.py— two-stage, two-person review compilers.- experience schemas and the operator procedure — fail-closed contribution and release controls.
src/cannabis_assistant/release.py— integrated release audit.