RAG · List and close workspaces5 / 9
  1. 01
  2. 02
  3. 03
  4. 04
  5. 06
  6. 07
  7. 08
  8. 09

List and close workspaces

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

Workspaces live on disk under the SDK's data directory. ragListWorkspaces() reads them back so we can see what's there. ragCloseWorkspace({ workspace, deleteOnClose }) tears one down.

The list comes back as an array of { name, open } objects, where the open flag tells us if the workspace is still loaded or already torn down. The loop prints one line per workspace:

for (const ws of workspaces) {
  console.log(`▸ ${ws.name} (${ws.open ? "open" : "closed"})`);
}

Closing a workspace is a single call. deleteOnClose: true drops the in-memory handle and wipes the on-disk folder. The call itself only needs the workspace name:

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

If we pass deleteOnClose: false, the workspace files stay on disk but the in-memory handle is dropped. A workspace auto-closes when the process exits, so this call is for explicit cleanup during long-running sessions.

Note: deleteOnClose is the right name for "remove from disk." Passing false is the right call when you want to keep the data but release the in-memory handle.

Put it to the test

  1. The editor prefills the ragListWorkspaces() call. Loop through and log each workspace's name and open status.
  2. Call ragCloseWorkspace({ workspace, deleteOnClose: true }) to remove the workspace from disk.
index.ts

$ Run your code to see results

$