Choose Where Embeddings Come From

In the last lesson, rank-rules.js put the pier rule on top for table 6’s question, and every vector behind that ranking came from a small model running on your own computer. Soon the rules desk will embed every page of the café’s eight rulebooks, so this is the moment to ask where those vectors should come from.

Model providers sell embeddings too. Here, you’ll weigh a provider’s embeddings API against a local model for the rules desk, and you’ll see why this course stays local. You’ll also learn the one habit that keeps a later model change from silently breaking your search. Start with what each option costs you.

Weigh a Provider’s API Against a Local Model

The rules desk needs one source for every vector it stores, so pick it before there are hundreds. A provider’s embeddings endpoint works much like the requests behind ask(). Your code sends texts with your API key in a fetch() request, and vectors come back. OpenAI offers one. Anthropic doesn’t, and its documentation points you to third-party embedding providers instead.

For the rules desk, the two options compare like this:

A provider’s API This course’s local model
Cost Billed per token: all eight rulebooks are about 6,500 tokens Nothing per call
Privacy Every text goes to the provider Texts stay on your machine
Speed A network request each time Your own CPU, no network
Quality Depends on the model you pick Small, made for English text
Download None, but a key and an account About 90 MB, once

The local column describes this course’s model, all-MiniLM-L6-v2, not every local model. Quality and language coverage depend on the model itself, whether it runs behind an API or on your machine. You’ll find small and large, English-only and multilingual models both ways. To compare candidates, embed a few real questions with each and check which ranks the right rules first.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.