RAG · Delete a RAG workspace and its data8 / 10

Delete a RAG workspace and its data

Example on GitHub(packages/sdk/examples/rag/rag-hyperdb/workspaces.ts)

The list-and-close lesson closed the in-memory handle for a workspace without touching the data. This one drops the workspace and its on-disk files in one call.

ragCloseWorkspace({ workspace, deleteOnClose: true }) releases the in-memory handle and removes the on-disk folder in a single pass. The flag is the only thing that flips the call from "close" to "delete":

await ragCloseWorkspace({ workspace, deleteOnClose: true });

The setup is the same as the other RAG lessons: a named workspace, an ingest to give it content, then the teardown. Right call for "throw away the index and start over":

const workspace = "delete-workspace-demo";
const samples = [
  "A temporary workspace holds documents we want to remove in one go.",
];

const modelId = await loadModel({ modelSrc: GTE_LARGE_FP16 });
await ragIngest({ modelId, workspace, documents: samples, chunk: false });
console.log(`▸ Created workspace '${workspace}' with ${samples.length} document`);

await ragCloseWorkspace({ workspace, deleteOnClose: true });
console.log(`▸ Deleted workspace '${workspace}' and its on-disk files`);

await unloadModel({ modelId });

After the call returns, the workspace is gone. The next ragIngest against the same name starts fresh; the next ragSearch returns "workspace not found" instead of empty results.

Note: deleteOnClose: true is the destructive flag. Omit it and the same ragCloseWorkspace call only releases the in-memory handle, leaving the on-disk data intact for the next ragOpen (when one is available).

Questions

Question 1 of 2

What makes ragCloseWorkspace delete a workspace instead of just closing it?

Question 2 of 2

After ragCloseWorkspace runs with deleteOnClose: true, what happens if ragIngest targets that same workspace name again?

index.ts
Loading editor...

Run your code, check your answer, or ask a question. It all shows up here.