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

# Search knowledge base

> Search a Knowledge Base and return the most similar chunks, along with their search and rerank scores. Note that all configuration changes made in the API will override the settings in the UI.

<Note>
  **Related guide**: Knowledge bases guide. See the [Knowledge bases guide](/docs/ai-studio/ai-engineering/knowledge-bases) for a walkthrough with examples.
</Note>


## OpenAPI

````yaml post /v2/knowledge/{knowledge_id}/search
openapi: 3.1.0
info:
  title: orq.ai API
  version: '2.0'
  description: orq.ai API documentation
servers:
  - url: https://my.orq.ai
security:
  - ApiKey: []
tags:
  - name: Chunking
    description: Split text into smaller chunks for retrieval and generation workflows.
  - name: File Systems
    description: >-
      Create and manage persistent file systems that agents and MCP clients read
      from and write to.
  - name: Knowledge Bases
    description: Create and manage knowledge bases used by agents and retrieval workflows.
  - name: Memory Stores
    description: Create and manage memory stores, memories, and memory documents.
  - name: Evals
    description: Run an evaluator against a conversation and its result
  - description: List models available through the AI Router.
    name: Models
  - name: Policies
  - name: Alerts
    description: >-
      Alerts evaluate a Reporting API metric on a fixed interval and fire
      notifications through notifiers when the value breaches a threshold. Each
      breach opens a trigger that tracks the incident until the value recovers.
  - name: Annotation Queues
    description: Annotation queues collect spans for human review.
  - name: API keys
    description: >-
      API keys authenticate programmatic access to the workspace. They expose
      opaque tokens, per-domain access grants, and budget and rate-limit
      constraints.
  - name: Audit Logs
    description: Audit logs record workspace entity changes and access-relevant events.
  - name: Budgets
    description: >-
      Budgets govern spend, token usage, and request rate across six scopes:
      workspace, project, identity, API key, provider, and model. Every
      applicable budget is enforced, and the most restrictive limit applies per
      dimension.
  - name: Files
    description: File upload and retrieval operations.
  - name: Guardrail Rules
    description: >-
      Guardrail Rules conditionally enforce evaluators and plugins for AI
      Gateway traffic. Rules may be scoped to a project or the whole workspace.
  - name: Identities
    description: >-
      Identities represent end users from your system for usage and engagement
      tracking.
  - name: Management keys
    description: >-
      Management keys are workspace-scoped credentials that authenticate
      programmatic access to workspace administration surfaces (API keys,
      budgets). Unlike project-scoped API keys, a management key always operates
      at the workspace level.
  - name: MCP Gateway
    description: >-
      Register upstream MCP servers, discover and sync their tools, and assemble
      gateways that expose a curated tool surface to MCP clients.
  - name: Model Catalog
    description: >-
      Browse the orq.ai model catalog: every model orq offers, across every
      provider, with pricing, capabilities and benchmark data. List endpoints
      only return models that are not deprecated. This API is public, requires
      no authentication, and is rate limited to 120 requests per minute per IP.
      Responses carry a 5-minute cache-control max-age.
  - name: Notifiers
    description: Notifier destinations used to send delivery and workflow notifications.
  - name: Projects
    description: Projects organize resources within a workspace
  - name: Routing Rules
    description: >-
      Routing Rules conditionally select models and enforce request plugins for
      AI Gateway traffic. Rules are evaluated by ascending priority and may be
      scoped to a project or the whole workspace.
  - name: Skills
    description: >-
      Skills are modular instructions you can use to codify processes and
      conventions
  - name: Smart Routers
    description: >-
      Create and manage workspace Smart Routers. A Smart Router selects a model
      from an eligible pool for each request according to a quality, balanced,
      or cost profile.
  - name: Webhooks
    description: >-
      Create and manage webhooks that deliver workspace events to external HTTPS
      endpoints.
  - name: Workspace Security
    description: >-
      Workspace-level domain verification and IP allowlist controls. These
      operations are restricted to workspace administrators.
  - name: Workspace Settings
    description: >-
      Workspace-level settings managed with a workspace credential. A workspace
      is the tenant, so these settings are a singleton — there is nothing to
      create or delete, only read and update.
  - name: Responses
  - description: Run agents on a cron cadence. Minimum firing interval is 1 hour.
    name: Agent Schedules
  - name: Embeddings
  - name: Logs
    description: >-
      OpenTelemetry log query API. Search, filter, aggregate, and facet log
      records ingested via OTLP.
  - name: Reporting
    description: >-
      GenAI reporting API over canonical analytics rollups. Accepts a metric
      name, time range, grain, group-by, and filters; returns a typed time
      series and optional totals.
  - name: Traces
    description: >-
      Query and inspect ingested trace data: search trace summaries, aggregate
      metrics, and read individual traces and their spans.
externalDocs:
  url: https://docs.orq.ai
  description: orq.ai Documentation
paths:
  /v2/knowledge/{knowledge_id}/search:
    post:
      tags:
        - Knowledge Bases
      summary: Search knowledge base
      description: >-
        Search a Knowledge Base and return the most similar chunks, along with
        their search and rerank scores. Note that all configuration changes made
        in the API will override the settings in the UI.
      operationId: SearchKnowledge
      parameters:
        - name: knowledge_id
          in: path
          description: The unique identifier or key of the knowledge base.
          required: true
          schema:
            type: string
      requestBody:
        description: A search request for chunks in a knowledge base
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchKnowledgeRequest'
        required: true
      responses:
        '200':
          description: Search knowledge base
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchKnowledgeResponse'
      x-code-samples:
        - lang: curl
          label: Core
          source: |-
            curl --request POST \
              --url "https://my.orq.ai/v2/knowledge/$KNOWLEDGE_ID/search" \
              --header "Authorization: Bearer $ORQ_API_KEY" \
              --header 'Content-Type: application/json' \
              --data '{
                "query": "What is our refund policy?",
                "top_k": 10,
                "search_type": "hybrid_search",
                "search_options": {
                  "include_vectors": false,
                  "include_metadata": true,
                  "include_scores": true
                }
              }'
        - lang: typescript
          label: Node.js
          source: |-
            import { Orq } from "@orq-ai/node";

            const orq = new Orq({
              apiKey: process.env["ORQ_API_KEY"]
            });

            const result = await orq.knowledge.search({
              knowledgeId: process.env["KNOWLEDGE_ID"],
              requestBody: {
                query: "What is our refund policy?",
                topK: 10,
                searchType: "hybrid_search",
                searchOptions: {
                  includeVectors: false,
                  includeMetadata: true,
                  includeScores: true
                }
              }
            });

            console.log(result.matches);
        - lang: python
          label: Python
          source: |-
            import os
            from orq_ai_sdk import Orq

            orq = Orq(api_key=os.getenv("ORQ_API_KEY"))

            result = orq.knowledge.search(
                knowledge_id=os.getenv("KNOWLEDGE_ID"),
                query="What is our refund policy?",
                top_k=10,
                search_type="hybrid_search",
                search_options={
                    "include_vectors": False,
                    "include_metadata": True,
                    "include_scores": True,
                },
            )

            print(result.matches)
components:
  schemas:
    SearchKnowledgeRequest:
      required:
        - query
      type: object
      properties:
        query:
          minLength: 1
          type: string
          description: The query to use to search the knowledge base
        top_k:
          maximum: 100
          minimum: 1
          type: integer
          description: >-
            The number of results to return. If not provided, will default to
            the knowledge base configured `top_k`.
          format: int32
        threshold:
          maximum: 1
          type: number
          description: >-
            The threshold to apply to the search. If not provided, will default
            to the knowledge base configured `threshold`
          format: double
          minimum: 0
        search_type:
          $ref: '#/components/schemas/SearchType'
          default: hybrid_search
          description: >-
            The type of search to perform. If not provided, will default to the
            knowledge base configured `retrieval_type`
        filter_by:
          description: >-
            The metadata filter to apply to the search. Check the [Searching a
            Knowledge
            Base](https://docs.orq.ai/docs/knowledge/api#knowledge-base-search)
            for more information.
          anyOf:
            - type: object
              additionalProperties:
                anyOf:
                  - type: object
                    properties:
                      eq:
                        anyOf:
                          - type: string
                            title: string
                            description: String
                          - type: number
                            title: number
                            description: Number
                          - type: boolean
                            title: boolean
                            description: Boolean
                    required:
                      - eq
                    title: eq
                    description: Equal to
                  - type: object
                    properties:
                      ne:
                        anyOf:
                          - type: string
                            title: string
                            description: String
                          - type: number
                            title: number
                            description: Number
                          - type: boolean
                            title: boolean
                            description: Boolean
                    required:
                      - ne
                    title: ne
                    description: Not equal to
                  - type: object
                    properties:
                      gt:
                        type: number
                    required:
                      - gt
                    title: gt
                    description: Greater than
                  - type: object
                    properties:
                      gte:
                        type: number
                    required:
                      - gte
                    title: gte
                    description: Greater than or equal to
                  - type: object
                    properties:
                      lt:
                        type: number
                    required:
                      - lt
                    title: lt
                    description: Less than
                  - type: object
                    properties:
                      lte:
                        type: number
                    required:
                      - lte
                    title: lte
                    description: Less than or equal to
                  - type: object
                    properties:
                      in:
                        type: array
                        items:
                          anyOf:
                            - type: string
                              title: string
                              description: String
                            - type: number
                              title: number
                              description: Number
                            - type: boolean
                              title: boolean
                              description: Boolean
                    required:
                      - in
                    title: in
                    description: In
                  - type: object
                    properties:
                      nin:
                        type: array
                        items:
                          anyOf:
                            - type: string
                              title: string
                              description: String
                            - type: number
                              title: number
                              description: Number
                            - type: boolean
                              title: boolean
                              description: Boolean
                    required:
                      - nin
                    title: nin
                    description: Not in
                  - type: object
                    properties:
                      exists:
                        type: boolean
                    required:
                      - exists
                    title: exists
                    description: Exists
              title: Search operator
            - type: object
              properties:
                and:
                  type: array
                  items:
                    type: object
                    additionalProperties:
                      anyOf:
                        - type: object
                          properties:
                            eq:
                              anyOf:
                                - type: string
                                  title: string
                                  description: String
                                - type: number
                                  title: number
                                  description: Number
                                - type: boolean
                                  title: boolean
                                  description: Boolean
                          required:
                            - eq
                          title: eq
                          description: Equal to
                        - type: object
                          properties:
                            ne:
                              anyOf:
                                - type: string
                                  title: string
                                  description: String
                                - type: number
                                  title: number
                                  description: Number
                                - type: boolean
                                  title: boolean
                                  description: Boolean
                          required:
                            - ne
                          title: ne
                          description: Not equal to
                        - type: object
                          properties:
                            gt:
                              type: number
                          required:
                            - gt
                          title: gt
                          description: Greater than
                        - type: object
                          properties:
                            gte:
                              type: number
                          required:
                            - gte
                          title: gte
                          description: Greater than or equal to
                        - type: object
                          properties:
                            lt:
                              type: number
                          required:
                            - lt
                          title: lt
                          description: Less than
                        - type: object
                          properties:
                            lte:
                              type: number
                          required:
                            - lte
                          title: lte
                          description: Less than or equal to
                        - type: object
                          properties:
                            in:
                              type: array
                              items:
                                anyOf:
                                  - type: string
                                    title: string
                                    description: String
                                  - type: number
                                    title: number
                                    description: Number
                                  - type: boolean
                                    title: boolean
                                    description: Boolean
                          required:
                            - in
                          title: in
                          description: In
                        - type: object
                          properties:
                            nin:
                              type: array
                              items:
                                anyOf:
                                  - type: string
                                    title: string
                                    description: String
                                  - type: number
                                    title: number
                                    description: Number
                                  - type: boolean
                                    title: boolean
                                    description: Boolean
                          required:
                            - nin
                          title: nin
                          description: Not in
                        - type: object
                          properties:
                            exists:
                              type: boolean
                          required:
                            - exists
                          title: exists
                          description: Exists
              required:
                - and
              title: and
              description: And
            - type: object
              properties:
                or:
                  type: array
                  items:
                    type: object
                    additionalProperties:
                      anyOf:
                        - type: object
                          properties:
                            eq:
                              anyOf:
                                - type: string
                                  title: string
                                  description: String
                                - type: number
                                  title: number
                                  description: Number
                                - type: boolean
                                  title: boolean
                                  description: Boolean
                          required:
                            - eq
                          title: eq
                          description: Equal to
                        - type: object
                          properties:
                            ne:
                              anyOf:
                                - type: string
                                  title: string
                                  description: String
                                - type: number
                                  title: number
                                  description: Number
                                - type: boolean
                                  title: boolean
                                  description: Boolean
                          required:
                            - ne
                          title: ne
                          description: Not equal to
                        - type: object
                          properties:
                            gt:
                              type: number
                          required:
                            - gt
                          title: gt
                          description: Greater than
                        - type: object
                          properties:
                            gte:
                              type: number
                          required:
                            - gte
                          title: gte
                          description: Greater than or equal to
                        - type: object
                          properties:
                            lt:
                              type: number
                          required:
                            - lt
                          title: lt
                          description: Less than
                        - type: object
                          properties:
                            lte:
                              type: number
                          required:
                            - lte
                          title: lte
                          description: Less than or equal to
                        - type: object
                          properties:
                            in:
                              type: array
                              items:
                                anyOf:
                                  - type: string
                                    title: string
                                    description: String
                                  - type: number
                                    title: number
                                    description: Number
                                  - type: boolean
                                    title: boolean
                                    description: Boolean
                          required:
                            - in
                          title: in
                          description: In
                        - type: object
                          properties:
                            nin:
                              type: array
                              items:
                                anyOf:
                                  - type: string
                                    title: string
                                    description: String
                                  - type: number
                                    title: number
                                    description: Number
                                  - type: boolean
                                    title: boolean
                                    description: Boolean
                          required:
                            - nin
                          title: nin
                          description: Not in
                        - type: object
                          properties:
                            exists:
                              type: boolean
                          required:
                            - exists
                          title: exists
                          description: Exists
              required:
                - or
              title: or
              description: Or
        search_options:
          allOf:
            - $ref: '#/components/schemas/SearchOptions'
          description: Additional search options
        rerank_config:
          allOf:
            - $ref: '#/components/schemas/SearchRerankConfig'
          description: >-
            Override the rerank configuration for this search. If not provided,
            will use the knowledge base configured rerank settings.
        agentic_rag_config:
          description: >-
            Override the agentic RAG configuration for this search. If not
            provided, will use the knowledge base configured agentic RAG
            settings.
          anyOf:
            - type: object
              allOf:
                - $ref: '#/components/schemas/GoogleProtobufValue'
              anyOf:
                - required:
                    - model
                - required:
                    - model_db_id
                    - provider
              properties:
                model:
                  type: string
                  description: >-
                    The name of the model for the Agent to use. Refer to the
                    [model list](https://docs.orq.ai/docs/proxy#/chat-models).
                model_db_id:
                  type: string
                  description: Identifier of the stored model configuration to use.
                provider:
                  type: string
                  description: Provider identifier for the stored model configuration.
                integration_id:
                  type:
                    - string
                    - 'null'
                  description: >-
                    Optional integration identifier for the stored model
                    configuration.
            - type: 'null'
        retrieval_config:
          allOf:
            - $ref: '#/components/schemas/SearchRetrievalConfig'
          description: >-
            Override the stored retrieval configuration for this search. If not
            provided, the knowledge base configuration is used.
      description: >-
        Search request. Sets the knowledge base and query, plus optional
        retrieval
         settings.
    SearchKnowledgeResponse:
      required:
        - matches
      type: object
      properties:
        matches:
          type: array
          items:
            $ref: '#/components/schemas/SearchKnowledgeMatch'
          description: >-
            Matching chunks. The response codec must emit this field even when
            empty.
    SearchType:
      type: string
      enum:
        - vector_search
        - keyword_search
        - hybrid_search
    SearchOptions:
      type: object
      properties:
        include_vectors:
          type: boolean
          description: Whether to include the vector in the chunk
        include_metadata:
          type: boolean
          description: Whether to include the metadata in the chunk
        include_scores:
          type: boolean
          description: Whether to include the scores in the chunk
    SearchRerankConfig:
      required:
        - model
      type: object
      properties:
        model:
          example: cohere/rerank-multilingual-v3.0
          type: string
          description: >-
            The name of the rerank model to use. Refer to the [model
            list](https://docs.orq.ai/docs/proxy#/rerank-models).
        threshold:
          maximum: 1
          type: number
          default: 0
          description: >-
            The threshold value used to filter the rerank results, only
            documents with a relevance score greater than the threshold will be
            returned
          format: double
          minimum: 0
        top_k:
          maximum: 100
          minimum: 1
          type: integer
          default: 10
          description: >-
            The number of top results to return after reranking. If not
            provided, will default to the knowledge base configured `top_k`.
          format: int32
    GoogleProtobufValue:
      description: >-
        Represents a dynamically typed value which can be either null, a number,
        a string, a boolean, a recursive struct value, or a list of values.
    SearchRetrievalConfig:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/SearchType'
        top_k:
          type: integer
          format: int32
        threshold:
          type: number
          format: double
        rerank_config:
          type:
            - object
            - 'null'
          description: >-
            Override reranking for this retrieval configuration. Omit to inherit
            stored settings or set to null to disable reranking.
          properties:
            enabled:
              type: boolean
            provider:
              type: string
            top_k:
              type: integer
              format: int32
              minimum: 1
              maximum: 100
            model:
              type: string
            model_db_id:
              type: string
            model_type:
              type: string
              enum:
                - rerank
            model_parameters:
              type: object
              properties:
                threshold:
                  type: number
            integration_id:
              type:
                - string
                - 'null'
      description: >-
        SearchRetrievalConfig is the retrieval strategy configuration. Type
        remains
         optional because external knowledge bases use the same base configuration
         without a retrieval strategy discriminator.
    SearchKnowledgeMatch:
      required:
        - id
        - text
      type: object
      properties:
        id:
          type: string
        text:
          type: string
        vector:
          type: array
          items:
            type: number
            format: double
          description: Embedding vector of the chunk, returned only when requested.
        metadata:
          type: object
          description: Arbitrary chunk metadata, omitted unless requested.
        scores:
          allOf:
            - $ref: '#/components/schemas/SearchKnowledgeScores'
          description: Search and rerank scores, omitted unless requested.
    SearchKnowledgeScores:
      type: object
      properties:
        rerank_score:
          type: number
          format: double
        search_score:
          type: number
          format: double
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````