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

# Filter most relevant chunks

> This endpoint can be used to filter document chunks based on a given query.

The query should be a single string.

Chunk ids should be a list of strings. Each string should be the UUID of an existing document chunk.

The `model` field should be the name of the model to use for filtering.

An optional integer `n` can be provided, which can be used to return the first `n` chunks that pass the filter.





## OpenAPI

````yaml /api-reference/openapi-v2.yaml post /api/v2/filter/chunks
openapi: 3.0.3
info:
  title: Paradigm API
  version: xenial-xerus (v2)
  description: >-
    A versatile and adaptable tool designed to integrate Generative AI into your
    applications
servers:
  - url: https://paradigm.lighton.ai
security: []
tags:
  - name: Models
    description: Operations about AI models
  - name: Files Search
    description: Operations about files search
  - name: Files
    description: Operations about files
  - name: Upload Sessions
    description: Operations about upload sessions
  - name: Workspaces
    description: Operations about workspaces
  - name: Users
    description: Operations about users
  - name: Companies
    description: Operations about companies
  - name: SCIM
    description: Operations about SCIM
  - name: Feedbacks
    description: Operations about feedbacks
  - name: Reporting
    description: Operations about reporting
  - name: Monitoring
    description: Operations about monitoring
  - name: Platform Status
    description: Operations about platform status
paths:
  /api/v2/filter/chunks:
    post:
      tags:
        - Files Search
      summary: Filter most relevant chunks
      description: >+
        This endpoint can be used to filter document chunks based on a given
        query.


        The query should be a single string.


        Chunk ids should be a list of strings. Each string should be the UUID of
        an existing document chunk.


        The `model` field should be the name of the model to use for filtering.


        An optional integer `n` can be provided, which can be used to return the
        first `n` chunks that pass the filter.

      operationId: api_v2_filter_chunks_create
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChunkFilterRequestSerializerV2'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/ChunkFilterRequestSerializerV2'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ChunkFilterRequestSerializerV2'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChunkFilterResponseSerializerV2'
          description: ''
      security:
        - bearerAuth: []
components:
  schemas:
    ChunkFilterRequestSerializerV2:
      type: object
      description: Request serializer for filtering document chunks based on a query.
      properties:
        query:
          type: string
          description: The query string to filter document chunks against
        chunk_ids:
          type: array
          items:
            type: string
          description: List of document chunk UUIDs to filter
        'n':
          type: integer
          nullable: true
          description: Maximum number of chunks to return (optional)
        model:
          type: string
          description: >-
            Model to use for the filtering, must exist and be configured. If no
            model is given, will try to use the 'reranker' finetune.
      required:
        - chunk_ids
        - model
        - query
    ChunkFilterResponseSerializerV2:
      type: object
      description: Response serializer for document chunk filtering results.
      properties:
        query:
          type: string
          description: The original query used for filtering
        chunks:
          type: array
          items:
            $ref: '#/components/schemas/ChunkSerializerV2'
          description: List of filtered document chunks with their relevance scores
      required:
        - chunks
        - query
    ChunkSerializerV2:
      type: object
      description: Serializer for individual document chunks in filter responses.
      properties:
        uuid:
          type: string
          format: uuid
          description: Unique identifier for the document chunk
        text:
          type: string
          description: Text content of the document chunk
        metadata:
          type: object
          additionalProperties: {}
          description: Metadata associated with the document chunk
        filter_score:
          type: number
          format: double
          description: Relevance score assigned by the filtering model
      required:
        - filter_score
        - metadata
        - text
        - uuid
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your auth token.

````