Skip to main content

Participant guide

Session 01 · Building AI applications for research and data

The notebooks​

Six notebooks build one application step by step. Open them in Google Colab from the repository, or clone the repository and run them locally.

NotebookAddsTime to read
01 · From a language model to an applicationInstructions and context15 min
02 · Preparing knowledge for an applicationMetadata, chunks, embeddings, an index15 min
03 · Retrieval-augmented generationRetrieval, citations, a retrieval failure and its fixes20 min
04 · Connecting the application to data and toolsA data tool, tool calls, a typed output20 min
05 · Workflows and agentsTwo tools, a fixed workflow and a bounded loop20 min
06 · VerificationClaim tags and a verifier for every number15 min

Every notebook is committed with its outputs, so it can be read without running anything. The notebooks are built on LangChain, LangGraph, FastMCP, Pydantic, and the program's pcn-core; notebooks/requirements.txt lists the versions.

Running without a key​

The notebooks run in a fresh Colab environment with no API key. Model outputs are then recorded ones, labelled [recorded output: ...], replayed by a LangChain chat model that stands in for the live one. Everything else runs for real: the vector store, retrieval, the data tool, the MCP server, the schemas, the agent graph, and the verifier.

Running with a key​

Set three values, in Colab under Secrets or in the environment:

VariableMeaningDefault
WORKSHOP_API_KEYKey for an OpenAI-compatible chat APInone; recorded outputs are used
WORKSHOP_BASE_URLBase URL of the API, for a gateway or a self-hosted modelthe OpenAI endpoint
WORKSHOP_MODELModel namegpt-4o-mini

With a key, the same cells call the model live. Outputs will differ from the recorded ones in wording; the behaviours the text describes should hold. Where they do not, that is a finding worth noting.

Never write a key into a notebook. The setup cell reads it from the environment.

Running locally​

git clone https://github.com/worldbank/ai4data.git
cd ai4data/training/session-01-building-ai-applications/notebooks
pip install -r requirements.txt jupyter
jupyter lab

The embedding model (about 90 MB) downloads on first use.

The shared code​

notebooks/workshop.py holds what the libraries do not: the worked-example data and the indicator tool over it, a chat model that replays recorded outputs, the output schemas, the claim-tag parsing that hands numbers to pcn-core, and the evaluation helpers. notebooks/indicator_server.py is the same tool as a FastMCP server. Together about 450 lines.

Exercises​

Each notebook ends with one exercise. In recorded mode some exercises ask for a prediction, because a changed prompt has no recorded output. With a key, every exercise runs.

Further reading​