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

# Get Document Answer

>  Answer a question based on the documents matching the provided metadata filter. <br /> The `metadata_filter` parameter supports MongoDB-like query syntax with operators: <br />
- Comparison: `$eq, $ne, $gt, $lt, $gte, $lte, $in, $nin`
- Array: `$contains, $containsAny, $notContains, $size`
- Logical: `$and, $or, $not`
- Type: `$type`
- Regex: `$regex, $iregex`
<br />
#### Example Metadata Filter
```json { "$and": [ { "category": "finance" }, { "tags": { "$contains": ["important"] } }, { "$or": [ { "priority": { "$gt": 2 } }, { "status": "active" } ] } ] } ```




## OpenAPI

````yaml post /api/v1/documents/answer
openapi: 3.1.0
info:
  title: Fieldwise API
  description: API for the Fieldwise platform.
  version: 1.0.0
servers:
  - url: https://api.fieldwise.ai
security:
  - ApiKeyAuth: []
paths:
  /api/v1/documents/answer:
    post:
      tags:
        - Documents
      summary: Get Document Answer
      description: >-
        Answer a question based on the documents matching the provided metadata
        filter.


        The metadata_filter parameter supports MongoDB-like query syntax with
        operators:

        - Comparison: $eq, $ne, $gt, $lt, $gte, $lte, $in, $nin

        - Array: $contains, $containsAny, $notContains, $size

        - Logical: $and, $or, $not

        - Type: $type

        - Regex: $regex, $iregex


        Example metadata filter:    ```json

        {
            "$and": [
                {"category": "finance"},
                {"tags": {"$contains": ["important"]}},
                {
                    "$or": [
                        {"priority": {"$gt": 2}},
                        {"status": "active"}
                    ]
                }
            ]
        }    ```
      operationId: get_document_answer_api_v1_documents_answer_post
      parameters:
        - name: X-API-Key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Api-Key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QuestionRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnswerResponse'
        '401':
          description: Invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetail'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetail'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetail'
components:
  schemas:
    QuestionRequest:
      properties:
        question:
          type: string
          title: Question
        optimize_metadata:
          type: boolean
          title: Optimize Metadata
          description: If True, optimize the metadata filter based on the question
          default: false
        optimize_question:
          type: boolean
          title: Optimize Question
          description: >-
            If True, optimize the question by removing parts covered by metadata
            filter
          default: false
        metadata_filter:
          anyOf:
            - type: object
            - type: 'null'
          title: Metadata Filter
          description: Optional metadata filters using MongoDB-like query syntax
        created_at_filter:
          anyOf:
            - type: object
            - type: 'null'
          title: Created At Filter
          description: >-
            Filter by created_at database field. Supports operators: $eq, $ne,
            $gt, $lt, $gte, $lte, $in, $nin. Use ISO date format (e.g.,
            '2024-01-01T00:00:00')
        updated_at_filter:
          anyOf:
            - type: object
            - type: 'null'
          title: Updated At Filter
          description: >-
            Filter by updated_at database field. Supports operators: $eq, $ne,
            $gt, $lt, $gte, $lte, $in, $nin. Use ISO date format (e.g.,
            '2024-01-01T00:00:00')
        format:
          anyOf:
            - type: string
              enum:
                - MARKDOWN
                - PLAIN_TEXT
            - type: 'null'
          title: Format
          description: Format of the answer (MARKDOWN or PLAIN_TEXT)
          default: MARKDOWN
      type: object
      required:
        - question
      title: QuestionRequest
      description: Request model for asking questions about documents.
      example:
        format: MARKDOWN
        metadata_filter:
          $and:
            - category: finance
            - priority:
                $gt: 2
            - tags:
                $contains:
                  - important
        question: What is the main topic of the document?
    AnswerResponse:
      properties:
        success:
          type: boolean
          title: Success
          default: true
        data:
          allOf:
            - $ref: '#/components/schemas/AnswerResponseData'
          description: Response data
        error:
          anyOf:
            - $ref: '#/components/schemas/ErrorDetail'
            - type: 'null'
        meta:
          $ref: '#/components/schemas/MetaData'
      type: object
      required:
        - data
      title: AnswerResponse
    ErrorDetail:
      properties:
        message:
          type: string
          title: Message
          description: Error message
        error_code:
          type: string
          title: Error Code
          description: Error code identifier
        details:
          anyOf:
            - items:
                type: object
              type: array
            - type: 'null'
          title: Details
          description: Additional error details
      type: object
      required:
        - message
        - error_code
      title: ErrorDetail
      description: Schema for API error responses.
      example:
        error_code: RESOURCE_NOT_FOUND
        message: Resource not found
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    AnswerResponseData:
      properties:
        answer:
          type: string
          title: Answer
          description: Generated answer
        sources:
          items:
            $ref: '#/components/schemas/AnswerSource'
          type: array
          title: Sources
          description: Source references
        format:
          type: string
          title: Format
          description: Format of the answer (MARKDOWN or PLAIN_TEXT)
        optimized_question:
          anyOf:
            - type: string
            - type: 'null'
          title: Optimized Question
          description: The question after optimization, if optimization was requested
        optimized_metadata:
          anyOf:
            - type: object
            - type: 'null'
          title: Optimized Metadata
          description: >-
            The metadata filter after optimization, if optimization was
            requested
      type: object
      required:
        - answer
        - format
      title: AnswerResponseData
    MetaData:
      properties:
        timestamp:
          type: string
          format: date-time
          title: Timestamp
        version:
          type: string
          title: Version
          default: '1.0'
      type: object
      title: MetaData
      description: Metadata for API responses
    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
    AnswerSource:
      properties:
        document_id:
          type: integer
          title: Document Id
        page_number:
          type: integer
          title: Page Number
        relevance:
          type: string
          title: Relevance
        document_metadata:
          type: object
          title: Document Metadata
      type: object
      required:
        - document_id
        - page_number
        - relevance
        - document_metadata
      title: AnswerSource
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````