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

# Retrieve Chunks

> Retrieve relevant chunks.

The optional `request.filters` payload accepts equality checks (which also match scalars inside JSON arrays)
plus the logical operators `$and`, `$or`, `$nor`, and `$not`. Field-level predicates include `$eq`, `$ne`,
`$in`, `$nin`, `$exists`, `$type`, `$regex`, `$contains`, and the comparison operators `$gt`, `$gte`, `$lt`,
and `$lte`. Comparison clauses evaluate typed metadata (`number`, `decimal`, `datetime`, or `date`) and
raise detailed validation errors when operands cannot be coerced. Regex filters allow the optional `i` flag
for case-insensitive matching, while `$contains` performs substring checks (case-insensitive by default,
configurable via `case_sensitive`). Filters can be nested freely, for example:

```json
{
  "$and": [
    {"category": "policy"},
    {"$or": [{"region": "emea"}, {"priority": {"$in": ["p0", "p1"]}}]}
  ]
}
```
Returns a list of `ChunkResult` objects ordered by relevance.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/morphik/openapi.documented.yml post /retrieve/chunks
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers: []
security: []
paths:
  /retrieve/chunks:
    post:
      summary: Retrieve Chunks
      description: >-
        Retrieve relevant chunks.


        The optional `request.filters` payload accepts equality checks (which
        also match scalars inside JSON arrays)

        plus the logical operators `$and`, `$or`, `$nor`, and `$not`.
        Field-level predicates include `$eq`, `$ne`,

        `$in`, `$nin`, `$exists`, `$type`, `$regex`, `$contains`, and the
        comparison operators `$gt`, `$gte`, `$lt`,

        and `$lte`. Comparison clauses evaluate typed metadata (`number`,
        `decimal`, `datetime`, or `date`) and

        raise detailed validation errors when operands cannot be coerced. Regex
        filters allow the optional `i` flag

        for case-insensitive matching, while `$contains` performs substring
        checks (case-insensitive by default,

        configurable via `case_sensitive`). Filters can be nested freely, for
        example:


        ```json

        {
          "$and": [
            {"category": "policy"},
            {"$or": [{"region": "emea"}, {"priority": {"$in": ["p0", "p1"]}}]}
          ]
        }

        ```

        Returns a list of `ChunkResult` objects ordered by relevance.
      operationId: retrieve_chunks_retrieve_chunks_post
      parameters:
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RetrieveRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ChunkResult'
                title: Response Retrieve Chunks Retrieve Chunks Post
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Morphik from 'morphik';

            const client = new Morphik({
              apiKey: process.env['MORPHIK_API_KEY'], // This is the default and can be omitted
            });

            const chunkResults = await client.retrieve.chunks.create();

            console.log(chunkResults);
        - lang: cURL
          source: |-
            curl https://api.morphik.ai/retrieve/chunks \
                -H 'Content-Type: application/json' \
                -H "Authorization: Bearer $MORPHIK_API_KEY" \
                -d '{}'
components:
  schemas:
    RetrieveRequest:
      properties:
        query:
          anyOf:
            - type: string
              minLength: 1
            - type: 'null'
          title: Query
          description: >-
            Natural-language query used to retrieve relevant chunks or
            documents.
        query_image:
          anyOf:
            - type: string
            - type: 'null'
          title: Query Image
          description: >-
            Base64-encoded image to use as query for Morphik multimodal
            retrieval. Requires use_colpali=True. Mutually exclusive with
            'query'.
        filters:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Filters
          description: >-
            Metadata filters supporting logical operators ($and/$or/$not/$nor)
            and field predicates
            ($eq/$ne/$gt/$gte/$lt/$lte/$in/$nin/$exists/$type/$regex/$contains).
        k:
          type: integer
          exclusiveMinimum: 0
          title: K
          description: Maximum number of chunks or documents to return.
          default: 4
        min_score:
          type: number
          title: Min Score
          description: Minimum similarity score a result must meet before it is returned.
          default: 0
        use_reranking:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Use Reranking
          description: >-
            When provided, overrides the workspace reranking configuration for
            this request.
        use_colpali:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Use Colpali
          description: >-
            When provided, uses Morphik's finetuned ColPali style embeddings
            (recommended to be True for high quality retrieval).
        output_format:
          anyOf:
            - $ref: '#/components/schemas/OutputFormat'
            - type: 'null'
          description: >-
            How to return image chunks: base64 (default), url, or text (markdown
            format)
          default: base64
        padding:
          type: integer
          minimum: 0
          title: Padding
          description: >-
            Number of additional chunks/pages to retrieve before and after
            matched chunks (ColPali only)
          default: 0
        folder_name:
          anyOf:
            - type: string
            - items:
                type: string
              type: array
            - type: 'null'
          title: Folder Name
          description: >-
            Optional folder scope. Accepts a folder PATH (e.g.,
            '/Company/Reports') or list of paths.
        folder_depth:
          anyOf:
            - type: integer
            - type: 'null'
          title: Folder Depth
          description: >-
            Folder scope depth. 0 or None = exact folder only, -1 = include all
            descendants, n > 0 = include descendants up to n levels deeper.
        end_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: End User Id
          description: Optional end-user scope for the operation
      type: object
      title: RetrieveRequest
      description: Base retrieve request model
    ChunkResult:
      properties:
        content:
          type: string
          title: Content
        score:
          type: number
          title: Score
        document_id:
          type: string
          title: Document Id
        chunk_number:
          type: integer
          title: Chunk Number
        metadata:
          additionalProperties: true
          type: object
          title: Metadata
        content_type:
          type: string
          title: Content Type
        filename:
          anyOf:
            - type: string
            - type: 'null'
          title: Filename
        download_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Download Url
        is_padding:
          type: boolean
          title: Is Padding
          description: Whether this chunk was added as padding
          default: false
      type: object
      required:
        - content
        - score
        - document_id
        - chunk_number
        - metadata
        - content_type
      title: ChunkResult
      description: Query result at chunk level
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    OutputFormat:
      type: string
      enum:
        - base64
        - url
        - text
      title: OutputFormat
      description: Output format for image chunks in retrieval results.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````