> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pnbr.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Slices

> Save reusable scopes over your graph with pb.slices.

A **slice** is a saved, reusable [scope](/sdk/context). You define a scope once,
confirm what it matches, save it under a name, and reuse or compile it later.

## Author a slice

Saving a slice returns the same `matched` + `scope_warnings` you get from a
preview, so you confirm it resolves before you rely on it.

```ts theme={null}
const slice = await pb.slices.create("Alpha cos since Jan", {
  filter: {
    types: ["Company"],
    properties: [{ path: "stage", operator: "eq", value: "alpha" }],
    after: "2026-01-01",
  },
});
// { id, name, matched: 18, scope_warnings: [], filter_definition: {...} }
```

## List, read, promote

```ts theme={null}
await pb.slices.list();            // slices in scope
await pb.slices.get(slice.id);     // includes a live, recomputed member count
await pb.slices.promote(slice.id); // make it a durable lens others reuse
await pb.slices.demote(slice.id);
```

## Method reference

| Method                                 | REST                           | Description                                 |
| -------------------------------------- | ------------------------------ | ------------------------------------------- |
| `pb.slices.create(name, scope)`        | `POST /v1/slices`              | Save a scope; returns `matched` + warnings. |
| `pb.slices.list(options?)`             | `GET /v1/slices`               | List slices in scope.                       |
| `pb.slices.get(id)`                    | `GET /v1/slices/{id}`          | Read a slice (live member count).           |
| `pb.slices.update(id, input)`          | `PATCH /v1/slices/{id}`        | Update a slice.                             |
| `pb.slices.promote(id)` / `demote(id)` | `POST /v1/slices/{id}/promote` | Promote to / demote from a durable lens.    |

## Compile a slice

Pass a slice into [`pb.context.compile`](/sdk/context) to turn it into context.

```ts theme={null}
const compiled = await pb.context.compile({ slice_id: slice.id });
```

## Related

<Columns cols={2}>
  <Card title="Context" icon="layer-group" href="/sdk/context">
    The scope grammar, preview, and compile.
  </Card>

  <Card title="CQL" icon="terminal" href="/concepts/cql">
    Write scopes as a terse string.
  </Card>
</Columns>
