QVAC Logo

ragSaveEmbeddings( )

Saves pre-embedded documents to the RAG vector database.

function ragSaveEmbeddings(params): Promise<RagSaveEmbeddingsResult[]>;

Part of the segregated flow: ragChunk()embed()ragSaveEmbeddings(). Implicitly opens (or creates) the workspace.

Parameters

NameTypeRequired?DefaultDescription
params.documentsRagEmbeddedDoc[]Pre-embedded documents
params.modelIdstringEmbedding model ID (required if no cached RAG instance exists)
params.workspacestring"default"Workspace for isolated storage
params.onProgress(stage, current, total) => voidProgress callback
params.progressIntervalnumberMinimum interval between progress updates in ms

RagEmbeddedDoc

FieldTypeRequired?Description
idstringDocument identifier
contentstringDocument text content
embeddingnumber[]Pre-computed embedding vector
embeddingModelIdstringModel used to generate the embedding
metadataRecord<string, unknown>Optional metadata

Returns

Promise<RagSaveEmbeddingsResult[]> — Array of { status: "fulfilled" | "rejected", id?, error? }.

Throws

ErrorWhen
RAG_SAVE_FAILEDThe save operation fails
STREAM_ENDED_WITHOUT_RESPONSEStreaming ends unexpectedly (when using onProgress)

Example

const chunks = await ragChunk({ documents: ["text1", "text2"] });
const embeddings = await embed({ modelId, text: chunks.map(c => c.content) });
const embeddedDocs = chunks.map((chunk, i) => ({
  ...chunk,
  embedding: embeddings[i],
  embeddingModelId: modelId,
}));
const result = await ragSaveEmbeddings({
  documents: embeddedDocs,
  workspace: "my-workspace",
});

On this page