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

# Semantic Retrieval

> This endpoint used to retrieve the relevant chunks of the knowledge base based on the user question in the Pawa AI Platform.



## OpenAPI

````yaml POST /store/knowledge-base/semantic-retrieval
openapi: 3.1.0
info:
  title: Pawa AI APIs
  description: >-
    API endpoints in Pawa Platform to perform CRUD operations on different
    features using Pawa AI, a digital assistant built for Africa for various
    tasks.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.pawa-ai.com/v1
    description: Production Server
security:
  - bearerAuth: []
paths:
  /store/knowledge-base/semantic-retrieval:
    post:
      tags:
        - Knowledge base semantic retrieval
      summary: Knowledge base semantic retrieval
      description: >-
        This endpoint used to retrieve the relevant chunks of the knowledge base
        based on the user question in the Pawa AI Platform.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RelevantKBRequestDto'
      responses:
        '200':
          description: Relevant chunks retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RelevantChunksResponseData'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                badRequest:
                  value:
                    success: false
                    message: Invalid input provided
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  value:
                    success: false
                    message: Unauthorized access
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  value:
                    success: false
                    message: You do not have permission to access this resource
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                notFound:
                  value:
                    success: false
                    message: Resource does not exist
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                tooManyRequests:
                  value:
                    success: false
                    message: Rate limit exceeded. Please try again later.
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                serverError:
                  value:
                    success: false
                    message: Internal server error
components:
  schemas:
    RelevantKBRequestDto:
      type: object
      properties:
        knowledge_base_id:
          type: string
          description: >-
            The knowledge_base_reference_id of the knowledge base to perform the
            RAG if the question asked relates to the purpose of the
            knowledge_base_tool provided.
          default: kb-f9d817f5-46c2-49b2-b07f-f3db8df0887a
        question_asked_by_user:
          type: string
          description: The question asked by the user to perform the RAG.
          default: What is the purpose of this knowledge base?
      required:
        - knowledge_base_id
        - question_asked_by_user
    RelevantChunksResponseData:
      type: object
      properties:
        finalRelevantChunk:
          description: Final relevant chunk based on the user query.
          example:
            - Hello Pawa AI, I am the final relevant chunk you need
          type: array
          items:
            type: string
        filteredResults:
          description: >-
            Filtered results based on the relevance of the chunks to the user
            query.
          example:
            - id: 63
              knowledgeBaseId: 7
              documentName: 131.3-Visa-Requirements-Schengen-2021-05 (1) (1).pdf
              chunk: >-
                and for the whole period of staying in the Schengen area. In
                order to have a flexible travel schedule it is suggested to
                issue the Insurance for a few days longer than the planned
                travel time...
              distance: 0.7506968916261936
            - id: 76
              knowledgeBaseId: 7
              documentName: 131.3-Visa-Requirements-Schengen-2021-05 (1) (1).pdf
              chunk: >-
                plan agreed with the clinic. Medical health documentation issued
                by the applicant’s country of residence...
              distance: 0.7515738980069386
          type: array
          items:
            $ref: '#/components/schemas/chunksData'
      required:
        - finalRelevantChunk
        - filteredResults
    ErrorResponse:
      required:
        - success
        - message
      type: object
      properties:
        success:
          type: boolean
          example: false
        message:
          type: string
          example: An error occurred
    chunksData:
      type: object
      properties:
        id:
          type: number
          example: 63
        knowledgeBaseId:
          type: number
          example: 7
        documentName:
          type: string
          example: 131.3-Visa-Requirements-Schengen-2021-05 (1) (1).pdf
        chunk:
          type: string
          example: and for the whole period of staying in the Schengen area...
        distance:
          type: number
          example: 0.7506968916261936
      required:
        - id
        - knowledgeBaseId
        - documentName
        - chunk
        - distance
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````