AI MOOC
✦ Grow togetherInvite 3 friends, earn 1 month of membership · Up to 12 monthsInvite friends →

Library / My reading notes

Connect a real model and inspect failures

Optionally execute real local generation and identify the stage reached.

Back to the RAG course plan: Build a searchable, cited RAG knowledge base

Chapter 6 / 8 · Read and take notes

Optionally execute real local generation and identify the stage reached.

Understand the method

Only this chapter calls a real service, using Ollama at 127.0.0.1:11434/api/chat. Follow official setup and inspect installed names with ollama list. Choose a model compatible with your device rather than assuming an example name is installed.

Replace MODEL_NAME with an installed name. --ask requires --model. The request sets model, messages, stream=false and format=json; disabling streaming allows one complete response document. The request timeout is 120 seconds.

HTTP 200 is insufficient. The program saves the raw response under runs/, then parses message.content as JSON and validates its structure. Extra prose, missing fields, wrong types and unknown citations fail explicitly. Do not replace a failure with a reference answer.

Connection refusal suggests the service or address; an unknown model suggests its installed name; timeouts may involve loading or hardware. Verify the model independently with official tools. Preserve malformed responses for diagnosis instead of calling every failure a network issue.

The result records model, elapsed_seconds and evidence. One request duration is not throughput. Run Q1/Q2 twice and review citations and abstention stability. Without a response, report generation as unrun or failed while retaining valid retrieval work.

Local inference uses device resources. Start small with the public corpus. No paid API or browser key is required. Connecting a cloud provider later introduces separate data, terms and cost decisions; this lab does not claim those are implemented.

  1. 1Environment
  2. 2Request
  3. 3Parse
  4. 4Diagnose

Included material

ollama list
# Replace MODEL_NAME with your actual installed model name.
python3 rag_lab.py --case Q2 --model MODEL_NAME
python3 rag_lab.py --case Q6 --model MODEL_NAME > model-answer.json

Work through the steps

  1. Check service and installed model, or record this chapter as unrun.
  2. Run Q1/Q2 and save actual responses, model name and evidence.
  3. Try an invalid model name to observe explicit failure, then restore the installed name.

Worked example

Run record: actual date, installed model, original Q2 JSON, structural result, factual review of the missing cap, and any error. A failure is retained rather than relabeled as success.

Your exercise

Document one failure, evidence, one change and a retry. If no model can run, use the actual service failure and do not invent an answer.

Check before delivery

  • Identify model calls separately from retrieval.
  • Retain real responses and errors without substituting references.
Finish the exercise, then view the reference

Generation acceptance requires a real response, valid structure and factual review. State each result separately. Connection failure says nothing about model quality; valid structure says nothing about correctness.

An original course with teaching exercises. Reading records, practice outcomes and independent certification are distinct.

References and further reading

The lessons are original. The following sources are provided under their respective permissions.

Article / guide

Prompt Engineering Guide

DAIR.AI · en/zh

MIT

License checked. This entry links to the original; the book text is not mirrored.

License checked: 2026-10-16 · Pinned 57673726
Article / guide

RAG and Vector Databases

Microsoft · en/zh

MIT

License checked. This entry links to the original; the book text is not mirrored.

License checked: 2026-10-16 · Pinned d45da912
Whitepaper / report

NIST AI 600-1: Generative AI Profile

NIST / Autio et al. · en

NIST Technical Series reprint policy

Original PDF provided under the institution’s reprint policy.

License checked: 2026-10-16
Article / guide

Ollama Chat API

Ollama · en

Official documentation link; no full-text reproduction

Original link only; full text is not mirrored.

License checked: 2026-10-20