Applied AI

Nine original lessons · Fictional evidence · Explicit model, replay, parser and reviewer modes.

1. Design an evidence-first AI workflow

2. Run real local semantic retrieval

3. Evaluate retrieval and unsupported questions

4. Extract structured fields without hiding ambiguity

5. Validate model-shaped output and abstention

6. Review factual support claim by claim

7. Treat retrieved instructions as untrusted data

8. Record privacy, provenance, cost and latency

9. Deliver an inspectable Applied AI mini-project

1. Design an evidence-first AI workflow

Objective & prerequisites

Separate retrieval, extraction, validation and final factual review. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

A useful AI workflow starts with a task and an evidence contract. Retrieval finds candidate passages; it does not decide the answer is true. Extraction proposes fields from text; valid structure does not prove those values match the source. Factual-support review compares each atomic claim with eligible evidence, considering negation, dates, numbers and scope. Keep these boundaries visible in both code and reports. An unsupported question should produce an abstention or a request for evidence rather than a fluent guess. Source documents are untrusted data, even when retrieved by a model. This kit deliberately avoids a generative answer service so you can inspect each boundary before adding one.

Worked example

The corpus has eight short passages with IDs and versions: seven current and one retired draft. Queries include six answerable paraphrases and an unsupported breakfast question. A real pretrained encoder produced the supplied vectors; lab.py replays those vectors for the named fixture queries. A separate rule-based extractor handles narrow invoice text. Eight hand-authored claim cases are reviewed against sources. These are separate measured activities, not an end-to-end chatbot accuracy score.

from lab import load,validate_corpus
docs=validate_corpus(load("corpus.json"))
assert len(docs)==8
assert sum(d["status"]=="current" for d in docs)==7

Try it yourself

Draw input → eligible sources → retrieval → proposed claim/fields → structure check → evidence review → answer or abstain. Mark which steps are executed models, pure functions, human decisions and future integrations. Write a failure example at three boundaries. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

A retired source should be excluded before ranking; a repeated JSON key should fail parsing; a real quote accompanying a wrong numerical claim should still fail factual review. No generative model is invoked by the core command. Keep retrieval rankings and review labels as separate outputs so one cannot disguise a failure in the other.

Knowledge check

If retrieval finds a plausible passage, has the full answer been verified?

Check and explain

No. You still need eligible evidence, a supported interpretation and appropriate abstention. Retrieval is candidate selection.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://www.sbert.net/docs/sentence_transformer/usage/semantic_textual_similarity.html — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

2. Run real local semantic retrieval

Objective & prerequisites

Encode meaning-related text and compare it with a transparent keyword baseline. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

An embedding maps text into a learned vector space. Here a pinned all-MiniLM-L6-v2 ONNX model encodes short English text into 384 dimensions. Attention-mask mean pooling combines token vectors and L2 normalization makes their length one. Cosine similarity compares direction, not factual truth or probability of relevance. The keyword baseline computes normalized overlap of token sets and cannot infer paraphrases without shared words. The local encoder uses explicit model files and CPU inference; it does not call a hosted API. Inputs longer than 256 wordpieces are refused so evidence is not silently truncated. For longer documents, design chunks with stable document IDs, offsets, version and neighboring context before indexing.

Worked example

The supplied run encoded eight passages and seven queries with the pinned model. Q1 asks how long exercise files remain obtainable; D1 says practice downloads last fourteen days after enrolment. Semantic top result is D1, while keyword top result is D6. The saved vector file includes model revision, dimensions and source hashes. New text requires encode.py with the actual model; fixture_rank only accepts known fixture query IDs and refuses stale source hashes. A brute-force in-memory cosine index is sufficient here; no vector database is implemented or needed for eight passages.

from lab import load,fixture_rank,keyword_rank
q=load("queries.json")[0]
assert fixture_rank("Q1")[0]["id"]=="D1"
assert keyword_rank(q["text"],load("corpus.json"))[0]["id"]=="D6"

Try it yourself

Run the dependency-free replay and compare Q1 rankings. Optionally follow README to create a virtual environment, install the recorded semantic dependencies and explicitly download the pinned public model. Then run encode.py with a new short paraphrase. Do not describe replaying Q1 as encoding new text. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

fixture_rank("Q1")[0] is D1. keyword_rank for Q1 puts D6 first in this frozen corpus. Actual inference is invoked only with an explicit local --model-dir. fetch_model.py downloads about 91 MB of public files and verifies fixed hashes; model weights are not bundled into the website or small ZIP. The model card declares Apache-2.0; retain provenance and review terms for later uses. Similarity differences on this tiny authored set do not demonstrate universal superiority.

Knowledge check

Is a cosine score of 0.8 an 80% probability that an answer is true?

Check and explain

No. It is a geometric similarity score under the chosen representation. Relevance and factual support need their own evaluation.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

3. Evaluate retrieval and unsupported questions

Objective & prerequisites

Use relevance labels, ranking metrics and separate abstention cases. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

An evaluation set states which passages are relevant to which queries. A hit at k means at least one labelled relevant passage appears in the first k results. Reciprocal rank is 1 divided by the first relevant position; mean reciprocal rank averages this across queries. These fixture queries each have one relevant passage, so the report calls its metric hit rate rather than implying general multi-label recall. Keep development examples separate from test examples, freeze relevance labels and avoid tuning thresholds repeatedly against the same test labels. Seven authored questions cannot estimate performance for a real customer population. Include unsupported questions separately: a nearest-neighbor search always returns something when candidates exist, even when none answers the question.

Worked example

Three development and three answerable test questions are supplied. At k=3, both methods hit all three relevant test passages; semantic MRR@3 is 1.000 and keyword MRR@3 is about 0.611. Thus their hit rates match while ranking quality differs on this fixture. Q7, the breakfast question, has no relevant source and is excluded from answerable-query ranking metrics. Semantic retrieval still returns D6 first. That is not permission to answer. No score threshold was validated for automatic abstention; the reference reports this gap instead of inventing one.

from lab import load,fixture_rank,retrieval_metrics
qs=[q for q in load("queries.json") if q["split"]=="test" and q["answerable"]]
ranks={q["id"]:[r["id"] for r in fixture_rank(q["id"])] for q in qs}
assert retrieval_metrics(ranks,qs)["mrr_at_k"]==1.0

Try it yourself

Calculate reciprocal ranks from the saved rankings by hand. Explain why reporting only hit rate hides differences. Add one new question to a separate evaluation copy, label its relevant sources before measuring and document whether it is development or a fresh test. Unknown fixture IDs must fail until actual embeddings are generated. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

The test keyword relevant ranks are 3,2,1, giving (1/3+1/2+1)/3 ≈ 0.611. Semantic ranks are 1,1,1, giving 1.000. Both hit rates at three are 100% across only three questions. Q7 needs abstention because the supplied sources contain no breakfast preference. Record unanswered-query coverage separately from relevance ranking; do not count an unsupported query as an incorrect relevant-passage rank or quietly exclude its answer-generation risk.

Knowledge check

Can a retriever returning three high-scoring results guarantee the question is answerable?

Check and explain

No. The highest-ranked available source may still be irrelevant or insufficient. Answerability needs evidence beyond ranking.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://www.sbert.net/docs/package_reference/util.html — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

4. Extract structured fields without hiding ambiguity

Objective & prerequisites

Build a narrow deterministic baseline before considering a generative extractor. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

Structured extraction turns a source document into named typed fields. Begin with a clear schema and a baseline whose assumptions can be inspected. The reference accepts exactly one Invoice, Currency and Total line in a small fictional format. It converts decimal strings directly into integer cents, preserving a valid zero and avoiding floating-point money rounding. Repeated totals, missing values, unsupported currencies and thousands separators are refused rather than guessed. This parser is rule-based, not an LLM or a general invoice product. A later model must be compared against it on agreed source formats and error categories. Preserve the original source and record whether a field was extracted, missing, ambiguous or outside the supported contract.

Worked example

I1 is EUR 125.40 and becomes 12540 cents; I2 is EUR 0.00 and becomes zero. I3 has two totals and is rejected, I4 has no total and is rejected, I5 uses USD and I6 uses a comma separator, both unsupported here. The report matches the six declared fixture outcomes. That means agreement with this limited contract, not general invoice accuracy or accounting readiness. No OCR, PDF layout processing or tax interpretation is implemented.

from lab import extract_invoice,load
cases=load("invoices.json")
assert extract_invoice(cases[0]["text"])["total_cents"]==12540
assert extract_invoice(cases[1]["text"])["total_cents"]==0

Try it yourself

Run all six cases and build a table of ID, accepted/rejected, fields and reason. Add a negative amount and a three-decimal amount in a copy. Explain why silently choosing the last total or converting an unknown amount to zero would destroy evidence. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

Accepted IDs are I1 and I2; rejected IDs are I3–I6. Negative and three-decimal values fail the deliberately nonnegative two-decimal format. A real invoice may contain refunds or different locales, so new formats require a separately specified and tested contract rather than a claim that the source is inherently wrong. Keep missing or ambiguous values distinct from a known zero.

Knowledge check

Does the extractor accepting EUR 0.00 justify replacing a missing total with zero?

Check and explain

No. The first is explicit evidence; the second invents a value. Missing totals must be handled as missing under the contract.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://docs.python.org/3/library/re.html — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

5. Validate model-shaped output and abstention

Objective & prerequisites

Enforce types, fields and failure behavior while keeping factual checks separate. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

A prompt requesting JSON is not a reliable application boundary. Parse a bounded response, reject repeated keys and unexpected fields, then validate exact types, formats and bounds. Python bool is an integer subtype, so money uses an exact int check. Schema-valid values may still be false: a model can return 125400 cents in perfectly valid JSON even though the source says 12540. The answer envelope separately requires answer, citations and abstain. An abstention must have an empty answer and citation list. Citation IDs must name current eligible documents; their presence still does not establish support. A provider-contract exercise uses a local fixture function only, and refuses external mode. It is not an active hosted adapter or measured LLM extraction.

Worked example

validate_invoice accepts C-001/EUR/125400 structurally, illustrating a wrong-but-valid amount. Comparing it to I1’s known source result reveals the mismatch. validate_answer accepts the incorrect thirty-day claim with D1 because its role is structural validation, not entailment. The factual-review lesson must then reject that interpretation. A duplicate JSON key fails before schema validation. The code does not automatically repair malformed responses or repeatedly retry until an invented answer appears.

from lab import validate_invoice,extract_invoice,load
wrong=validate_invoice({"invoice_id":"C-001","currency":"EUR","total_cents":125400})
assert wrong!=extract_invoice(load("invoices.json")[0]["text"])

Try it yourself

Read extraction-prompt-template.txt and predict a source-supported object for I1 and null for ambiguous I3; these are expected answers, not measured LLM outputs. Create three local candidate strings: correct invoice, wrong-but-schema-valid amount and boolean money. Predict parsing, schema and source-agreement outcomes separately. Use provider_contract.py with a local fixture function, then attempt allow_external=True and confirm refusal. Do not supply real personal or employer records. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

The correct candidate passes structure and source comparison; the tenfold amount passes structure but fails comparison; True fails exact integer validation. External mode raises ValueError before calling the supplied function. A future provider would need an explicit transmission/privacy/cost contract and a separately tested adapter. No provider key, live response, token bill or model quality is claimed by the fixture callback.

Knowledge check

If a JSON schema validates a number, has the application verified that number against the document?

Check and explain

No. Type/shape validation is necessary but source agreement is a separate obligation.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://docs.python.org/3/library/json.html — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

6. Review factual support claim by claim

Objective & prerequisites

Distinguish supported, contradicted and insufficient claims with a reproducible rubric. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

Factual support is a relation between a particular claim and eligible evidence. Split compound claims into atomic statements, locate the relevant passage and compare entities, numbers, negation, time, conditions and quantifiers. Use supported only when the evidence establishes the claim; contradicted when it conflicts; insufficient when evidence is missing, outdated or cannot establish the whole assertion. The exact-quote locator checks whether text occurs in a current cited source. It intentionally returns human_review_required rather than a semantic verdict. A real quote can accompany a contradicted interpretation. Human reference labels are authored teaching judgments, not an unbiased model benchmark. The FActScore paper provides background on atomic factual evaluation; this three-label teaching rubric is not an implementation or validation of FActScore. For a real evaluation, define reviewer training, independent labels, disagreement handling and provenance.

Worked example

C1’s fourteen-day claim is supported by D1. C2 cites the same current document and quotes its true fourteen-day sentence, but claims thirty days: contradicted. C3’s job-offer promise has no evidence in a project-report passage. C4 adds guaranteed renewal to a source requiring review: insufficient for the compound claim. C5 reverses a negation; C6 contradicts the privacy instruction. C7 invents a quote and C8 cites a retired draft. The supplied imperfect human-review example gets 6/8 labels right, but only one of its three supported predictions is correct: supported precision is 1/3. This is not an LLM accuracy score.

from lab import load,evidence_checks,evaluate_reviews
case=load("claims.json")[1]
assert evidence_checks(case,load("corpus.json"))["quote_found"]
assert case["gold"]=="contradicted"
r=evaluate_reviews(load("claims.json"),load("reviews-example.json"))
assert r["accuracy"]==0.75
assert r["supported_precision"]==1/3

Try it yourself

Copy reviews-blank.json and label all eight cases before looking at gold labels/reasons. For each, write an atomic claim, current evidence quote and reason. Compare your labels with claims.json, investigate disagreements, then run evaluate_reviews. Explain why overall accuracy can look acceptable while unsupported claims are incorrectly approved. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

Gold labels are C1 supported; C2,C5,C6 contradicted; C3,C4,C7,C8 insufficient. The imperfect example falsely approves C2 and C4, giving 75% accuracy but 33.33% supported precision. Quote-found is true for C2 even though the number is wrong. C4 should be split: the download duration can be supported, but guaranteed renewal cannot. Do not force the whole compound statement into supported just because one part is correct.

Knowledge check

Can an exact quotation in a real current citation prove that an accompanying paraphrase preserves its meaning?

Check and explain

No. A paraphrase can reverse negation, alter a number or add a promise. Review the actual claim against the evidence.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://aclanthology.org/2023.emnlp-main.741/ — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

7. Treat retrieved instructions as untrusted data

Objective & prerequisites

Keep document content outside application permissions and tool authority. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

Prompt injection embeds instructions inside content that should be treated as evidence. D7 asks for a system password as an adversarial example; its retrieval rank does not give it authority. A warning prompt alone cannot enforce authorization. Keep document eligibility and ownership checks outside the model, allow only deliberately supported actions, validate arguments and avoid executing generated code. This kit has no shell tool, file-reading tool or external provider action at inference time. An inactive example is not a proof of resistance for a future agent. If later sources become private, enforce user scope before retrieval and again at access/export boundaries; a vector index is not an authorization system.

Worked example

D7 can appear among results for Q5 even though D6 is the relevant answer passage. The local workflow prints rankings and never interprets the document text as an application command. D8 is excluded as retired before ranking, including for citation validation. These are tested narrow controls. They do not verify a live LLM against every injection strategy or establish security for a multi-user vector service.

from lab import validate_answer,load
try:
    validate_answer('{"answer":"Seven days","citations":["D8"],"abstain":false}',load("corpus.json"))
except ValueError:
    pass
else:
    raise AssertionError("Retired source must be refused")

Try it yourself

Locate D7 in the corpus, write what a vulnerable agent might do and identify the external permission control that should stop it. Test an answer citing D8 and an invented ID. Explain why filtering after presenting a private retrieved passage would be too late. Do not probe real systems or use real secrets. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

Both retired and unknown citation IDs are refused. A retrieved request to reveal credentials is document data and cannot authorize a tool or disclosure. For a private index, filter eligible documents before scoring and constrain downstream access; if no eligible evidence remains, abstain. Document the lack of an actual tool executor in this kit rather than calling it a deployed agent-defense system.

Knowledge check

Does a highly similar source passage gain permission to choose an arbitrary filesystem path or external destination?

Check and explain

No. Content relevance and application authority are different. Permissions must be enforced independently.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://genai.owasp.org/llmrisk/llm01-prompt-injection/ — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

8. Record privacy, provenance, cost and latency

Objective & prerequisites

Write an operating contract that distinguishes actual measurements from assumptions. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

A local model still has operating costs and data-handling responsibilities. Document what leaves the device, what is retained, which model files execute, what is cached and how failures are surfaced. This kit’s explicit setup downloads public weights and packages but sends no source documents or queries to an inference provider. Actual encode.py uses only pinned local files. The core replay uses only the packaged fixture vectors and standard library. A future hosted provider needs explicit owner approval of data categories, endpoint, retention, budget, timeout, retry and failure rules; no such provider is implemented here. Zero paid API calls does not mean zero compute, storage or maintenance cost.

Worked example

The recorded initial CPU run encoded fifteen short texts in about 1.81 seconds including model setup/hash validation; it is one local observation, not a service-level promise or p95 latency. File sizes, SHA-256 hashes and immutable model revision are recorded. The ZIP excludes roughly 91 MB of model files and all installed Python dependencies. It includes saved vectors and an optional dependency inventory. Dependencies and model formats need maintenance review; a checksum verifies consistency with a recorded artifact, not perpetual safety or an independent security audit.

from lab import load
v=load("embeddings.json")
assert v["runtime"]["dimensions"]==384
assert v["runtime"]["provider"]=="CPUExecutionProvider"
assert v["runtime"]["silent_truncations"]==0

Try it yourself

Complete privacy-cost-contract-template.txt for the current local workflow and a separate hypothetical hosted version. List transmitted data, retained artifacts, estimated resource use, permitted actions and unknowns. Run replay twice and explain why its elapsed time cannot be reported as model inference latency. If you install the optional runtime, record your actual versions and timing. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

The current workflow has public setup downloads, local fictional inference, no external provider request and no paid token bill. Replay timings measure loading/scoring cached vectors, not generating embeddings. Real inference includes tokenization, model loading and CPU operations; report the measurement boundary and hardware. Future provider cost/latency/privacy remain unmeasured. Do not invent a provider price or claim an untested hosted adapter is ready.

Knowledge check

If replay takes 0.02 seconds, can you advertise that as the live model’s response time?

Check and explain

No. It is a different execution mode and measurement boundary. Report each mode accurately.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://onnxruntime.ai/docs/get-started/with-python.html — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.

9. Deliver an inspectable Applied AI mini-project

Objective & prerequisites

Build a small evidence report that makes model, parser and reviewer limitations visible. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.

python3 lab.py
python3 -m unittest discover -s tests -v

Understand the concept

A useful portfolio artifact lets a reviewer reproduce its claims. Keep the corpus, version/eligibility rules, queries and relevance labels, model identity, extraction schema, review rubric and failure cases together. Separate a retrieval scorecard from extraction agreement and factual-support judgments. Preserve the original fixtures and add a clearly labelled new scenario rather than editing expectations until the code passes. If you add a passage or query, its embeddings must be regenerated with the pinned model; the saved-vector mode deliberately detects stale source hashes. A new real deployment is outside this exercise and requires its own security, privacy and operating review.

Worked example

The baseline artifact includes keyword versus semantic rankings, six narrow invoice outcomes and eight human-reviewed claims. Its visual report shows both successes and deliberate failures. A good extension adds one invented paraphrase, one ambiguous extraction and one claim with a changed number. Establish expected relevance/handling before executing, run actual local encoding for new text if available and mark any skipped optional runtime honestly. A reviewer can then inspect your own contribution without confusing it with supplied teaching code.

python3 lab.py
python3 -m unittest discover -s tests -v
# Optional actual new-text inference after explicit setup:
# python3 encode.py --model-dir ./model --query "Can I hand my workshop credit to someone else?"

Try it yourself

Complete the worksheet and mini-project rubric. Produce a 250–400 word evidence memo, one new case per boundary and test outputs. State whether you used real inference or only replay. If you cannot install the model, complete the core lessons and label the new semantic case unexecuted; do not invent a vector or relabel a keyword score as semantic. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.

Worked solution

A strong memo reports three-answerable-query test MRR with its tiny denominator, the unsupported Q7 case, exact extraction failures and the difference between citation membership and claim support. It identifies all fictional data, records model/runtime provenance and discloses that no generative extraction, autonomous support judge, production vector database or hosted adapter is delivered. No job offer, client outcome or production-readiness guarantee follows from completing the activity.

Knowledge check

Would a working local semantic search justify claiming a deployed, fully factual AI assistant?

Check and explain

No. It proves the bounded local encoder/retrieval work actually executed. Generation, truth evaluation, authorization and operating acceptance need separate evidence.

Evidence, mistakes & handover

Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.

Authoritative reference

https://onnxruntime.ai/docs/get-started/with-python.html — official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.