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

# Unified search

> Runs unified search across both unstructured documents and structured connector-backed data in your environment. Memic classifies the incoming query and intelligently routes it — natural-language questions are answered by semantic search over indexed documents, while structured queries (filters, aggregations, lookups) hit connector-backed sources. Returns ranked results with source citations plus routing metadata so you can see which path was taken.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/search
openapi: 3.1.0
info:
  title: Memic API
  description: >-
    Memic is a memory layer for AI applications. The Memic API lets you ingest
    documents, run semantic search and chat, and manage prompts — all scoped to
    an environment via a single API key.
  version: 1.0.0
servers:
  - url: https://api.memic.ai
    description: Production
security:
  - MemicApiKey: []
tags:
  - name: Endpoints
    description: All 10 Memic API endpoints.
paths:
  /api/v1/search:
    post:
      tags:
        - Endpoints
      summary: Unified search
      description: >-
        Runs unified search across both unstructured documents and structured
        connector-backed data in your environment. Memic classifies the incoming
        query and intelligently routes it — natural-language questions are
        answered by semantic search over indexed documents, while structured
        queries (filters, aggregations, lookups) hit connector-backed sources.
        Returns ranked results with source citations plus routing metadata so
        you can see which path was taken.
      operationId: search
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - MemicApiKey: []
components:
  schemas:
    SearchRequest:
      properties:
        query:
          type: string
          maxLength: 1000
          minLength: 1
          title: Query
          description: The search query text
          examples:
            - What are the key findings in the cybersecurity report?
        project_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Project Id
          description: Optional project ID to limit search scope
        file_ids:
          anyOf:
            - items:
                type: string
                format: uuid
              type: array
            - type: 'null'
          title: File Ids
          description: Optional list of file IDs to limit search scope
        environment_slug:
          anyOf:
            - type: string
            - type: 'null'
          title: Environment Slug
          description: >-
            Optional environment slug to filter search ('staging' or
            'production')
        top_k:
          type: integer
          maximum: 50
          minimum: 1
          title: Top K
          description: Number of results to return (max 50)
          default: 10
        min_score:
          type: number
          maximum: 1
          minimum: 0
          title: Min Score
          description: Minimum similarity score threshold (0.0 to 1.0)
          default: 0.7
        include_metadata:
          type: boolean
          title: Include Metadata
          description: Whether to include file and chunk metadata in results
          default: true
        connector_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Connector Id
          description: 'Optional: Force query to use a specific connector'
        force_route:
          anyOf:
            - $ref: '#/components/schemas/QueryRouteEnum'
            - type: 'null'
          description: 'Optional: Force query routing (structured, semantic, or hybrid)'
        metadata_filters:
          anyOf:
            - $ref: '#/components/schemas/MetadataFilters'
            - type: 'null'
          description: >-
            Metadata filters for vector search (reference_id, page_number,
            etc.). Used in lookup-based search where SQL returns filter values.
      type: object
      required:
        - query
      title: SearchRequest
      description: Request model for semantic search.
    SearchResponse:
      properties:
        query:
          type: string
          title: Query
          description: Original search query
        results:
          $ref: '#/components/schemas/SearchResults'
          description: All search results by type
        total_results:
          type: integer
          title: Total Results
          description: Total number of results returned
        routing:
          anyOf:
            - $ref: '#/components/schemas/RoutingInfo'
            - type: 'null'
          description: Query routing information
        search_time_ms:
          type: number
          title: Search Time Ms
          description: Search execution time in milliseconds
        namespace:
          type: string
          title: Namespace
          description: Organization namespace used for search
        filters_applied:
          additionalProperties: true
          type: object
          title: Filters Applied
          description: Filters applied to the search
      type: object
      required:
        - query
        - total_results
        - search_time_ms
        - namespace
        - filters_applied
      title: SearchResponse
      description: Response model for semantic search.
      example:
        filters_applied:
          project_id: d1710969-5973-4cf1-8c4e-3264158e765f
        namespace: 8e9fd1e0-e355-4394-9878-b59ec0fffcfd
        query: quarterly revenue
        results:
          semantic:
            - category: Security
              chunk_id: 123e4567-e89b-12d3-a456-426614174000
              chunk_index: 5
              content: The cybersecurity landscape shows increasing threats...
              file_id: 123e4567-e89b-12d3-a456-426614174001
              file_name: Cyber_Report_2024.pdf
              mime_type: application/pdf
              page_number: 3
              score: 0.92
              tags:
                - cybersecurity
                - report
              token_count: 256
          structured:
            columns:
              - description: Customer name
                name: customer
                type: varchar
              - name: revenue
                type: integer
            rows:
              - customer: Acme
                revenue: 50000
              - customer: Beta
                revenue: 75000
        routing:
          reasoning: Query combines document search with structured data
          route: hybrid
        search_time_ms: 125.5
        total_results: 3
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    QueryRouteEnum:
      type: string
      enum:
        - structured
        - semantic
        - hybrid
      title: QueryRouteEnum
      description: Query routing options.
    MetadataFilters:
      properties:
        reference_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Reference Id
          description: Client-provided file reference ID (matches file.reference_id)
        reference_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Reference Ids
          description: Multiple reference IDs to match (OR logic)
        page_number:
          anyOf:
            - type: integer
              minimum: 1
            - type: 'null'
          title: Page Number
          description: Exact page number match
        page_numbers:
          anyOf:
            - items:
                type: integer
              type: array
            - type: 'null'
          title: Page Numbers
          description: Match any of these page numbers (OR logic)
        page_range:
          anyOf:
            - $ref: '#/components/schemas/PageRangeFilter'
            - type: 'null'
          description: Page number range filter (inclusive)
        category:
          anyOf:
            - type: string
            - type: 'null'
          title: Category
          description: Exact category match
        document_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Document Type
          description: Exact document type match
      type: object
      title: MetadataFilters
      description: >-
        Type-safe metadata filters for vector search.


        Used for lookup-based search where SQL query returns filter values

        (e.g., reference_id, page_number) that are then applied to vector
        search.


        Example usage:
            # Filter by reference_id (from SQL: file_ref = 'TG_G1_Math')
            {"reference_id": "TG_G1_Math"}

            # Filter by reference_id + exact page
            {"reference_id": "TG_G1_Math", "page_number": 40}

            # Filter by reference_id + multiple pages
            {"reference_id": "TG_G1_Math", "page_numbers": [40, 41, 42]}

            # Filter by reference_id + page range
            {"reference_id": "TG_G1_Math", "page_range": {"gte": 40, "lte": 50}}
    SearchResults:
      properties:
        semantic:
          items:
            $ref: '#/components/schemas/SearchResultChunk'
          type: array
          title: Semantic
          description: Semantic search results from vector store
          default: []
        structured:
          anyOf:
            - $ref: '#/components/schemas/StructuredResult'
            - type: 'null'
          description: Structured query results with schema
      type: object
      title: SearchResults
      description: Container for all result types.
    RoutingInfo:
      properties:
        route:
          type: string
          title: Route
          description: 'Route used: structured, semantic, or hybrid'
        reasoning:
          anyOf:
            - type: string
            - type: 'null'
          title: Reasoning
          description: Why this route was chosen
        connector_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Connector Id
          description: Connector used for structured query
        connector_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Connector Name
          description: Name of connector used
        sql_generated:
          anyOf:
            - type: string
            - type: 'null'
          title: Sql Generated
          description: SQL query generated (if structured)
        sql_explanation:
          anyOf:
            - type: string
            - type: 'null'
          title: Sql Explanation
          description: Explanation of SQL query
      type: object
      required:
        - route
      title: RoutingInfo
      description: Information about how the query was routed.
    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
    PageRangeFilter:
      properties:
        gte:
          anyOf:
            - type: integer
              minimum: 1
            - type: 'null'
          title: Gte
          description: Page number greater than or equal to
        lte:
          anyOf:
            - type: integer
              minimum: 1
            - type: 'null'
          title: Lte
          description: Page number less than or equal to
      type: object
      title: PageRangeFilter
      description: Filter pages by range (inclusive).
    SearchResultChunk:
      properties:
        chunk_id:
          type: string
          format: uuid
          title: Chunk Id
          description: Database chunk ID
        file_id:
          type: string
          format: uuid
          title: File Id
          description: File ID the chunk belongs to
        file_name:
          type: string
          title: File Name
          description: Original filename
        project_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Project Id
          description: Project ID
        content:
          type: string
          title: Content
          description: Chunk text content
        score:
          type: number
          title: Score
          description: Similarity score (0.0 to 1.0)
        chunk_index:
          type: integer
          title: Chunk Index
          description: Index of chunk within file
        page_number:
          anyOf:
            - type: integer
            - type: 'null'
          title: Page Number
          description: Page number if available
        start_page:
          anyOf:
            - type: integer
            - type: 'null'
          title: Start Page
          description: Starting page number
        end_page:
          anyOf:
            - type: integer
            - type: 'null'
          title: End Page
          description: Ending page number
        token_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Token Count
          description: Number of tokens in chunk
        mime_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Mime Type
          description: File MIME type
        category:
          anyOf:
            - type: string
            - type: 'null'
          title: Category
          description: File category
        tags:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Tags
          description: File tags
        document_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Document Type
          description: Document type
        reference_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Reference Id
          description: Client-provided file reference ID
        blob_storage_path:
          anyOf:
            - type: string
            - type: 'null'
          title: Blob Storage Path
          description: Full chunk JSON path in blob storage
        bounding_boxes:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Bounding Boxes
          description: >-
            Bounding boxes for chunk highlighting: {content_id: {page: [x1, y1,
            x3, y3]}}
      type: object
      required:
        - chunk_id
        - file_id
        - file_name
        - content
        - score
        - chunk_index
      title: SearchResultChunk
      description: Individual search result chunk.
    StructuredResult:
      properties:
        columns:
          items:
            $ref: '#/components/schemas/ColumnInfo'
          type: array
          title: Columns
          description: Column metadata for the result set
          default: []
        rows:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Rows
          description: Result rows as key-value objects
          default: []
      type: object
      title: StructuredResult
      description: Structured query results with schema metadata.
    ColumnInfo:
      properties:
        name:
          type: string
          title: Name
          description: Column name
        type:
          type: string
          title: Type
          description: Column data type (e.g., varchar, integer, timestamp)
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: Human-readable column description
      type: object
      required:
        - name
        - type
      title: ColumnInfo
      description: Column metadata for structured results.
  securitySchemes:
    MemicApiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        Memic API key. Every key is bound to exactly one environment — get one
        from the Memic dashboard under API Keys.

````