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

# Data Slices

> Filter documents for targeted processing and analysis

Data Slices are filtered subsets of your data based on metadata. They allow you to focus on specific segments of your document repository without affecting the entire dataset.

## Benefits

| Benefit                 | Description                                                           |
| :---------------------- | :-------------------------------------------------------------------- |
| **Targeted Processing** | Run extraction on only relevant documents (e.g., just 2024 contracts) |
| **Focused Analysis**    | View and analyze specific document categories                         |
| **Efficient Workflows** | Avoid reprocessing already-enriched documents                         |
| **Team Collaboration**  | Share team-specific data slices with team members                     |
| **Controllability**     | Run downstream applications on controlled data                        |

## Data Slice Properties

| Property           | Description                                          |
| :----------------- | :--------------------------------------------------- |
| **Name**           | User-defined identifier                              |
| **Description**    | Optional notes about what's included                 |
| **Data Connector** | Which Data Connector it's derived from               |
| **Document Count** | Number of files matching the conditions              |
| **Conditions**     | Filter rules that define the slice based on metadata |

## How Data Slices Work

```mermaid theme={"dark"}
flowchart LR
    subgraph source [Data Source]
        ALL[All Documents: 10,000]
    end
    
    subgraph slices [Data Slices, one per use case]
        S1[Support Chatbot KB: 1,247]
        S2[Sales Agent Brain: 892]
        S3[Compliance Review: 3,521]
    end
    
    ALL --> S1
    ALL --> S2
    ALL --> S3
```

## Example Data Slices

A slice is a use case: it captures exactly the documents one AI application or initiative should see.

| Slice Name           | Feeds                    | Filter Conditions                                                        |
| :------------------- | :----------------------- | :----------------------------------------------------------------------- |
| "Support Chatbot KB" | Customer-facing chatbot  | Document Type = Manual or FAQ AND no Data Quality Status flag AND no PII |
| "Sales Agent Brain"  | Account agent            | Document Type = Contract or Pricing AND Data Quality Status not exists   |
| "Contracts 2024"     | Legal analysis project   | Document Type = Contract AND Year = 2024                                 |
| "Compliance Review"  | Human review queue       | PII = true OR PHI = true                                                 |
| "Needs Processing"   | Remediation classify job | Required tags = Not found                                                |

<Tip>
  The same document can appear in several slices and be excluded from others. The support chatbot never sees PII; the compliance queue sees nothing else.
</Tip>

## Creating Effective Data Slices

<Steps>
  <Step title="Define Your Goal">
    Identify what subset of documents you need to work with.
  </Step>

  <Step title="Choose Filter Conditions">
    Select metadata fields and values that define your target documents.
  </Step>

  <Step title="Combine Conditions">
    Use AND/OR logic to create precise filters.
  </Step>

  <Step title="Verify Document Count">
    Check that the slice captures the expected number of documents.
  </Step>

  <Step title="Apply to Workflows">
    Use the slice in Projects or for targeted exports.
  </Step>
</Steps>

## Common Use Cases

<CardGroup cols={2}>
  <Card title="Incremental Processing" icon="forward">
    Filter to documents that haven't been processed yet
  </Card>

  <Card title="Compliance Review" icon="shield-check">
    Focus on documents containing sensitive information
  </Card>

  <Card title="Time-Based Analysis" icon="calendar">
    Analyze documents from specific time periods
  </Card>

  <Card title="Category Deep-Dive" icon="folder-tree">
    Examine all documents of a particular type
  </Card>
</CardGroup>

***

## Python SDK

<Tabs>
  <Tab title="Create Data Slice">
    ```python theme={"dark"}
    from unstructured import UnstructuredClient

    client = UnstructuredClient(
        base_url="https://unstructured.your-company.com/rest/unstructured",
        username="your-username",
        password="your-password",
    )

    # Create a data slice with filter conditions
    slice_condition = {
        "condition": "AND",
        "children": [
            {"tag": {"name": "document_type", "operator": "in", "values": ["Contract"]}},
            {"tag": {"name": "year", "operator": "in", "values": ["2024"]}},
        ],
    }

    slice = client.data_slice.create(
        data_connector_name="my-s3-bucket",
        dataslice_name="2024-contracts",
        description="All contracts from 2024",
        condition=slice_condition,
    )
    print(f"Created slice: {slice.dataslice_id}")

    # Check how many files the slice captures
    count = client.data_slice.file_count(
        data_connector_name="my-s3-bucket",
        condition=slice_condition,
    )
    ```
  </Tab>

  <Tab title="Filter Examples">
    ```python theme={"dark"}
    # Documents missing required metadata (data-quality gate)
    needs_processing = client.data_slice.create(
        data_connector_name="my-s3-bucket",
        dataslice_name="needs-processing",
        condition={
            "condition": "OR",
            "children": [
                {"tag": {"name": tag, "operator": "in", "values": ["Not found"]}}
                for tag in ["document_type", "summary"]
            ],
        },
    )

    # Documents with detected PII
    sensitive = client.data_slice.create(
        data_connector_name="my-s3-bucket",
        dataslice_name="contains-pii",
        condition={
            "tag": {"name": "ssn_detected", "operator": "in", "values": ["Yes"]},
        },
    )
    ```
  </Tab>

  <Tab title="Export Slice">
    ```python theme={"dark"}
    # Export a data slice's metadata as CSV or JSON
    result = client.data_slice.export(
        data_connector_name="my-s3-bucket",
        dataslice_id="your-dataslice-id",
        export_format="csv",
    )

    # Export the slice to a configured destination (e.g. a vector database)
    client.destination.export(
        destination_name="my-qdrant",
        dataslice_id="your-dataslice-id",
        export_level="chunk",
        export_nodes=True,
    )
    ```
  </Tab>

  <Tab title="List & Delete">
    ```python theme={"dark"}
    # List all data slices
    slices = client.data_slice.list()
    for s in slices.dataslices:
        print(f"{s.name} ({s.id}): {s.data_points} docs")

    # Delete a data slice (by ID)
    client.data_slice.delete(dataslice_id="your-dataslice-id")
    print("Data slice deleted")
    ```
  </Tab>
</Tabs>

***

## API Reference

<CardGroup cols={2}>
  <Card title="Create Data Slice" icon="plus" href="/api-reference/data-slices/create">
    Create a new data slice
  </Card>

  <Card title="List Data Slices" icon="list" href="/api-reference/data-slices/list">
    List all your data slices
  </Card>

  <Card title="Delete Data Slice" icon="trash" href="/api-reference/data-slices/delete">
    Remove a data slice
  </Card>

  <Card title="Export Data Slice" icon="download" href="/api-reference/data-slices/export">
    Export data from a slice
  </Card>
</CardGroup>
