← The Forge
RAG Lab · Fundamentals

Embed, Store, Retrieve, Ground

The theory lesson described the pipeline. This lab runs it: embed real text, store it in the same Postgres this course already knows — via pgvector, one more instance of "Postgres goes further than the spec" — then retrieve the right chunk and hand it to a real Fire chat call.
Theory 1 of 2

One honest exception to "always go through Fire."

Fire has no embeddings endpoint as of this writing — check /v1/capabilities yourself rather than trusting this sentence forever. This lab calls an embeddings provider directly, which Week 5 already told you never to do. That's not a contradiction to gloss over — it's a real, current gap in this stack's own infrastructure, and noticing it is more valuable than a lab that pretends the gap doesn't exist.
Theory 2 of 2

Cosine distance always returns an answer — even a wrong one.

A nearest-neighbor query has no concept of "nothing here is actually relevant." It returns whatever is closest, full stop, even if the closest thing is still quite far away and useless. This lab's live break asks a question with nothing relevant in the store on purpose — watch the query still confidently return its top match.
Before the Practicum

One table, real pgvector syntax.

  • Same terminal as every other lab — click it, type or paste the command shown, Enter runs it.
  • A doc_chunks table already exists: id, content text, embedding vector(1536) — the real dimension for OpenAI's text-embedding-3-small.
  • <=> is pgvector's real cosine-distance operator — smaller means closer.
Done

Retrieval found the passage. Grounding is what happens after.

Everything up to the last exercise was search — find the closest stored text. The last step is what makes it RAG instead of just search: that retrieved text became part of a real /v1/chat call, in a user turn, next to the actual question. The model never touched your database. It only ever saw whatever your code decided to hand it — which is exactly why the live break mattered: hand it a bad match with enough confidence, and it will answer from the bad match just as fluently as a good one.
1 / 1
ends with a "mark complete" step