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

# Search Knowledge Base

> Search in knowledge base using vector search

Perform semantic search across documents in a knowledge base using vector similarity. Returns the most relevant document chunks based on your query.

## Path Parameters

<ParamField path="kb_id" type="string" required>
  Unique identifier of the knowledge base to search (UUID format)
</ParamField>

## Query Parameters

<ParamField query="search_query" type="string" required>
  The search query text to find relevant documents
</ParamField>

<ParamField query="top_k" type="integer" default={5}>
  Number of results to return (default: 5, maximum: 50)
</ParamField>

## Response

Returns a flat array of search results, each containing:

<ResponseField name="content" type="string">
  The extracted text content from the matching document
</ResponseField>

<ResponseField name="score" type="number">
  Relevance score (float, higher indicates better match)
</ResponseField>

## Example Request

```bash theme={"dark"}
curl --request GET \
  --url 'https://api.xpander.ai/v1/knowledge/<kb-id>/search?search_query=pricing+plans&top_k=5' \
  --header 'x-api-key: <your-api-key>'
```

## Example Response

```json theme={"dark"}
[
  {
    "content": "The extracted text content from the matching document...",
    "score": 81.41
  }
]
```

## Notes

* Search only returns results from documents with `status: "completed"`
* Pending or failed documents are excluded from search results
* Empty results indicate no matching content in the knowledge base
* Returns 404 if the knowledge base is not found


## OpenAPI

````yaml GET /v1/knowledge/{kb_id}/search
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/knowledge/{kb_id}/search:
    get:
      tags:
        - API v1
        - Knowledge
        - Knowledge Search
      summary: Search In Knowledge Base
      description: Searches using vector search in knowledge base
      operationId: Search_in_knowledge_base_v1_knowledge__kb_id__search_get
      parameters:
        - name: kb_id
          in: path
          required: true
          schema:
            type: string
            title: Kb Id
        - name: search_query
          in: query
          required: true
          schema:
            type: string
            description: Query to search in the VDB
            title: Search Query
          description: Query to search in the VDB
        - name: use_bubble
          in: query
          required: false
          schema:
            anyOf:
              - type: boolean
              - type: 'null'
            description: Should use bubble search to return the result capped
            default: false
            title: Use Bubble
          description: Should use bubble search to return the result capped
        - name: bubble_size
          in: query
          required: false
          schema:
            anyOf:
              - type: integer
              - type: 'null'
            description: Bubble size (padding + result + margin)
            default: 1000
            title: Bubble Size
          description: Bubble size (padding + result + margin)
        - name: top_k
          in: query
          required: false
          schema:
            anyOf:
              - type: integer
              - type: 'null'
            description: Top K Results
            default: 10
            title: Top K
          description: Top K Results
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/VectorSearchResult'
                title: >-
                  Response Search In Knowledge Base V1 Knowledge  Kb Id  Search
                  Get
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    VectorSearchResult:
      properties:
        content:
          type: string
          title: Content
          description: The content of the document
        score:
          type: number
          title: Score
          description: The search result score
      type: object
      required:
        - content
        - score
      title: VectorSearchResult
      description: |-
        Represents the result of a vector search.

        Attributes:
            content (str): The content of the document.
            score (float): The search result score.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    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
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````