Text embeddings · Load an embedding model1 / 5
  1. 02
  2. 03
  3. 04
  4. 05

Load an embedding model

Example on GitHub(packages/sdk/examples/embed-p2p.ts)

Now that we've finished chapter 2, we're going to start a new line of work: embeddings.

An embedding is a list of numbers that encodes what a piece of text means. A real model maps a sentence to a 1024-number array. We can't read the numbers, but we can compare them with math, and two similar sentences end up with similar numbers.

The QVAC SDK loads embedding models through the same loadModel() we used in chapter 1. Same import, same options, same modelId pattern. The only thing that changes is the constant we hand to modelSrc.

GTE_LARGE_FP16 is the SDK's embedding model. The call is the same loadModel from chapter 1, with GTE_LARGE_FP16 in modelSrc:

const modelId = await loadModel({ modelSrc: GTE_LARGE_FP16 });
console.log("modelId:", modelId);

Save the modelId. The next lessons vectorize text against the same loaded model, and reloading between calls would be wasteful.

Note: the import line changes too. We'll have both loadModel and GTE_LARGE_FP16 in the same import { ... } statement, since they come from the same @qvac/sdk package.

Put it to the test

  1. Inside main(), call loadModel with { modelSrc: GTE_LARGE_FP16 }.
  2. await the result and store it in a variable called modelId. Log modelId to stdout.
index.ts

$ Run your code to see results

$