Sell Your Logic
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
Level 2 · Retrieval-augmented generation (RAG)

Logictote Kids Lab · Ask Baby Tote

Look things up before you answer

Children ask science questions. Before the model answers, our code finds the few lesson notes that are about the question and gives the model only those, so answers stay true, short and inside what our labs teach.

The business need

Children ask anything: "how many planets are there?" on the Magnets page. Answers must be correct, short, kind and safe, and a small local model on its own is often unsure or wrong.

59 → 99

evaluation score before and after RAG (48 test questions)

68.6% → 100%

answers containing the required fact

0.62

minimum similarity, chosen from a threshold sweep

How one request flows

From the visitor's words to what they see, step by step.

  1. 1

    Safety first

    Personal details and unsafe topics are handled before anything else, without any AI.

  2. 2

    Embed the question

    The question becomes a vector of 768 numbers that captures its meaning.

  3. 3

    Vector search

    Postgres finds the lesson notes closest in meaning, above a minimum similarity.

  4. 4

    Ground

    Only those notes go into the prompt. The model explains them in Baby Tote's voice.

  5. 5

    Filter

    Links, formatting and anything too long are removed after the model.

  6. 6

    Learn more

    Links to our labs are built by code from the notes used, never by the model.

The key ideas

Chunking: one idea per piece

Notes are cut into chunks of one to three sentences. Too big and a chunk is about everything at once; too small and it loses its context.

Embeddings: meaning as numbers

Texts with similar meaning get vectors that point the same way, even with no shared words. "Why does my fridge magnet stick?" lands next to "A magnet pulls on things made of iron".

Vector search in Postgres

The pgvector extension stores the vectors and sorts by cosine distance. With a few hundred chunks an exact scan takes milliseconds; an index is only needed at many thousands.

A threshold beats a guess

Below the minimum similarity a note is treated as "not about this question". No notes is better than misleading notes.

The page as context

The page the child is on adds its own related notes, so "what gas is in the bubbles?" means pondweed on the Photosynthesis page and fizzy drinks on the Fizzy page.

Only change what changed

Each chunk has a hash of its text. Editing one line re-embeds one chunk, not the whole library.

RAG does not replace safety

Retrieval improves what Baby Tote knows, not who it talks to. Every safety layer runs before retrieval, and nothing a child types is stored.

Never worse than before

No vectors, a sleeping model or no provider: each step falls back to the page's own notes or the closest note, so a child is never stuck.

What testing taught us

Found by running the real model, not by guessing. This is the most useful part.

Measure retrieval and answers separately

If the right note is never retrieved, no prompt can fix the answer. So the evaluation checks retrieval (is the right page in the top 4?) apart from grounding (does the answer contain the required fact?).

A good-sounding idea made it worse

Putting the page title in front of every question before searching sounded clever. Measured, it lowered retrieval and let off-topic questions match, so it was removed.

Choosing the threshold from data

A sweep showed 0.62 as the highest value that lost no recall and the lowest that let no off-topic question pull in a note.

Refusing everything is not safe, it is useless

Before RAG the model refused "is it safe to touch a wall socket?". With the safety notes retrieved, it now answers "Never touch a wall socket…". The evaluation counts wrong refusals as failures too.

What you learn at this level

  • Chunking
  • Embeddings
  • Vector search with pgvector
  • Similarity thresholds
  • Grounding in retrieved notes
  • Evaluation sets
  • Safety for a young audience

Where it stops

The test questions were written by the same person who wrote the notes, so they are easier than real children's questions. A new test item is added whenever a tester reports a bad answer.

Open now · free

AI Playground

Change chunk size, similarity threshold, model and prompt on our case studies, and see what was retrieved, the exact prompt, the answer, the speed and the cost.

Open the Playground →
Live · paid with tokens

Live workshops

Hands-on sessions that build each level step by step, hosted by our founder and by experts on SellYourLogic.

See the workshops