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

# Search knowledge

> Returns the knowledge passages closest to a query, best match first,
without generating an answer. Use it to build your own retrieval
flows or "related articles". No model is called: each search costs a
flat 0.2 credits.




## OpenAPI

````yaml /openapi.yaml post /agents/{agentId}/search
openapi: 3.0.3
info:
  title: ReyGrid API
  version: 1.0.3
  description: |
    ReyGrid API

    ## Persistent user conversations

    If you want to build a separate conversation system for each user,
    build a wrapper layer around the ReyGrid API.

    The wrapper should manage the application's own user IDs and map them
    to ReyGrid conversations.

    The wrapper is responsible for:
    - Managing and identifying users.
    - Storing the relationship between the application's userId and
      ReyGrid conversationId.
    - Persisting conversation IDs in the application's own database.
    - Reusing the stored conversationId when the same user continues
      a conversation.
    - Verifying that conversation IDs belong to the expected user before
      using them.

    ReyGrid's userId can also be used as a stable identifier for persistent
    conversations. However, if the application requires its own user and
    conversation management, it should maintain this mapping in its own
    database.
servers:
  - url: https://reygrid.com/api/v1
security: []
paths:
  /agents/{agentId}/search:
    post:
      summary: Search knowledge
      description: |
        Returns the knowledge passages closest to a query, best match first,
        without generating an answer. Use it to build your own retrieval
        flows or "related articles". No model is called: each search costs a
        flat 0.2 credits.
      operationId: searchKnowledge
      parameters:
        - $ref: '#/components/parameters/AgentId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequest'
            example:
              query: How do I get a refund?
              limit: 3
      responses:
        '200':
          description: Matching passages
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
              example:
                success: true
                results:
                  - score: 0.812
                    content: >-
                      Orders can be refunded within 30 days of delivery. Refunds
                      go back to the original payment method within 5 business
                      days.
                    source:
                      id: b7a1e2c4-5d3f-4e8a-9b10-2c4d6e8f0a1b
                      type: text
                      title: Refund policy
                  - score: 0.564
                    content: >-
                      To request a refund, open your order history and select
                      Request refund next to the order.
                    source:
                      id: 661a6da1-181f-43ac-9516-9847b9dd663b
                      type: file
                      title: handbook.pdf
        '400':
          $ref: '#/components/responses/InvalidBody'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: Not enough credits for the search (INSUFFICIENT_CREDITS)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          $ref: '#/components/responses/NotFound'
      security:
        - apiKeyAuth: []
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |-
            curl -X POST https://reygrid.com/api/v1/agents/{AgentId}/search \
              -H "Authorization: Bearer $REYGRID_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{"query": "How do I get a refund?", "limit": 3}'
        - lang: python
          label: Python SDK
          source: >-
            from reygrid import ReyGrid


            client = ReyGrid(api_key="YOUR_API_KEY")


            for result in client.search("{AgentId}", "How do I get a refund?",
            limit=3).results:
                print(round(result.score, 2), result.source.title)
                print(result.content)
        - lang: javascript
          label: TypeScript SDK
          source: >-
            import { ReyGrid } from "reygrid";


            const client = new ReyGrid({ apiKey: "YOUR_API_KEY" });


            const { results } = await client.search("{AgentId}", "How do I get a
            refund?", { limit: 3 });

            for (const r of results) console.log(r.score.toFixed(2),
            r.source.title, r.content);
components:
  parameters:
    AgentId:
      name: agentId
      in: path
      required: true
      description: The ID of the agent.
      schema:
        type: string
  schemas:
    SearchRequest:
      type: object
      required:
        - query
      properties:
        query:
          type: string
          minLength: 1
          maxLength: 1000
          example: How do I get a refund?
        limit:
          type: integer
          minimum: 1
          maximum: 20
          default: 5
    SearchResponse:
      type: object
      properties:
        success:
          type: boolean
        results:
          type: array
          items:
            $ref: '#/components/schemas/SearchResult'
    ErrorResponse:
      type: object
      required:
        - success
        - error
      properties:
        success:
          type: boolean
        output:
          type: object
          additionalProperties: true
        error:
          $ref: '#/components/schemas/Error'
        usage:
          $ref: '#/components/schemas/ChatUsage'
    SearchResult:
      type: object
      properties:
        score:
          type: number
          description: Similarity between 0 and 1. Higher is closer.
          example: 0.812
        content:
          type: string
          description: The matching passage.
        source:
          type: object
          properties:
            id:
              type: string
            type:
              $ref: '#/components/schemas/SourceType'
            title:
              type: string
    AuthErrorResponse:
      type: object
      required:
        - error
        - code
      properties:
        error:
          type: string
          example: Unauthorized
        code:
          type: string
          example: AUTH_REQUIRED
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
        list:
          type: array
          description: |
            Validation error details.
            Present when error.code is INVALID_BODY.
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
    ChatUsage:
      type: object
      required:
        - credits
      properties:
        credits:
          type: number
    SourceType:
      type: string
      enum:
        - text
        - qa
        - file
        - website
    ValidationErrorItem:
      type: object
      additionalProperties: true
  responses:
    InvalidBody:
      description: Invalid body or query (INVALID_BODY)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            success: false
            error:
              code: INVALID_BODY
              message: Invalid body
              list:
                title:
                  - Title too short
    Unauthorized:
      description: API key is missing or invalid
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AuthErrorResponse'
          example:
            error: Unauthorized
            code: AUTH_REQUIRED
    NotFound:
      description: The agent, source or message doesn't exist, or the key can't access it
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            success: false
            error:
              code: SOURCE_NOT_FOUND
              message: This source does not exist
  securitySchemes:
    apiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API-Key
      description: ReyGrid API key sent as a Bearer token.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.