# Source: https://upstash.com/docs/search/sdks/ts/commands/search.md

# Source: https://upstash.com/docs/search/sdks/py/commands/search.md

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

# Search

## Search Command for Python SDK

The search method is designed to retrieve the most relevant documents from the database, using AI-powered search capabilities.

For more details on how the search algorithm works, please refer to our [advanced settings documentation](/search/features/advanced-settings).

### Arguments

<ResponseField name="Payload" type="dict" required>
  <Expandable defaultOpen="true">
    <ResponseField name="query" type="string" required>
      The search query string.
    </ResponseField>

    <ResponseField name="limit" type="int" required>
      The maximum number of results to return. Defaults to 10.
    </ResponseField>

    <ResponseField name="reranking" type="bool">
      Whether to enable AI-powered reranking of results. Disabled by default.
    </ResponseField>

    <ResponseField name="filter" type="string">
      A [filter](/search/features/filtering) for narrowing down the search results based on content fields.
    </ResponseField>

    <ResponseField name="semantic_weight" type="number">
      Optional relevance balance between semantic and keyword search (0-1 range, defaults to 0.75).
      For instance, 0.2 applies 20% semantic matching with 80% full-text matching.
      You can learn more about how Upstash Search works from [our docs](/search/features/algorithm).
    </ResponseField>

    <ResponseField name="input_enrichment" type="boolean">
      Optional boolean to enhance queries before searching (enabled by default).
    </ResponseField>
  </Expandable>
</ResponseField>

### Response

<ResponseField name="Documents" type="List[DocumentScore]" required>
  This field is `null` if no document with the specified ID is found.

  <Expandable defaultOpen="true">
    <ResponseField name="id" type="string | number" required>
      The ID of the resulting document.
    </ResponseField>

    <ResponseField name="content" type="Record<string, unknown>">
      The main content of the document.
    </ResponseField>

    <ResponseField name="metadata" type="Record<string, unknown>">
      Additional metadata for the document.
    </ResponseField>

    <ResponseField name="score" type="float" required>
      Similarity score of the document
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```python Basic Search theme={"system"}
  results = index.search(
      query="space opera",
      limit=2
  )
  print(results)
  ```

  ```python Search with Reranking theme={"system"}
  results = index.search(
      query="space opera",
      limit=2,
      reranking=True
  )
  print(results)
  ```

  ```python Search with Filter theme={"system"}
  results = index.search(
      query="space", 
      limit=2, 
      filter="category = 'classic'"
  )
  print(results)
  ```
</RequestExample>