|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "raw", |
| 5 | + "id": "49a58314", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "---\n", |
| 9 | + "title: \"A guide to Generative AI for the working scientist\"\n", |
| 10 | + "date: 2025-10-29\n", |
| 11 | + "author:\n", |
| 12 | + " - name: Charles F. Vardeman II\n", |
| 13 | + " id: cfv\n", |
| 14 | + " orcid: 0000-0002-1825-0097\n", |
| 15 | + " email: cvardema@nd.edu\n", |
| 16 | + " affiliation:\n", |
| 17 | + " - name: Center for Research Computing, University of Notre Dame\n", |
| 18 | + " city: Notre Dame\n", |
| 19 | + " state: IN\n", |
| 20 | + " url: https://crc.nd.edu\n", |
| 21 | + " - name: CI-Compass\n", |
| 22 | + " url: https://ci-compass.org\n", |
| 23 | + "keywords:\n", |
| 24 | + " - Generative AI in Science\n", |
| 25 | + " - Science Agents\n", |
| 26 | + "license: \"CC BY\"\n", |
| 27 | + "citation:\n", |
| 28 | + " type: document\n", |
| 29 | + " container-title: Zenodo\n", |
| 30 | + " doi: 10.5281/zenodo.10815117\n", |
| 31 | + "links:\n", |
| 32 | + " - text: \"Video Presentation\"\n", |
| 33 | + " url: \"https://www.youtube.com/@cicompass\"\n", |
| 34 | + " - text: \"GitHub Repository\"\n", |
| 35 | + " url: \"https://github.com/ci-compass/AI-working-scientist/\"\n", |
| 36 | + "funding: \"This project is supported by the U.S. National Science Foundation Office of Advanced Cyberinfrastructure in the Directorate for Computer Information Science under Grant #2127548\"\n", |
| 37 | + "format:\n", |
| 38 | + " html:\n", |
| 39 | + " toc: true\n", |
| 40 | + " code-fold: true\n", |
| 41 | + "---" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "markdown", |
| 46 | + "id": "49926eb8", |
| 47 | + "metadata": {}, |
| 48 | + "source": [ |
| 49 | + "## GitHub CI-compass Organization\n", |
| 50 | + "- [GitHub Link: https://github.com/ci-compass/AI-working-scientist/tree/main](https://github.com/ci-compass/AI-working-scientist/tree/main)" |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "markdown", |
| 55 | + "id": "984505e3", |
| 56 | + "metadata": {}, |
| 57 | + "source": [ |
| 58 | + "# A guide to Generative AI for the Working Scientist\n", |
| 59 | + "\n", |
| 60 | + "> This video is meant to be a rough guide to some of the concepts and to help understand generative AI and preparation for the NSF CyberInfrastructure Center of Excellence [CI-Compass](https://ci-compass.org/) [Virtual Workshop - AI Meets CI: Intelligent Infrastructure for Major & Midscale Facilities](https://ci-compass.org/news-and-events/events/virtual-workshop-ai-meets-ci-intelligent-infrastructure-for-major-and-midscale-facilities/). The purpose is to start from the beginning and try to de-mystify **chatbot** based Generative AI.\n", |
| 61 | + "\n", |
| 62 | + "" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "markdown", |
| 67 | + "id": "b4f311d9", |
| 68 | + "metadata": {}, |
| 69 | + "source": [ |
| 70 | + "## Agents and \"Agentic\" Workflows\n", |
| 71 | + "- [Sequoia AI Ascent event, \"What's next for AI agentic workflows ft. Andrew Ng of AI Fund\", https://youtu.be/sal78ACtGTc](https://youtu.be/sal78ACtGTc)\n", |
| 72 | + "- [Andrew Ng, \"The Batch\", Issue 253, June 12, 2024, https://www.deeplearning.ai/the-batch/issue-253/](https://www.deeplearning.ai/the-batch/issue-253/)\n", |
| 73 | + "\n", |
| 74 | + "> Rather than having to choose whether or not something is an agent in a binary way, I thought, it would be more useful to think of systems as being agent-like to different degrees. Unlike the noun “agent,” the adjective “agentic” allows us to contemplate such systems and include all of them in this growing movement.\n", |
| 75 | + "\n", |
| 76 | + "Andrew Ng Defined four \"Agentic Patterns\"\n", |
| 77 | + "- Reflection \n", |
| 78 | + "- Tool use\n", |
| 79 | + "- Planning\n", |
| 80 | + "- Multi-agent collaboration" |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "markdown", |
| 85 | + "id": "7716a095", |
| 86 | + "metadata": {}, |
| 87 | + "source": [ |
| 88 | + "### However, this hasn't stopped the discussions on what is \"Agentic\"\n", |
| 89 | + "\n", |
| 90 | + "> \"An LLM agent runs tools in a loop to achieve a goal.\"\n", |
| 91 | + "\n", |
| 92 | + "- [I think “agent” may finally have a widely enough agreed upon definition to be useful jargon now](https://simonwillison.net/2025/Sep/18/agents/)\n", |
| 93 | + "\n", |
| 94 | + "\n", |
| 95 | + "- [Matt Pocock, X, https://x.com/mattpocockuk/status/1975655749251436738](https://x.com/mattpocockuk/status/1975655749251436738)" |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "markdown", |
| 100 | + "id": "fb00e108", |
| 101 | + "metadata": {}, |
| 102 | + "source": [ |
| 103 | + "### \"Vibe Coding\" and \"YOLO Mode\"\n", |
| 104 | + "\n", |
| 105 | + "Vibe Coding: [Mirriam-Webster](https://www.merriam-webster.com/slang/vibe-coding) and [Wikipedia](https://en.wikipedia.org/wiki/Vibe_coding) coined by Andrej Karpathy\n", |
| 106 | + "> \"Vibe coding (also written as vibecoding) is a recently-coined term for the practice of writing code, making web pages, or creating apps, by just telling an AI program what you want, and letting it create the product for you. In vibe coding the coder does not need to understand how or why the code works, and often will have to accept that a certain number of bugs and glitches will be present. The verb form of the word is vibe code.\"\n", |
| 107 | + "\n", |
| 108 | + "> \"YOLO mode,\" in the context of vibe coding, is an approach where a developer gives an autonomous AI agent complete control to execute tasks without requiring human permission. The name comes from the acronym YOLO (\"You Only Live Once\"), and it represents a high-risk, high-speed approach to AI-assisted development. \n", |
| 109 | + "\n", |
| 110 | + "- [Chika Ihejimba, PhD, \"Vibe Coding\", Apr 09, 2025,https://chikaihejimba.substack.com/p/vibe-coding](https://chikaihejimba.substack.com/p/vibe-coding)" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "markdown", |
| 115 | + "id": "320416e8", |
| 116 | + "metadata": {}, |
| 117 | + "source": [ |
| 118 | + "## Retrieval Augmented Generation (RAG)\n", |
| 119 | + "Imagine you’re building a giant language model (LLM) like ChatGPT. It’s been trained on lots of text, so it “knows” a lot of patterns. But two problems still bite you:\n", |
| 120 | + "\n", |
| 121 | + "- Memory / scale: The model’s internal weights can only capture so much. If you want up-to-date facts, niche documents, very large corpora, you can’t just cram all of that into the params.\n", |
| 122 | + "- Hallucination / accuracy: Pure generation means the model might “make things up” or approximate rather than fetch exact info.\n", |
| 123 | + "\n", |
| 124 | + "So the idea: let the model retrieve relevant documents / passages at inference time, then feed those as context into the LLM so it can generate an answer grounded in real retrieved material. That’s RAG." |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + "cell_type": "markdown", |
| 129 | + "id": "ccac6e86", |
| 130 | + "metadata": {}, |
| 131 | + "source": [ |
| 132 | + "### RAG pieces (modular breakdown)\n", |
| 133 | + "\n", |
| 134 | + "**The retrieval system:**\n", |
| 135 | + "- You have a large corpus (documents, web pages, knowledge-base).\n", |
| 136 | + "- Build an index (e.g., embedding index, vector store) so you can map a query → “top-k relevant documents”.\n", |
| 137 | + "- Techniques: embedding models (convert query + docs to vectors), nearest neighbour search (FAISS, Annoy, HNSW).\n", |
| 138 | + "- Example: embed each document d_i → v_i, embed query q → v_q, then find docs whose vectors v_i are near v_q (cosine similarity).\n", |
| 139 | + "- Output: a small set of snippets, passages, maybe full docs: D = \\{d_1, d_2, \\dots\\}.\n", |
| 140 | + "\n", |
| 141 | + "**The generation model (LLM):**\n", |
| 142 | + "- A transformer-based model trained for text generation (autoregressive, or sequence to sequence).\n", |
| 143 | + "- At inference, you concatenate or otherwise provide the retrieved docs + the user query (and maybe instructions) as input.\n", |
| 144 | + "- The LLM uses those docs as context to generate a response.\n", |
| 145 | + "\n", |
| 146 | + "**The glue / orchestration:**\n", |
| 147 | + "- You need to design how the docs are inserted into the prompt: inline, chunked, ranked, maybe with metadata (source, doc id).\n", |
| 148 | + "- You might filter/re-rank docs (only top 5, or only high quality).\n", |
| 149 | + "- You might decide how to prompt the model so it “uses” the docs (e.g., “Using the passages below, answer the question”, or “You are an expert, refer to the sources”).\n", |
| 150 | + "- You might include a source attribution mechanism (so answer can cite which doc it came from).\n", |
| 151 | + "\n", |
| 152 | + "<hr>\n", |
| 153 | + "\n", |
| 154 | + "- [I. Flath, \"Retrieval 101\",2025-03-17, https://isaacflath.com/blog/2025-03-17-Retrieval101](https://isaacflath.com/blog/2025-03-17-Retrieval101)\n", |
| 155 | + "- [I. Flath, \"Late Chunking: The Better Way to Embed Document Chunks\",2025-04-09,https://isaacflath.com/blog/2025-04-08-LateChunking](https://isaacflath.com/blog/2025-04-08-LateChunking)" |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + "cell_type": "markdown", |
| 160 | + "id": "59a5430d", |
| 161 | + "metadata": {}, |
| 162 | + "source": [ |
| 163 | + "### GraphRAG\n", |
| 164 | + "\n", |
| 165 | + "So, you already know **RAG (Retrieval-Augmented Generation)**.\n", |
| 166 | + "It solves “my LLM can’t remember the whole internet” by adding a retriever that fetches relevant chunks from a **vector database** — little islands of meaning.\n", |
| 167 | + "\n", |
| 168 | + "But here’s the problem:\n", |
| 169 | + "\n", |
| 170 | + "> “The world is not a pile of paragraphs. It’s a web of relationships.”\n", |
| 171 | + "\n", |
| 172 | + "Documents reference each other, entities co-occur, knowledge is relational.\n", |
| 173 | + "Plain RAG sees text as isolated chunks.\n", |
| 174 | + "GraphRAG connects them into a **knowledge graph** — a structure that encodes who is related to what and how.\n", |
| 175 | + "\n", |
| 176 | + "So instead of searching over disjoint vectors, we search and reason over a **graph topology**.\n", |
| 177 | + "\n", |
| 178 | + "🌐 GraphRAG Idea:\n", |
| 179 | + "\n", |
| 180 | + "- Represent knowledge as a **graph** (entities + relations).\n", |
| 181 | + "- Retrieval = **traversal**, not just vector search.\n", |
| 182 | + "- Feed connected **subgraphs** (not isolated chunks) to the LLM.\n", |
| 183 | + "\n", |
| 184 | + "<hr>\n", |
| 185 | + "\n", |
| 186 | + "- [Microsoft Research, \"GraphRAG: Unlocking LLM discovery on narrative private data\" (February 13, 2024), https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/](https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/)" |
| 187 | + ] |
| 188 | + }, |
| 189 | + { |
| 190 | + "cell_type": "markdown", |
| 191 | + "id": "41abbfff", |
| 192 | + "metadata": {}, |
| 193 | + "source": [ |
| 194 | + "### GraphRAG Example GraphRAG for Scientific Insight (Wikidata)**\n", |
| 195 | + "\n", |
| 196 | + "**Question (user query):**\n", |
| 197 | + "*“Which proteins interact with BRCA1 and are linked to breast cancer?”*\n", |
| 198 | + "\n", |
| 199 | + "**Why GraphRAG (intuition):**\n", |
| 200 | + "\n", |
| 201 | + "* RAG pulls **text chunks** → good facts, weak relationships\n", |
| 202 | + "* GraphRAG walks a **knowledge graph** (entities + relations) → multi-hop, explainable answers\n", |
| 203 | + "\n", |
| 204 | + "**We’ll click real nodes & relations:**\n", |
| 205 | + "\n", |
| 206 | + "* **BRCA1** (human tumor-suppressor) → [https://www.wikidata.org/wiki/Q227339](https://www.wikidata.org/wiki/Q227339) ([Wikidata][1])\n", |
| 207 | + "* **Breast cancer** → [https://www.wikidata.org/wiki/Q128581](https://www.wikidata.org/wiki/Q128581) ([Wikidata][2])\n", |
| 208 | + "* Property **“interacts with”** (`P129`) shown on BRCA1’s page (scroll to statements)\n", |
| 209 | + "* Property **“genetic association”** (`P2293`) definition → [https://www.wikidata.org/wiki/Property:P2293](https://www.wikidata.org/wiki/Property:P2293) ([Wikidata][3])\n", |
| 210 | + "\n", |
| 211 | + "**Example path you can inspect by clicking through BRCA1’s statements:**\n", |
| 212 | + "\n", |
| 213 | + "```\n", |
| 214 | + "BRCA1 --(interacts with/P129)--> RAD51 family protein\n", |
| 215 | + "RAD51* --(genetic association/P2293)--> Breast cancer\n", |
| 216 | + "```\n", |
| 217 | + "\n", |
| 218 | + "Helpful RAD51 paralogs (human):\n", |
| 219 | + "\n", |
| 220 | + "* **RAD51C** → [https://www.wikidata.org/wiki/Q18031015](https://www.wikidata.org/wiki/Q18031015) ([Wikidata][4])\n", |
| 221 | + "* **RAD51B** → [https://www.wikidata.org/wiki/Q18031016](https://www.wikidata.org/wiki/Q18031016) ([Wikidata][5])\n", |
| 222 | + "\n", |
| 223 | + "> Tip: On the BRCA1 page, use the **“Statements”** section to find “interacts with,” click the target protein item, then look for disease associations on that protein’s page.\n", |
| 224 | + "\n", |
| 225 | + "** Generated entirely by ChatGPT using thinking, reflection and tool use." |
| 226 | + ] |
| 227 | + }, |
| 228 | + { |
| 229 | + "cell_type": "markdown", |
| 230 | + "id": "571d1935", |
| 231 | + "metadata": {}, |
| 232 | + "source": [ |
| 233 | + "### GraphRAG Agentic Flow\n", |
| 234 | + "\n", |
| 235 | + "**1) Retrieve entry points (semantic search over labels/aliases):**\n", |
| 236 | + "Find BRCA1 and nearby nodes (proteins it *interacts with*) via their Wikidata pages.\n", |
| 237 | + "\n", |
| 238 | + "* BRCA1 → open statements → find **P129 (interacts with)** targets. ([Wikidata][1])\n", |
| 239 | + "\n", |
| 240 | + "**2) Expand neighborhood (graph traversal):**\n", |
| 241 | + "From those proteins (e.g., RAD51 family), follow **P2293 (genetic association)** to diseases (e.g., breast cancer).\n", |
| 242 | + "\n", |
| 243 | + "* P2293 docs → scope & meaning. ([Wikidata][3])\n", |
| 244 | + "* Breast cancer item for cross-check. ([Wikidata][2])\n", |
| 245 | + "\n", |
| 246 | + "**3) Serialize subgraph for the LLM (prompt context):**\n", |
| 247 | + "Minimal triples you can copy from the pages you clicked:\n", |
| 248 | + "\n", |
| 249 | + "```\n", |
| 250 | + "<BRCA1> --interacts with--> <RAD51C>\n", |
| 251 | + "<RAD51C> --genetic association--> <Breast cancer>\n", |
| 252 | + "```\n", |
| 253 | + "\n", |
| 254 | + "(You can substitute **RAD51B** similarly.) ([Wikidata][4])\n", |
| 255 | + "\n", |
| 256 | + "**4) Generate grounded answer (LLM prompt):**\n", |
| 257 | + "“Using these Wikidata facts (with Q-IDs/links), explain how BRCA1’s interaction partners connect to breast cancer and cite the items.”\n", |
| 258 | + "\n", |
| 259 | + "**TL;DR:**\n", |
| 260 | + "\n", |
| 261 | + "```\n", |
| 262 | + "LLM weights → baked patterns\n", |
| 263 | + "RAG → fetch similar text\n", |
| 264 | + "GraphRAG → walk the graph (entities/relations), then generate\n", |
| 265 | + "= Retrieval-Augmented Reasoning\n", |
| 266 | + "```" |
| 267 | + ] |
| 268 | + } |
| 269 | + ], |
| 270 | + "metadata": { |
| 271 | + "solveit_dialog_mode": "learning", |
| 272 | + "solveit_ver": 2 |
| 273 | + }, |
| 274 | + "nbformat": 4, |
| 275 | + "nbformat_minor": 5 |
| 276 | +} |
0 commit comments