How it works
Retrieval-Augmented Generation, in plain sight
Every answer is built in four small steps, from your question to a grounded reply. You can follow exactly how retrieval-augmented generation turns a question into an answer drawn only from real NASA texts.
- 1Embed the questionQuery
Your question is turned into a list of 768 numbers (a vector) by Google's multilingual Gemini embedding model. The same model already turned every APOD description into a vector, so a German question can still find an English text. Meaning becomes math the computer can compare. (With Smart search on, you first pick from cleaned-up versions of your question, typos fixed, before this step.)
- 2Find the closest textsRetrieve
That question-vector goes to the Upstash Vector database, which compares it against every stored APOD vector by cosine similarity and hands back the closest ones. The closer two vectors point, the closer their meaning.
- 3Keep the best matchesRank
Upstash already hands the matches back sorted by similarity, so this step just takes the top five and applies one cheap guard: if even the closest match scores far too low, skip the model and treat that input as invalid. Scores alone can't tell gibberish from a real question (random text often scores high), so the real judgement is the model's, in the next step. How do we know the cutoff and the top-five are any good? An offline eval (`npm run eval`) asks a set of questions whose right answer we already know and grades how often, and how near the top, the right picture is found (the standard search metrics Recall@K and MRR), so those knobs are set from numbers, not guesses.
- 4Generate a grounded answerAnswer
The question and the top texts go to Google Gemini. It used to answer in free text with NONSENSE / NO_MATCH markers parsed by hand, brittle and unable to prove which pictures were used; now it fills a fixed JSON form, checked by a schema, so the reply can't drift and invented citations are dropped. An optional Star Trek toggle changes only the tone, never the facts.