ragReindex( )
Reindexes the RAG database to optimize search performance. For HyperDB, this rebalances centroids using k-means clustering. **Workspace lifecycle:** This operation requires an existing workspace. **Note:** Reindex requires a minimum number of documents to perform clustering. For HyperDB, this is 16 documents by default. If there are insufficient documents, `reindexed` will be `false` with `details` explaining the reason.
function ragReindex(params: RagReindexParams, options?: { forceNewConnection?: boolean; profiling?: { enabled?: boolean; includeServerBreakdown?: boolean; mode?: "summary" | "verbose" }; timeout?: number }): PromiseParameters
| Name | Type | Required? | Description |
|---|---|---|---|
params | RagReindexParams | ✓ | The parameters for reindexing |
options | `{ forceNewConnection?: boolean; profiling?: { enabled?: boolean; includeServerBreakdown?: boolean; mode?: "summary" | "verbose" }; timeout?: number }` | ✗ |
Returns
PromiseThrows
| Error | When |
|---|---|
When the operation fails or workspace doesn't exist | |
When streaming ends unexpectedly (only when using onProgress) |
Example
// Simple reindex
const result = await ragReindex({
workspace: "my-docs",
});
// Check result
if (!result.reindexed) {
console.log("Reindex skipped:", result.details?.reason);
}
// With progress tracking
const result = await ragReindex({
workspace: "my-docs",
onProgress: (stage, current, total) => {
console.log(`[${stage}] ${current}/${total}`);
},
});ragListWorkspaces( )
Lists all RAG workspaces with their open status. Returns all workspaces that exist on disk. The `open` field indicates whether the workspace is currently loaded in memory and holding active resources (Corestore, HyperDB adapter, and possibly a RAG instance).
ragSaveEmbeddings( )
Saves pre-embedded documents to the RAG vector database. Part of the segregated flow: chunk() → embed() → saveEmbeddings() **Workspace lifecycle:** This operation implicitly opens (or creates) the workspace. The workspace remains open until closed.