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
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
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
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 Hugging Face 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
- Using the OpenAI APIs in Racket
- Using Google Gemini APIs in Racket
- Using the Anthropic APIs in Racket
- Using a Local Hugging Face Llama2-13b-orca Model with Llama.cpp Server
- Using a Local Mistral-7B Model with Ollama.ai
- 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 Shared Interrupt Flag
- The Provider-Agnostic Agentic Loop
- The Fireworks AI Client
- The Ollama Client
- The Tool Registry
- The Approval and Diff System
- Web Search Integration
- The Main REPL
- 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 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
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
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