{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Gena Notebooks: Company and course knowledge\n",
    "\n",
    "Turn example meeting notes and lecture material into a small, structured question-and-answer dataset that can be reviewed before use in an AI workflow. This notebook uses only fictional sample content authored for this demonstration.\n",
    "\n",
    "## Read before running: data handling\n",
    "\n",
    "- The meeting notes and lecture excerpt below are synthetic. Do not replace them with private company, customer, employee, student, or course information unless you have permission and have reviewed your organization's privacy, security, and retention requirements.\n",
    "- Gena provides this downloadable file; it does not receive your notebook inputs or run this code. Python runs in the browser on your device or on the Jupyter server you connect to. That runtime and its provider handle your session and files. Review its privacy and retention terms before using non-public data.\n",
    "- The code uses Python's standard library only. It does not send requests, call an AI model, install packages, or upload data. Exported files are written to the working directory of the runtime you chose.\n",
    "\n",
    "This is a data-preparation example, not a complete knowledge base or a deployed assistant. Review every answer against its cited source before using a dataset."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Set up the fictional source material\n",
    "\n",
    "The company example is a fictional project meeting. The course example is a fictional lecture excerpt. Each question and answer is written to be traceable to a short source excerpt; no real people, organizations, or course materials are represented."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "company_notes = [\n",
    "    {\n",
    "        \"source_id\": \"synthetic-company-meeting-01\",\n",
    "        \"text\": \"The fictional Northstar Bikes team agreed to test the new repair-booking page with five volunteer riders next Wednesday. Mira will prepare the test script by Monday. The team will decide whether to expand the pilot after reviewing the feedback.\",\n",
    "    },\n",
    "    {\n",
    "        \"source_id\": \"synthetic-company-meeting-02\",\n",
    "        \"text\": \"The team has not chosen a launch date. The booking page is still a pilot, and the next decision depends on the volunteer test feedback.\",\n",
    "    },\n",
    "]\n",
    "\n",
    "course_excerpt = [\n",
    "    {\n",
    "        \"source_id\": \"synthetic-course-lecture-01\",\n",
    "        \"text\": \"In this fictional lesson, evaporation is the process in which liquid water changes into water vapor. The Sun provides much of the energy that drives evaporation at Earth's surface.\",\n",
    "    },\n",
    "    {\n",
    "        \"source_id\": \"synthetic-course-lecture-02\",\n",
    "        \"text\": \"Water vapor cools and condenses into tiny liquid droplets, forming clouds. When droplets combine and become heavy enough, water can fall as precipitation.\",\n",
    "    },\n",
    "]\n",
    "\n",
    "print(f\"Company excerpts: {len(company_notes)}\")\n",
    "print(f\"Course excerpts: {len(course_excerpt)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Create reviewable question-and-answer records\n",
    "\n",
    "These records are curated examples rather than model-generated answers. Every answer includes its supporting source text and source ID. The `domain` and `record_type` fields keep company and course examples distinguishable when the dataset is reused."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "records = [\n",
    "    {\n",
    "        \"domain\": \"company\",\n",
    "        \"record_type\": \"meeting_action\",\n",
    "        \"source_id\": company_notes[0][\"source_id\"],\n",
    "        \"source_text\": company_notes[0][\"text\"],\n",
    "        \"question\": \"When will the repair-booking page be tested, and who will prepare the script?\",\n",
    "        \"answer\": \"Five volunteer riders will test it next Wednesday. Mira will prepare the test script by Monday.\",\n",
    "    },\n",
    "    {\n",
    "        \"domain\": \"company\",\n",
    "        \"record_type\": \"decision_status\",\n",
    "        \"source_id\": company_notes[1][\"source_id\"],\n",
    "        \"source_text\": company_notes[1][\"text\"],\n",
    "        \"question\": \"Has the team chosen a launch date?\",\n",
    "        \"answer\": \"No. The page is still a pilot, and the team will decide whether to expand it after reviewing test feedback.\",\n",
    "    },\n",
    "    {\n",
    "        \"domain\": \"course\",\n",
    "        \"record_type\": \"concept_explanation\",\n",
    "        \"source_id\": course_excerpt[0][\"source_id\"],\n",
    "        \"source_text\": course_excerpt[0][\"text\"],\n",
    "        \"question\": \"What is evaporation, and what energy source drives much of it at Earth's surface?\",\n",
    "        \"answer\": \"Evaporation is liquid water changing into water vapor. The Sun provides much of the energy that drives it at Earth's surface.\",\n",
    "    },\n",
    "    {\n",
    "        \"domain\": \"course\",\n",
    "        \"record_type\": \"process_step\",\n",
    "        \"source_id\": course_excerpt[1][\"source_id\"],\n",
    "        \"source_text\": course_excerpt[1][\"text\"],\n",
    "        \"question\": \"How can water fall from clouds as precipitation?\",\n",
    "        \"answer\": \"Water vapor cools and condenses into droplets. When droplets combine and become heavy enough, water can fall as precipitation.\",\n",
    "    },\n",
    "]\n",
    "\n",
    "print(f\"Prepared {len(records)} records\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Inspect the evidence and data shape\n",
    "\n",
    "Source excerpts are included to support human review. In a real project, decide whether source text may be retained in a training or retrieval dataset; remove or protect sensitive details where required. Do not treat the examples as verified company policy or course instruction."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for record in records:\n",
    "    print(f\"[{record['domain']} / {record['record_type']}] {record['question']}\")\n",
    "    print(\"Answer:\", record[\"answer\"])\n",
    "    print(\"Evidence ID:\", record[\"source_id\"])\n",
    "    print(\"Evidence:\", record[\"source_text\"])\n",
    "    print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Run basic quality checks\n",
    "\n",
    "These checks catch missing fields and duplicate questions, but they do not establish factual accuracy, completeness, privacy compliance, or suitability for model training. A subject-matter reviewer should verify each answer against its source."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "required_fields = {\"domain\", \"record_type\", \"source_id\", \"source_text\", \"question\", \"answer\"}\n",
    "assert records, \"No records were created\"\n",
    "assert all(required_fields <= record.keys() for record in records), \"A record is missing a required field\"\n",
    "assert all(all(str(record[field]).strip() for field in required_fields) for record in records), \"A required value is empty\"\n",
    "\n",
    "questions = [record[\"question\"].casefold().strip() for record in records]\n",
    "assert len(questions) == len(set(questions)), \"Duplicate questions found\"\n",
    "assert {record[\"domain\"] for record in records} == {\"company\", \"course\"}, \"Expected both example workflows\"\n",
    "\n",
    "for domain in (\"company\", \"course\"):\n",
    "    print(f\"{domain}: {sum(record['domain'] == domain for record in records)} records\")\n",
    "print(\"Basic structural checks passed. Human review is still required.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. Export a JSON Lines dataset\n",
    "\n",
    "Each output line is one record, which is convenient for later review or ingestion. The file is saved only to the working directory of your selected runtime; download it from that runtime's file browser if you want a local copy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from pathlib import Path\n",
    "\n",
    "output_path = Path(\"company-course-knowledge.jsonl\")\n",
    "with output_path.open(\"w\", encoding=\"utf-8\") as output_file:\n",
    "    for record in records:\n",
    "        output_file.write(json.dumps(record, ensure_ascii=False) + \"\\n\")\n",
    "\n",
    "print(f\"Wrote {len(records)} records to {output_path.resolve()}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Limitations and next steps\n",
    "\n",
    "- The fictional examples are tiny and manually authored; they are not a representative dataset, benchmark, or evidence of model quality.\n",
    "- Answers may omit nuance even when they cite a source. Review them with an authorized subject-matter expert before use.\n",
    "- This notebook does not split data for evaluation, train or query a model, connect to a company or learning platform, or verify access rights.\n",
    "- Real meeting and course materials can contain confidential, personal, copyrighted, or regulated information. Confirm permission, minimize data, and follow applicable retention and access policies before processing them.\n",
    "- Gena does not execute this notebook or retain its session. Your chosen browser or Jupyter runtime handles the code and exported file; its provider's terms and settings apply."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
