Python, from Zero, for AILesson 82 of 89

Module 9 · Building the thing: a small AI program, end to end

A response cache on sqlite: the re-run that costs nothing

In this lesson

  • 9 min read
  • 9 reading sections
  • Knowledge check
  • Lesson 3 of 10 in this chapter

This chapter’s goalAssemble a complete tool from the course’s parts (a chat loop with bounded history, injection-resistant prompt templates, a sqlite response cache, a document chunker, a local embedding search over your own notes, a free local model as the fallback provider) expose it through a Gradio interface and a FastAPI endpoint, run it on a schedule without double-processing, and gate every change behind a GitHub Actions job that runs the tests.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:39Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 11Free · no account needed
Lesson steps

Why a disk cache

Module 7’s lru_cache lives in memory and dies with the process. During development you run the same script twenty times an afternoon, and each run sends the same forty prompts to a paid model. Twenty runs of forty calls is eight hundred charged requests to check whether your CSV parser handles a comma. A cache that survives restarts makes runs two to twenty free, and makes a test suite that hits a real model affordable to run on every commit.

sqlite3 is in the standard library, needs no server, stores everything in one file, and handles a million rows without noticing. It is the right tool for this.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘A response cache on sqlite: the re-run that costs nothing’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/a-sqlite-response-cache (Accessed: 21 November 2026).