Small, focused, runnable examples for the AI fundamentals articles on snehalagrawal.com.

Each directory is self-contained, with its own README, setup instructions, and .env.example. These are educational demos, not production code.

Example What it shows Article
embeddings-semantic-search/ Keyword search vs. embedding-based semantic search, cosine similarity, and where similarity misleads (Python and JavaScript) Embeddings Explained
vector-search-at-scale/ Why exact search stops scaling, HNSW and IVF recall vs. latency on real embeddings, and the metadata-filtering trap (Python and JavaScript) Vector Databases Explained
prompt-as-interface/ Testing a prompt like an interface: three prompts, 24 test cases (answerable, not in the documents, planted instructions), two local models (Python and JavaScript) Prompt Engineering: Beyond Writing Better Prompts
generation-parameters/ Temperature, top-k, top-p, min-p, seeds, max tokens and stop sequences, measured: predicted vs observed token choices, and a temperature experiment on the support assistant (Python and JavaScript) Temperature, Top-P, and Other LLM Parameters Explained
structured-outputs/ Asking for JSON vs JSON mode vs strict schemas on the support assistant: what a schema guarantees, what it doesn’t, and the error and truncation paths (Python and JavaScript; Groq free tier or Ollama) Structured Outputs: Making LLMs Produce Reliable Data
tool-calling/ The support assistant with four tools: how a model requests a call, why the application decides what runs, and what goes wrong (questions turned into actions, invented arguments, claimed actions, planted instructions). Python and JavaScript; Ollama or Groq Function Calling and Tool Use in LLMs
llm-inference/ Where the time and memory go in inference, measured on local models: prefill vs decode, time to first token, the KV cache (predicted and checked), prompt caching, and model size vs generation speed (Python and JavaScript; Ollama) How LLM Inference Works
first-llm-app/ The model as the whole product versus the same model inside a small application: input validation, context, a guarded call, output checks, application-owned replies, and request logs, on ten real-world inputs (Python and JavaScript; Ollama). Also readiness probes: the Python application against a simulated provider, showing what it already handles and what it can’t answer yet (Python only; no model) Building Your First LLM-Powered Application; readiness probes: What Changes When an AI Prototype Goes to Production?
streaming-responses/ Streaming a reply from the model to the user’s screen, measured: when the first words appear, how a buffering proxy erases that, whether the model keeps generating after the user leaves, and what checks on streamed text show or withhold (Python and JavaScript; Ollama) Streaming LLM Responses: Why and How
conversation-state/ What an application sends a model in a long conversation: full history, the last N turns, a token budget, a running summary, or a structured case record; what silently falls outside the context window; and which facts the model can still answer (Python and JavaScript; Ollama) Managing Conversation State in AI Applications

Conventions

  • Examples support a cloud provider and a local option (Ollama) where practical.
  • Configuration goes through environment variables. Never commit a .env file.
  • Every demo passes the repository’s linters (below).

Linting

One configuration at the repository root covers every demo: Ruff for Python (ruff.toml) and ESLint for JavaScript (eslint.config.js).

# once, from the repository root
npm install                          # ESLint (root package.json holds only the lint tools)
pip install -r requirements-dev.txt  # Ruff (or: brew install ruff, pipx install ruff)

# check everything
npm run lint          # both
npm run lint:js       # ESLint only
npm run lint:py       # Ruff only
ruff check --fix .    # apply Ruff's safe automatic fixes

Ruff checks pycodestyle errors and warnings, Pyflakes, import order, bugbear, and pyupgrade rules, for Python 3.10. Long lines are allowed, because several demos print aligned tables. ESLint uses its recommended rules for Node.js ES modules.

From the repository's README on GitHub, synced Nov 24, 2026.

← All work