> ## 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

The search method is designed to retrieve the most relevant documents from the database, using AI-powered search capabilities. This method supports a variety of options to configure the query to your needs.

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

<Note>
  The score returned from search requests is a normalized value between 0 and 1, where 1 indicates the highest relevance and 0 the lowest.
</Note>

## Arguments

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

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

    <ResponseField name="reranking" type="boolean">
      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.
      See [typesafe filtering section](/search/features/filtering#typesafe-filters-typescript) for advanced usage.
    </ResponseField>

    <ResponseField name="semanticWeight" 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="inputEnrichment" type="boolean">
      Optional boolean to enhance queries before searching (enabled by default).
    </ResponseField>

    <ResponseField name="keepOriginalQueryAfterEnrichment" type="boolean">
      Optional boolean to keep the original query alongside the enriched one (false by default).
    </ResponseField>
  </Expandable>
</ResponseField>

## Response

<ResponseField name="Response" type="SearchResult" required>
  <Expandable defaultOpen="true">
    <ResponseField name="results" type="Document[]">
      The list of documents matching the search query.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```typescript Basic Search theme={"system"}
  const searchResults = await index.search({
    query: "space opera",
    limit: 2,
  });
  console.log(searchResults);
  ```

  ```typescript Search with Reranking theme={"system"}
  const searchResults = await index.search({
    query: "space opera",
    limit: 2,
    reranking: true,
  });
  console.log(searchResults);
  ```

  ```typescript Search with Filter theme={"system"}
  const searchResults = await index.search({
    query: "space",
    limit: 2,
    filter: "category = 'classic'",
  });
  console.log(searchResults);
  ```
</RequestExample>
