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
| Name | Type | Required? | Default | Description |
|---|---|---|---|---|
| params.documents | RagEmbeddedDoc[] | ✓ | — | Pre-embedded documents |
| params.modelId | string | ✗ | — | Embedding model ID (required if no cached RAG instance exists) |
| params.workspace | string | ✗ | "default" | Workspace for isolated storage |
| params.onProgress | (stage, current, total) => void | ✗ | — | Progress callback |
| params.progressInterval | number | ✗ | — | Minimum interval between progress updates in ms |
RagEmbeddedDoc
| Field | Type | Required? | Description |
|---|---|---|---|
| id | string | ✓ | Document identifier |
| content | string | ✓ | Document text content |
| embedding | number[] | ✓ | Pre-computed embedding vector |
| embeddingModelId | string | ✓ | Model used to generate the embedding |
| metadata | Record<string, unknown> | ✗ | Optional metadata |
Returns
Promise<RagSaveEmbeddingsResult[]> — Array of { status: "fulfilled" | "rejected", id?, error? }.
Throws
| Error | When |
|---|---|
RAG_SAVE_FAILED | The save operation fails |
STREAM_ENDED_WITHOUT_RESPONSE | Streaming 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",
});