Preface
- Requests from the Author
- License for Book Manuscript: Creative Commons
- Book Example Programs
- Racket, Scheme, and Common Lisp
- Personal Artificial Intelligence Journey: or, Life as a Lisp Developer
- Acknowledgements
Tutorial and Using Datastores
A Quick Racket Tutorial
- Installing Packages
- Installing Local Packages In Place
- Mapping Over Lists
- Hash Tables
- Racket Structure Types
- Simple HTTP GET and POST Operations
- Using Racket ~/.racketrc Initialization File
- Tutorial Wrap Up
Datastores
- Accessing Public RDF Knowledge Graphs - a DBPedia Example
- SQlite
- Optional Practice Problems
Implementing a Simple RDF Datastore With Partial SPARQL Support in Racket
- 1. Core RDF Data Structures and Basic Operations
- 2. Query Parsing and Execution
- 3. Helper Functions and Utilities
- 4. How a Join Actually Runs, Step by Step
- 5. Saving and Loading Triples: N-Triples Persistence
- 6. Adding FILTER to the Engine
- 7. Testing the Engine
- Conclusion
- Optional Practice Problems
Webscraping and Browser Use
Web Scraping
- Getting Started Web Scraping
- Implementation of a Racket Web Scraping Library
- Optional Practice Problems
Interfacing with External Programs: A Lightpanda Browser Client
- The Problem: JavaScript-Rendered Web Content
- Project Structure
- Configuration
- Running External Programs with
subprocess - HTML Parsing: Extracting Links
- The Main API Function
- Helper Functions
- Usage Examples
- Key Racket Takeaways
- Optional Practice Problems
Large Language Models
Building a MicroGPT in Racket
- Introduction
- Demystifying the Core Components
- Conclusion
- Complete Source Code Listing for
microgpt.rkt - Wrap Up
- Optional Practice Problems
Using the Google Gemini, OpenAI, Anthropic, Mistral, and Local Large Language Model APIs in Racket
- The Cambrian Explosion in Language Technology: A Historical Trajectory
- Commercial and Open Weight LLMs
- Introduction to the Applications of LLMs
- A Uniform API for LLMs in Racket:
llmapis.rkt - Dedicated Provider Modules and Proprietary Features
- Architecture and File Organization
- Examples Using William J. Bowman’s Racket Language LLM
- Optional Practice Problems
Ollama Tools/Function Calling in Racket
- How Tool Calling Works
- A Racket Tools Library
- Complete Example Using the Tools Library and Example Tools
- Writing Your Own Tools
- Testing Tools Without a Running Ollama Server
- Safety and Sandboxing
- Design Tips for Your Own Tools
- Summary
- Optional Practice Problems
A Racket Coding Agent
- The Agentic Loop
- Module Architecture
- The Provider-Agnostic Agentic Loop
- The Fireworks AI Client
- The MLX Client
- Hierarchical Provider Configuration
- The Tool Registry
- The Approval and Diff System
- Web Search Integration
- The Main REPL
- The Command-Line Interface
- Running the Agent
- Interpreting the Output
- Wrap Up
- Optional Practice Problems
Retrieval Augmented Generation of Text Using Embeddings
- Example Implementation
- What an Embedding Actually Is
- Chunking: the Most Underrated Part of RAG
- Retrieval, Without Thresholds
- Testing the Pipeline
- Production Notes
- Retrieval Augmented Generation Wrap Up
- Optional Practice Problems
Agentic RAG Using the Gemini API
- Architecture
- Embeddings and Vector Math
- The Vector Store
- The Agents
- Running the Demo
- Testing Without the Network
- Wrap Up
- Optional Practice Problems
Deep Learning, Natural Language Processing and Knowledge Graphs
Deep Learning in Racket with Malt: From XOR to a Two-Tower Recommendation System
- Why neural networks and why XOR first?
- The Malt mental model
- Every malt function used in this chapter, defined
- Example 1: XOR, the smallest non-linear problem
- Example 2: Two hidden layers learn a curved boundary
- Example 3: A jointly learned two-tower recommender
- Interlude: the bug that made the model learn nothing
- Malt survival guide (hard-won)
- Files in this directory
Category-Theory Deep Learning in Racket
- Why category theory for machine learning
- The mathematics of the five perspectives
- The data
- Implementation
- Running the code
- Interpreting the results
- Summary
Reinforcement Learning in Racket: Bandits, Q-Learning, Policy Gradients and DQN
- The three problems in one picture
- Part 1: Multi-armed bandits
- Part 2: Tabular temporal-difference control
- Part 3: Policy gradient methods
- Part 4: Deep Q-Networks
- Where the sharp edges are
- Exercises
Natural Language Processing
- NLP Wrap Up
- Optional Practice Problems
Knowledge Graph Navigator
- Entity Types Handled by KGN
- KGN Implementation
- Knowledge Graph Navigator Wrap Up
- Optional Practice Problems
Rule Based Symbolic AI Systems
Implementing OPS5 in Racket: A Forward-Chaining Production System
- Production Systems and Forward Chaining
- The Rete Algorithm
- Conflict Resolution
- The OPS5 Language
- The Example Programs
- The Racket Conversion: One File of Pure Code
- The Top-Level Commands as Macros
- Compiling a Production into the Network
- The Network Interpreter
- Working Memory
- The Recognize-Act Loop
- Running the RHS
- Running the Code
- Interpreting the Results
- Wrap Up
- Optional Practice Problems
Logic Programming with Racklog: Two Classic Problems Revisited
- Forward Chaining vs. Backward Chaining
- Problem One: Analyzing a Card Hand
- Problem Two: The Monkey and the Bananas
- Wrapping Up
- Exercises
Miscellaneous Short and Interesting Projects
Computing Pi and e: Fourteen Classical Algorithms in Exact Arithmetic
- The Oldest Calculation in Mathematics
- A Tour of the Algorithms
- The Program at a Glance
- Part 1: File Header and Exports
- Part 2: The Fixed-Point Number Helpers
- Part 3: The Pi Algorithms
- Part 4: The Algorithms for e
- Part 5: Reference Values and the Registry Scaffolding
- Part 6: The Method Registry
- Part 7: Reporting, the Console UI, and the Command Line
- The Test Suite
- Running the Code
- Interpreting the Results
- Wrap Up
- Optional Practice Problems