RAG · Delete a RAG workspace and its data8 / 9
  1. 01
  2. 02
  3. 03
  4. 04
  5. 05
  6. 06
  7. 07
  8. 09

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).

Put it to the test

  1. Call ragIngest to add a few documents to a named workspace, then log the workspace name and document count.
  2. Call ragCloseWorkspace({ workspace, deleteOnClose: true }) and log the deletion.
index.ts

$ Run your code to see results

$