ragReindex( )
Reindexes the RAG database to optimize search performance.
function ragReindex(params): Promise<RagReindexResult>;
For HyperDB, rebalances centroids using k-means clustering. Requires a minimum number of documents (16 by default).
| Name | Type | Required? | Default | Description |
|---|
| params.modelId | string | ✗ | — | Embedding model ID (required if no cached RAG instance) |
| params.workspace | string | ✗ | "default" | Workspace to reindex. Must already exist. |
| params.onProgress | (stage, current, total) => void | ✗ | — | Progress callback |
| Field | Type | Description |
|---|
| reindexed | boolean | Whether reindexing was performed |
| details | Record<string, unknown> | Additional details (e.g., reason if skipped) — optional |
| Error | When |
|---|
RAG_SAVE_FAILED | The reindex operation fails or workspace doesn't exist |
STREAM_ENDED_WITHOUT_RESPONSE | Streaming ends unexpectedly (when using onProgress) |
const result = await ragReindex({ workspace: "my-docs" });
if (!result.reindexed) {
console.log("Reindex skipped:", result.details?.reason);
}