Now that we have the chunk-embed-save pipeline running through ragIngest, we're going to break it apart. This lesson covers the third step on its own: saving vectors you've already computed.
ragSaveEmbeddings stores one RagEmbeddedDoc per entry. Each one has an id, the content, the embedding (a number[]), and the embeddingModelId that produced the vector. The embeddingModelId must match the modelId passed to ragSearch later, since cosine similarity is only meaningful between vectors from the same model.
ragSaveEmbeddings({ workspace, documents }) writes the RagEmbeddedDoc array to disk and returns processed, a per-entry { status, id, error } array. Counting fulfilled entries gives you the saved count:
const saveResult = await ragSaveEmbeddings({
workspace: "save-embeddings-demo",
documents: embeddedDocs,
});
const saved = saveResult.filter((r) => r.status === "fulfilled").length;
console.log(`▸ Saved ${saved}/${saveResult.length} embeddings to the workspace`);Note:
ragSaveEmbeddingsis a storage-only operation. The SDK doesn't need the model on hand to save. It only needs the model to search. Re-running with the sameidis idempotent; the existing entry is overwritten.
ragSaveEmbeddings({ workspace, documents }) with the prefilled embeddedDocs and log the count of fulfilled saves out of saveResult.length.$ Run your code to see results
$