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

# Chunking SDK Reference

> SDK reference for the Chunking API, available in Node.js and Python.

## Chunking

### Parse

Split large text documents into smaller, manageable chunks using different chunking strategies optimized for RAG (Retrieval-Augmented Generation) workflows. This endpoint supports multiple chunking algorithms including token-based, sentence-based, recursive, semantic, and specialized strategies.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.chunking.parse(request={
          "text": "The quick brown fox jumps over the lazy dog. This is a sample text that will be chunked into smaller pieces. Each chunk will maintain context while respecting the maximum chunk size.",
          "metadata": True,
          "strategy": "semantic",
          "chunk_size": 256,
          "threshold": 0.8,
          "embedding_model": "openai/text-embedding-3-small",
          "dimensions": 512,
          "mode": "window",
          "similarity_window": 1,
      })

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.chunking.parse({
      text: "The quick brown fox jumps over the lazy dog. This is a sample text that will be chunked into smaller pieces. Each chunk will maintain context while respecting the maximum chunk size.",
      metadata: true,
      strategy: "semantic",
      chunkSize: 256,
      threshold: 0.8,
      embeddingModel: "openai/text-embedding-3-small",
      dimensions: 512,
      mode: "window",
      similarityWindow: 1,
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "text": str,  # required
        "metadata": Optional[bool],
        "return_type": Optional[Literal["chunks", "texts"]],
        "strategy": Literal["token"],  # required
        "chunk_size": Optional[int],
        "chunk_overlap": Optional[int],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      text: string;  // required
      metadata?: boolean | undefined;
      return_type?: "chunks" | "texts" | undefined;
      strategy: "token";  // required
      chunk_size?: number | undefined;
      chunk_overlap?: number | undefined;
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "chunks": {
            "text": str,
            "index": float,
            "metadata": {  # optional
                "start_index": Nullable[float],
                "end_index": Nullable[float],
                "token_count": Nullable[float],
            },
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      chunks: {
        text: string;
        index: number;
        metadata?: {
          startIndex: number;
          endIndex: number;
          tokenCount: number;
        };
      };
    }
    ```
  </CodeGroup>
</Expandable>
