← All notes

Note · Being written · Updated 2026-11-13

Siya: a chat that answers from my own guides

How the chat on this site finds the right pages of my guides, hands them to an AI through the Vercel AI Gateway, and falls back to plain search when the AI fails. Explained in plain words, with a video and things to click.

New to AI? Start with the video. No background needed: every technical word is explained as it appears, and the list at the bottom translates the rest.

Step 1 of 8

How my chat answers questions from my own guides

Siya looks things up first, then writes. A one-minute tour, no jargon.

The short version

Look it up first. Then write.

  1. 1

    Look up

    Find the few pages of my guides most likely to hold the answer.

  2. 2

    Hand over

    Give those pages to an AI, with the rule “answer only from these”.

  3. 3

    Write

    The AI writes a short answer, and the sources are linked underneath.

  4. 4

    Plan B

    If the AI fails, answer straight from the guides instead.

An AI on its own answers from memory, and memory can be wrong. So instead of trusting its memory, Siya looks up my real pages every time and asks the AI to use only those. The technical name for this is RAG (retrieval-augmented generation): retrieve the right notes, then generate the answer.

Follow one question

Eight stops, from your question to the answer

Open any stop to see what happens in plain words, why it exists and what happens if it fails. Switch on the engineering detail if you want the specifics.

  1. Like: Ctrl+F across a whole library, but cleverer: rare words count for more than common ones.

    What happens, step by step

    1. 1Your question is broken into keywords. Little words (the, how, is) are dropped, and endings are trimmed so “publishing” matches “publish”.
    2. 2Every passage in the guides gets a score for how well it matches those keywords.
    3. 3A rare word (like “Storybook”) earns more points than a common one (like “component”).
    4. 4A keyword in a passage’s title earns a bonus.
    5. 5If you are reading a chapter, that chapter’s passages get a 35% boost.
    6. 6The five best passages move on.

    Why it is there

    An AI model can only use what is put in front of it. Finding the right five pages out of 133 is what makes the answer about my guides and not about anything on the internet.

    If it goes wrong

    If nothing matches, the question is treated as off-topic and Siya says so, instead of guessing.

Try it

Meet the librarian

This is the “look it up” step, running live in your browser. Type a question and watch which passages win, and which words earned the points.

Step 1 · The keywords Siya keeps

Little words are dropped and endings trimmed.

publishcomponent

Step 2 · The best passages, best first

Longer bar, better match. Tap one to see which words earned the points.

These are six sample passages written for this page, scored with the same method and the same tokenizer as the real chat. The real index has 133 passages. The top five go to the AI.

Its library

What Siya knows (and does not)

Siya only knows what is in this tree: the passages of my two guides, read from the same file the chat uses. Open a branch to see the real sections.

  • A script can turn my own component notes into passages after removing code, links, emails, addresses and client words, and dropping any section that still looks sensitive. A person reviews a report first. Nothing has been approved into it yet, so today the chat answers from the guides only.

  • Anything outside these pages: the live internet, news, your own files or accounts, and anything about a person’s private details. Asked about those, it says it is outside what it can help with.

When things go wrong

What if the AI fails?

Pick a problem and see the path the question takes. The aim: the visitor always gets something useful.

1

Is an AI model set up?

Is there a key for the Gateway or for OpenAI?

Yes
2

Did the model start answering?

Did words come back?

Yes
3

Try once more. Did it answer this time?

The free model sometimes returns nothing, so there is one retry.

skipped

What the visitor gets

An AI answer, streamed, with sources

A key is set and the model answers on the first try. You see the AI answer streaming in, with sources.

System design

The architecture map: click a part, click a badge

Every box is a part of the system. Tap one to see what goes in and out, what happens when traffic grows and when it fails. Tap a badge to learn the system-design idea it stands for, and to light up every part that has it.

Filter by a badge: every part that has it lights up

Browser

Your server

Built ahead of time

Outside services

Your server

Chat route (/api/siya)

The coordinator. It checks the visitor, finds passages, builds the prompt, calls the model, streams the answer and runs plan B.

Talks to

Goes in

Messages and the page path.

Comes out

A streamed answer with source links.

If traffic grows

General reasoning: serverless copies are added as requests arrive, and most of a request is spent waiting on the model, not computing.

If it fails

On any model failure it retries once, then answers from search.

At bigger scale

Add a queue only if requests must survive restarts. For a chat, streaming straight through is simpler.

Statements about growing traffic are general system-design reasoning, not measurements of this site.

System design

How to approach any system design question

The same nine steps work for a chat, a shop or a feed. Step through them, with this project as the worked example.

1. Clarify

What to do

Ask what it must do, for whom, and what “good” means before drawing anything.

Say it out loud

“Who uses it, what do they ask, and what matters most: accuracy, speed, cost or privacy?”

For Siya

Visitors ask questions about my guides. It must answer from the guides, cite sources, cost almost nothing, never leak client details, and never just break.

A design choice

Keyword search or embeddings?

Both ways answer the same question: “which of my pages is most likely to hold the answer?” They differ in how they decide. Keyword search looks at the exact words. Embeddings look at the meaning.

How it matches

Keyword: Counts shared words. “publish” finds pages that contain “publish”.

Embeddings: Turns text into a list of numbers that stands for its meaning. “ship my component” can find a page about publishing, with no shared word.

Extra pieces needed

Keyword: None. A few lines of code that run inside the same function.

Embeddings: An embedding model to convert every page and every question, and somewhere to store and search the numbers (a vector database or an index).

Cost

Keyword: Nothing beyond the function that is already running.

Embeddings: A small cost to convert the pages once, and to convert every question, plus storage for the numbers.

Speed

Keyword: Instant. It is just arithmetic in memory.

Embeddings: One extra network call per question (to convert it), then a search.

Exact names and commands

Keyword: Strong. A rare name like “Storybook” or a command is matched exactly.

Embeddings: Weaker. Meaning-based search can blur exact names and error codes.

Different wording

Keyword: Weak. If you use words my guide never uses, it can miss. (Siya says “not in the guides” instead of guessing.)

Embeddings: Strong. Handles synonyms and rephrasing much better.

Explaining a result

Keyword: Easy. You can show which words scored. The lab above does exactly that.

Embeddings: Hard. A similarity score does not say why.

Updating the content

Keyword: Rebuild one JSON file.

Embeddings: Re-convert and re-store every changed page.

General properties of the two approaches, not measurements from this site.

Why keyword search fits this chat

The content is small and specific
The guides are 133 passages across 31 chapters, full of exact names (component types, commands, error text). Exact words are what people type, so exact-word search is a good match for this material.
No extra service to run or pay for
The chat is designed to cost nothing to run (a free default model). Keyword search adds no database, no second AI call and no bill, so the whole feature fits in one function.
It is easy to explain and fix
When an answer is wrong, I can see which words scored and why. That makes it practical to debug and to teach, which is what this note does.
It fails honestly
If the guides do not use your words, Siya says it could not find it, rather than returning something that merely sounds close.

The honest trade-off: if a visitor describes a problem in words my guides never use, keyword search can miss it. Embeddings are better at that. They are the natural next step, and the cleanest way to add them is on top of keyword search, not instead of it (see the ideas below).

Try it

Where you cut the text changes what can be found

Before search, long text is cut into pieces (chunks). Slide the size and overlap, pick a question, and watch which piece wins and whether it still makes sense on its own.

3 chunks · about 184 characters each · best match highlighted

  • To publish a component, run the publish command. It builds your component and uploads it to Pega, and asks which environment to use. Before you publish, check that the build output folder exists. A production build is smaller
  • best matchand faster than a development build. Storybook shows a component on its own page with stand-in data, so you can see it without logging in. Start it with one command and open the address it prints. Tests check that a component
  • still works after a change. Run the test command, and fix anything that fails before you publish again.

A balanced size: enough context to make sense, little else. Siya does not cut at a fixed size: it cuts at each section heading of a guide, so a passage is one idea, and trims each to 1,800 characters.

Try it

How do you know search is any good?

Not by feel. Keep a list of questions with the passage that should come up, and count. Change a setting and see the score move.

Found in the top 3

5 / 6 (83%)

  • How do I publish a component?The right passage came 1st. Words match the guide.
  • What is Storybook?The right passage came 1st. A rare, exact name: keyword search is strong here.
  • How do I filter a long list?The right passage came 1st. Everyday words that the guide also uses.
  • How do I start a new component?The right passage came 1st. Close wording.
  • What makes a build faster?The right passage came 1st. One shared word.
  • How do I ship my widget?The right passage was not found at all. Different words for the same idea: “ship” and “widget”.

This is how you check a retrieval change without guessing: a fixed list of questions, each with the passage that should be found. Raise k and more questions pass, at the cost of sending more text. Turn on the synonym list and the “ship my widget” question starts working: a cheap fix before reaching for embeddings. Sample passages and questions, not the real index.

Cost and speed

How it stays cheap, and how to make it cheaper

Less text sent to the AI, fewer AI calls and a smaller model all mean a lower bill and a faster answer. Some of this is already in place. The rest are ideas, clearly marked.

Already in place

  • Free default model

    The model that writes answers is a free one, so each question costs nothing. A paid model is one setting away.

  • Only five passages, trimmed

    The AI is sent five passages of at most 1,800 characters each, not the whole guide. Less text in means a smaller bill and a faster answer.

  • Capped answer length

    The reply is capped at 1,500 tokens, and the instructions ask for about 180 words.

  • Thinking switched off

    Extra “reasoning” is turned off, so the model answers directly and quickly.

  • Cached health check

    Whether the AI works is checked at most once every 10 minutes (30 seconds after a failure), not on every page view.

  • Short memory and rate limits

    Only the last 8 messages are used, questions are cut to 500 characters, and each visitor is limited per minute and per hour.

  • Search as plan B

    When the AI is off or failing, answers come from search, which costs nothing.

Next ideas (not built)

  • Cache repeated questionsSmall

    Many visitors ask the same few things. Store the answer for a popular question and reuse it, with no model call at all.

  • Use the AI provider’s prompt cachingSmall

    The rules at the top of the prompt never change. Some providers charge much less for repeated text.

  • Send fewer or shorter passagesSmall, needs testing

    Try three passages instead of five and measure whether answers stay as good. Less text in is cheaper.

  • Route easy questions to a smaller modelMedium

    Use a tiny model for simple lookups, and a stronger one only when the question is hard.

  • Add meaning-based search on topMedium

    Combine keyword and embedding scores (hybrid search). Better recall, at the cost of an index to maintain.

  • A shared rate limitMedium

    Keep the counters in a small database so they survive restarts and apply across servers.

  • Log and lookSmall

    Record which questions got “not found” answers. Those tell me exactly which guide sections to write next, which is the cheapest quality gain.

Try it

Work out the bill yourself

Move the sliders. Fewer passages, shorter answers and a cache all shrink the number. The default prices are zero, because the model is free today.

The “made-up example” prices (1 in, 4 out) are invented for the demo. Type your provider’s real prices.

Sent per question

2,775 tokens

Model calls a month

6,000

Tokens a month

18.15 million

Cost a month

$0.00

With a free model the money cost is zero, but the tokens still show how much work is sent, which matters for speed and for any move to a paid model. Rough rule used: 4 characters per token, and the rules text is estimated at about 2,000 characters. Conversation history is left out, so real numbers run a little higher.

Try it

Try to break the rate limiter

The real limits (6 a minute, 40 an hour) running in a simulated clock. Compare the two ways of counting, then restart the server and see what memory forgets.

Clock

0:45

into the hour (simulated)

This minute

0 / 6

This hour

0 / 40

  • No questions yet. Ask a few.

Try this

Ask 5, wait 10 seconds, ask 5 more. The sliding window looks back a full minute from now, so the second batch is stopped. Then wait a minute and it opens again.

Then press “Restart the server”

The counters vanish, because they only live in memory. That is exactly how Siya behaves, and why a shared store is the upgrade for a busy site. Real clocks and limits: 6 a minute and 40 an hour, as in the code.

The thinking

The story behind it, in eight steps

Not just what was built, but the order the decisions came in. Each step answers the problem the one before it left.

  1. The problem

    My guides are long. A visitor with one question should not have to read chapters to find one command.

  2. The first idea

    Add a chat that answers from the guides. An AI alone would answer from memory and could invent steps, which is wrong for a technical guide.

  3. The key decision

    Do not ask the AI to remember. Find the right pages first, then ask it to answer using only those. That is retrieval-augmented generation.

  4. The simplest search that works

    Start with keyword ranking. It needs no extra service, costs nothing, and can be explained. Treat embeddings as an upgrade to earn, not a default.

  5. Keep it swappable

    Route the model through the AI Gateway so the model is a name in a setting. Free to start, paid or different later, no rewrite.

  6. Assume it will fail

    Free models sometimes return nothing. So: a health check, one retry, then an answer built straight from the guides. The chat never just breaks.

  7. Protect it and the content

    Input limits and rate limits for the chat. A cleaning script for any client-derived notes, so nothing private can reach the answers.

  8. Be honest about limits

    Show the sources, say “I could not find it” when true, and write down what was not measured.

Test yourself

Make the call

Six real situations. Pick the best move and read why. The reasoning matters more than the score.

Scenario 1 of 6

Visitors keep asking in words the guides never use, so Siya says “not found”. What is the best first move?

Questions and answers

Questions you might ask, and how I would answer

Filter by how technical you want to go. Tap a question to see the answer.

The big picture

Design choices

Quality and safety

Judgement

What this shows

Skills on display, in plain words

Retrieval-augmented generation
Answers come from my own writing, found fresh for every question, instead of from the AI’s memory.
LLM integration through a gateway
The AI model is a setting I can change, with a free default and a paid or direct option.
Streaming, typed API route
Answers appear live, from a server function written in TypeScript with the AI SDK.
Graceful degradation
When the AI fails, the chat still helps. A retry first, then an answer built from the guides.
Abuse protection
Input limits and a per-visitor rate limit, with the weaknesses stated openly.
Privacy-first content pipeline
A script that strips code, links, names and addresses from my notes, and drops any section that still looks sensitive, before anything is allowed in.

What was checked

  • Everything described on this page was read from the code that runs the chat.
  • The numbers (5 passages, 500 characters, 6 a minute, 40 an hour, 1,500 tokens, the two cache times) are the values in the code today.

What was not

  • No accuracy, speed or cost figures: none were measured, so none are claimed.
  • The free default model is a choice that may change. It is set by one setting, not baked in.
  • The retrieval demo below uses six sample passages written for this page, not the real index.
  • The “cleaned component notes” source has its cleaning script built, but nothing has been approved into it yet, so today the chat answers from the guides only.

Words, translated

The jargon, in one line each

LLM
A “large language model”: the AI that writes text. It predicts sensible next words after reading a lot of text.
RAG
Retrieval-Augmented Generation. Look up the right notes first, then let the AI write using only those notes.
Context
The notes handed to the AI along with your question. The AI cannot use what is not in its context.
Prompt
The full message sent to the AI: the rules, the context and your question.
Retrieval
Finding the most relevant pieces of text for a question. Here: a keyword scoring method called BM25.
BM25
A classic way to rank text by keywords. It rewards rare words and does not let long passages win just by being long.
Embedding
A different way to search, by meaning instead of keywords, using numbers that represent a text. Siya does not use it today.
AI Gateway
A switchboard in front of many AI companies. One key, many models, and the model can be swapped by name.
Streaming
Sending the answer a few words at a time, so you can start reading at once.
Token
A small piece of text, roughly three-quarters of a word. Models count and limit their output in tokens.
Rate limit
A cap on how often one visitor can ask, so nobody can use up the allowance.
Fallback
Plan B. What happens automatically when the first choice fails.