Learn AI with Rails: AI Topics You Must Know as a Senior Developer – Day 1

This is not an AI research course. It is a course to make you understand building AI-powered applications especially in your application like Ruby On Rails. You can use any interface or frameworks, but the idea is the same.

Day 1 – AI Fundamentals & LLMs (The Big Picture)

Goal

By the end of today, you should be able to confidently answer:

  • What is AI?
  • What is Machine Learning?
  • What is Deep Learning?
  • What is Generative AI?
  • What is an LLM?
  • How does ChatGPT actually work (at a high level)?
  • What is a Token?
  • What is a Context Window?
  • What is Temperature?
  • Why are there different models?
  • Where does Ruby on Rails fit into the AI ecosystem?

What you must learn?

A senior developer isn’t expected to explain transformer mathematics or derive attention equations.

Instead, they expect something like this:

“We integrated GPT-5 into our Rails application using the OpenAI API. We stored conversation history in PostgreSQL, streamed responses to the browser using Turbo Streams, and later improved answer quality by introducing a RAG pipeline backed by pgvector.”

That level of understanding is the target.

The Big Picture

Let’s zoom out.

Artificial Intelligence
Machine Learning
Deep Learning
Generative AI
Large Language Models
ChatGPT / Claude / Gemini

often ask about this hierarchy.


Step 1 – What is Artificial Intelligence?

Artificial Intelligence (AI) is the broad field of creating software that performs tasks normally associated with human intelligence.

Examples:

  • Recognising images
  • Translating languages
  • Understanding speech
  • Writing code
  • Answering questions
  • Driving cars

Notice that AI is an umbrella term.

Rails Analogy

Think of AI like Web Development.

Inside Web Development there are many areas:

  • Frontend
  • Backend
  • DevOps
  • Security
  • Performance

Similarly,

AI contains

  • Machine Learning
  • Robotics
  • Computer Vision
  • NLP
  • Reinforcement Learning
  • Generative AI

AI is not one single technology.


Step 2 – What is Machine Learning?

Traditional software follows explicit rules.

Example:

if age >= 18
  "Adult"
else
  "Minor"
end

The programmer writes every rule.

Machine Learning is different.

Instead of writing rules,

we provide:

Data
Algorithm
Model
Prediction

The model learns patterns from data.

Example:

100,000 spam emails
Machine Learning
Spam detector

Nobody writes:

if subject contains "FREE MONEY"

The model discovers useful patterns itself.

Question Answer

Machine Learning is a subset of AI where models learn patterns from data instead of relying solely on hand-written rules.


Step 3 – What is Deep Learning?

Deep Learning is a subset of Machine Learning.

Instead of simpler algorithms like decision trees or linear regression, it uses neural networks with many layers.

AI
Machine Learning
Deep Learning
LLMs

Question Answer

Deep Learning uses multi-layer neural networks to learn complex patterns from large datasets.

You don’t need to know the maths unless you’re interviewing for an ML engineering role.


Step 4 – What is Generative AI?

Most older AI systems classify or predict.

Examples:

Cat or Dog?
Spam or Not?
Fraud or Safe?

Generative AI creates new content.

Examples:

Text
Images
Music
Video
Code

ChatGPT generates text.

GitHub Copilot generates code.

Midjourney generates images.


Step 5 – What is an LLM?

This is the most common interview question.

LLM stands for Large Language Model.

Break it down:

Large

Trained on enormous datasets.

Language

Designed to understand and generate human language (and code).

Model

A trained neural network that predicts the next token.

The Most Important Sentence

An LLM predicts the most likely next token given the previous context.

That’s fundamentally what it does.

Everything else — chatting, coding, summarising, translation — is built on top of that capability.

Rails Analogy

Think of ActiveRecord.

You write:

User.where(active: true)

Rails converts that into SQL.

Similarly, when you type:

Write a Rails controller.

The LLM converts your prompt into a sequence of likely output tokens.

How ChatGPT Works (Simplified)

You type
Prompt
Tokenizer
Tokens
LLM
Next Token Prediction
Next Token
Next Token
Next Token
Final Response

Notice that the model does not generate an entire paragraph at once. It generates one token after another.

What is a Token?

This is one of the most frequently asked concepts.

A token is a chunk of text that the model processes.

It is not always a word.

Example:

Hello world

may be split into tokens similar to:

Hello
world

But longer or uncommon words can be split into multiple tokens.

For example:

internationalization

might become several tokens.

Models operate on tokens, not characters or words.

Why Tokens Matter

Every API request is billed based on tokens.

Input Tokens
+
Output Tokens
=
Cost

Tokens also affect:

  • latency
  • context limits
  • pricing

What is a Context Window?

The context window is the maximum amount of information (measured in tokens) the model can consider in one request.

It includes:

  • your system prompt,
  • conversation history,
  • retrieved documents (for RAG),
  • and the model’s response.

If you exceed the context window, older information may need to be removed or summarised before sending the request.

Rails Analogy

Imagine your Rails app sends this:

System Prompt
Conversation
PDF
User Message

Everything together must fit inside the model’s context window.


What is Temperature?

Temperature controls how deterministic or creative the model’s output is.

Low temperature (e.g. 0.0–0.2):

  • More consistent
  • Better for code
  • Better for SQL
  • Better for structured JSON

Higher temperature (e.g. 0.8–1.0):

  • More varied
  • Better for brainstorming
  • Better for creative writing

A useful interview answer:

Temperature influences randomness in token selection. Lower values produce more predictable outputs, while higher values encourage greater variation.


Why Are There Different Models?

A common misconception is that there’s one “best” model.

In reality, different models optimise different trade-offs:

Model CharacteristicBetter For
Small modelLower cost, lower latency
Large modelMore reasoning ability, richer responses
Vision modelImage understanding
Audio modelSpeech recognition and synthesis
Embedding modelSemantic search and RAG
Code-oriented modelProgramming assistance

As a senior engineer, you’ll often choose the model that best fits the use case rather than always selecting the most capable one.


Where Ruby on Rails Fits

A common question is:

“Does Rails perform the AI?”

No.

Rails orchestrates the AI workflow.

Browser
Rails
OpenAI / Anthropic / Gemini API
LLM
Rails
Browser

Rails is responsible for:

  • authentication,
  • storing conversations,
  • business logic,
  • background jobs,
  • rate limiting,
  • streaming,
  • persistence,
  • caching,
  • monitoring,
  • and integrating AI into the product.

The LLM performs the language generation.


Common Questions – Day 1

Try answering these aloud without looking back.

  1. What is Artificial Intelligence?
  2. How is Machine Learning different from traditional programming?
  3. What is Deep Learning?
  4. What is Generative AI?
  5. What is an LLM?
  6. Why is it called a Large Language Model?
  7. How does an LLM generate text?
  8. What is a token?
  9. Why do tokens matter?
  10. What is a context window?
  11. What is temperature?
  12. Does Ruby on Rails perform AI?
  13. Why are there different AI models?

If you can answer these clearly in your own words, you’ve built a strong foundation.


Practical Exercise 1 (30 minutes)

Use ChatGPT or Claude and experiment with temperature-like behaviour conceptually by changing the prompt.

Try:

Write a professional Ruby method
that calculates tax.

Then ask:

Write the same code
but optimise it for readability.

Then:

Write the same solution
using functional Ruby.

Observe how prompt specificity changes the output. This will prepare you for Day 2, where we’ll focus on prompt engineering.

Output – Gemini (3.1 Pro, 3.6 Flash)

Prompt 1: Write a professional Ruby method that calculates tax

Here is a professional, production-ready Ruby method for calculating a flat tax (like sales tax).

When dealing with financial calculations in Ruby, the most critical professional standard is never using floats. Standard floating-point math can introduce microscopic inaccuracies (e.g., 0.1 + 0.2 = 0.30000000000000004), which is unacceptable for currency.

This method uses Ruby’s standard BigDecimal library to ensure mathematical precision, includes basic input validation, and follows YARD documentation standards.

require 'bigdecimal'
require 'bigdecimal/util'

# Calculates the tax for a given financial amount.
#
# @param amount [Integer, Float, String, BigDecimal] The pre-tax amount.
# @param rate [Integer, Float, String, BigDecimal] The tax rate as a decimal (e.g., 0.08 for 8%).
# @return [BigDecimal] The calculated tax, rounded to 2 decimal places.
# @raise [ArgumentError] If the amount or rate is negative.
def calculate_tax(amount, rate)
  # 1. Input Validation
  raise ArgumentError, 'Amount cannot be negative' if amount.to_f.negative?
  raise ArgumentError, 'Tax rate cannot be negative' if rate.to_f.negative?

  # 2. Type Conversion
  # Convert inputs to BigDecimal to guarantee precision in financial math
  base_amount = amount.to_d
  tax_rate    = rate.to_d

  # 3. Calculation & Rounding
  # Multiply and round to the nearest cent (Banker's rounding by default)
  tax_total = base_amount * tax_rate
  tax_total.round(2)
end

Usage Examples

# Basic usage with standard numbers
tax = calculate_tax(150.50, 0.075) 
puts tax.to_f # => 11.29

# Handles strings seamlessly (common when receiving API or form data)
tax = calculate_tax("49.99", "0.20")
puts tax.to_f # => 10.0

# Raises errors for invalid business states
calculate_tax(-100, 0.05) # => ArgumentError: Amount cannot be negative

Why this is considered “Professional” code:

  • Precision (to_d): By requiring bigdecimal/util, we get the .to_d method, which safely converts Floats, Integers, and Strings into exact decimal objects before any math happens.
  • Defensive Programming: It explicitly checks for negative values, raising an ArgumentError early rather than silently returning a negative tax bill, which could cause havoc in an e-commerce checkout flow.
  • Rounding: It automatically rounds to two decimal places at the very end of the calculation, which is standard for most global currencies.

Prompt 2: Write the same code but optimise it for readability.

Here is the streamlined version, optimized for readability and idiomatic Ruby style:

require 'bigdecimal'
require 'bigdecimal/util'

def calculate_tax(amount, rate)
  raise ArgumentError, 'Inputs cannot be negative' if amount.to_f.negative? || rate.to_f.negative?

  (amount.to_d * rate.to_d).round(2)
end

What makes this version cleaner:

  • Single Guard Clause: Combines negative checks into a single line at the very top, declaring preconditions immediately.
  • Direct Expression: Replaces multi-step variable assignments (base_amount, tax_rate, tax_total) with a single expressive line: (amount.to_d * rate.to_d).round(2).
  • Zero Noise: Removes redundant inline comments and documentation headers while keeping 100% of the safety and decimal precision.

Prompt 3: Write the same solution using functional Ruby.

In functional programming, we prioritize pure functions, immutability, data pipelines, and higher-order/curried functions.

Here is the functional approach using a curried Proc combined with Ruby’s pipeline method (.then):

require 'bigdecimal'
require 'bigdecimal/util'

# Pure lambda with pipeline transformations and currying enabled
CalculateTax = ->(rate, amount) {
  raise ArgumentError, 'Inputs cannot be negative' if [amount, rate].any? { |val| val.to_f.negative? }

  [amount.to_d, rate.to_d]
    .then { |amt, rt| amt * rt }
    .then { |total| total.round(2) }
}.curry

What makes this Functional:

  • Currying (.curry): Enables partial application. You can fix the rate parameter once and reuse the resulting function across your codebase:
# Define a dedicated function by pre-supplying the tax rate
vat_calculator = CalculateTax.call(0.20)

vat_calculator.call(100) # => 20.0
vat_calculator.call(50)  # => 10.0
  • Pipeline Transformations (.then): Instead of intermediate variable assignments, data flows sequentially through pure, single-purpose transformations.
  • First-Class Function (CalculateTax): The logic lives in a callable object (lambda) rather than a class method, allowing it to easily be passed into higher-order collection processing like .map:
amounts = [10.0, 25.5, 99.99]
ny_tax  = CalculateTax.call(0.08875)

# Map over dataset purely
taxes = amounts.map(&ny_tax)

Practical Exercise 2 (Optional Rails)

Create a new Rails app (or use a scratch project) and sketch a minimal architecture for an AI feature.

For example:

app/
controllers/
chats_controller.rb
models/
conversation.rb
message.rb
services/
ai/
client.rb
jobs/
ai_response_job.rb

You don’t need to call an AI API yet. Just think about where the responsibilities belong. We’ll implement this later in the bootcamp.


Homework

  1. Draw the AI hierarchy from memory:
AI
Machine Learning
Deep Learning
Generative AI
LLMs
  1. Explain, in your own words, how an LLM generates text.
  2. Explain why tokens matter to both cost and context.
  3. Explain why a Rails application still needs authentication, databases, background jobs, and business logic even when it uses an LLM.
  4. Practice answering the 13 interview questions above without notes.

What’s Coming on Day 2

Day 2 will move from “What is an LLM?” to “How do we make LLMs useful?”

We’ll cover:

  • Prompt Engineering fundamentals
  • System vs User vs Assistant prompts
  • Zero-shot and Few-shot prompting
  • Structured outputs (JSON)
  • Function/Tool Calling
  • Prompt injection
  • Hallucinations and mitigation strategies
  • API request/response flow
  • Practical Ruby examples using an LLM API

By the end of Day 2, you’ll understand how to communicate effectively with LLMs – one of the most valuable practical skills for a senior Rails developer building AI-powered applications.

Happy AI Learning! 🚀