Running Embeddings and Vector Databases locally
Use this page to run the extracted course chatbot on your computer. On this page you install two missing packages, adapt the chatbot's OpenAI and Supabase settings for Vite, and start the browser project with the database you built during the course.
What you need first
Install a supported LTS version of Node.js. Node 24 is recommended and includes npm. You also need an OpenAI API key and an existing Supabase project containing the course data.
For Supabase, use a publishable key or the legacy anon key. These keys are designed to appear in browser code: anyone who copies one can only do what your Row Level Security policies (Supabase's per-row read rules) permit. Never put a secret key or service_role key in this browser project. See Supabase API keys for the current key types.
The OpenAI key has no equivalent scoping: any copy of it can make requests billed to your account, so in production it never belongs in client code. This learning setup sends it to the browser anyway; the warning in the Vite section explains the limits of doing that. The server-side counterpart of this setup, the Vercel AI SDK project, uses the same Supabase project but with a secret key. A secret key is acceptable there because that project runs on a server, so its keys never reach a browser.
anon key, the kind designed for browsers, never a server secret. I once used the wrong key type and spent an evening learning the difference between them! Open the project folder
Open a terminal in the extracted chatbot folder containing package.json:
$ cd path-to-your-downloaded-projectTo confirm you have the right download, open package.json: the chatbot export declares Vite, and the source beside it includes the config.js and index.js files the next sections edit. These instructions fit the completed chatbot, whose code imports both openai and @supabase/supabase-js; the folder name alone does not distinguish it from an earlier lesson's export.
package.json; every install and every file on this page belongs there. If the terminal is anywhere else, the commands run in the wrong folder and nothing after this works. I check the folder listing for package.json before typing anything, a habit I built after making that mistake several times. package.json at the top level, Vite declared inside it, and config.js and index.js sitting beside it. Thirty seconds of checking here costs less than repairing a different project's files. Every command on this page assumes you are in this folder. Prepare the project for Vite
Install the declared Vite dependency, then the two packages the source imports but the downloaded package.json does not declare:
$ npm install
$ npm install openai @supabase/supabase-jsOpen config.js and replace every Scrimba environment read. Keep the existing imports, exports, and validation, but replace three environment names across four occurrences; OPENAI_API_KEY appears twice:
process.env.OPENAI_API_KEY
import.meta.env.VITE_OPENAI_API_KEY
process.env.SUPABASE_API_KEY
import.meta.env.VITE_SUPABASE_API_KEY
process.env.SUPABASE_URL
import.meta.env.VITE_SUPABASE_URLThe two OPENAI_API_KEY reads sit in the validation check and the OpenAI client, so change both.
Open index.js and change the chat model from gpt-4 to gpt-4o-mini. Leave the supplied text-embedding-ada-002 embedding model unchanged while following the course. Existing vectors in the course database must have the same dimensions as the query embeddings; changing that model is a separate database migration, not part of local setup.
Create .env beside package.json:
VITE_OPENAI_API_KEY=your-openai-api-key
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_API_KEY=your-publishable-or-anon-keyAlso create .gitignore:
.env
node_modules/Sending .env to a Git repository is the most common way a key leaks; ignoring files and good habits covers the habit in full.
These credentials are visible in the browser
Vite copies VITE_ values into the frontend bundle. Use restricted learning credentials, enable Row Level Security in Supabase, and never publish this version. A production app must move the OpenAI request to a backend.
.env with a browser-safe Supabase key. Then keep .env out of Git. I once published a key with my first project and spent the evening replacing it, so this order is written from experience. .env and .gitignore pair finishes the repair. VITE_ names are what place the values in the bundle, which also delivers the OpenAI key to browser code. That is acceptable for a lesson and disqualifying for production, so move the OpenAI call behind a backend before real users reach this chatbot. I have seen a project skip that step, and it finished with a revoked key and an unexpected invoice. Run the project
$ npm startOpen the Local URL printed by Vite and ask the chatbot a question covered by the course data. A useful answer shows that the page, Supabase retrieval, and OpenAI request are all working. Restart the command after changing .env, and stop it with Ctrl+C.
npm start, open the Local URL, and ask the chatbot something the course data covers. If you change .env, restart the command so Vite reads the new values, and press Ctrl+C when you finish. Forgetting that restart once confused me for a whole afternoon, so I hope this note saves you one. .env change. Troubleshooting
Failed to resolve import "openai" or "@supabase/supabase-js": Run both of the install commands shown earlier on this page, and run them in the folder that contains package.json.
process is not defined: A process.env reference remains in config.js. Replace it with the matching import.meta.env.VITE_... value.
Supabase returns no rows or a permissions error: Confirm the project URL, use a publishable or anon key, and check that the course table and Row Level Security policies exist in that same project.
OpenAI rejects the model or key: Confirm billing and key access in the OpenAI account. Use a current model available to that project.

