> [!CAUTION]
> **Caution** : Document AI Warehouse is deprecated and will no longer be available on Google Cloud after January 16, 2025. To safeguard your data, migrate any documents currently saved in Document AI Warehouse to an alternative like Cloud Storage. Verify that your data migration is completed before the discontinuation date to prevent any data loss. See [Deprecations](https://docs.cloud.google.com/document-warehouse/docs/deprecations) for details.

<br />

> [!WARNING]
>
> **Preview**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

> [!NOTE]
> This feature is subject to the [Data Processing and Security
> Terms](https://cloud.google.com/terms/data-processing-terms) and the [GenAI Trusted Tester Terms of Service](https://cloud.google.com/trustedtester/aitos).

<br />

> [!NOTE]
> **Note:** Access to this feature is currently restricted. Fill out this [form](https://docs.google.com/forms/d/1WETvoadxz5PN47us4WPt1ag-3ain0OGku8bnf0JTErI/) to gain access.

## Before you start

To ingest sample documents into the Document AI Warehouse, see the [Quickstart Guide](https://docs.cloud.google.com/document-warehouse/docs/quickstart).

## GenAI search

GenAI search retrieves the top-k documents most relevant to the (keyword or natural-language) search query. It returns pinpointed answers from a body of customer-uploaded documents, sorting search results by relevance.

The search request caller decides the k by specifying it in the [qaSizeLimit](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/projects.locations.documents/search#request-body) field. Large language models determine the relevance between the search query and the documents.

What data gets searched?

- The document's [plain_text](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/Document).
- If you are importing a Document AI object, use the embedded [cloud_ai_document.text](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/Document#Document).

> [!NOTE]
> **Note:** The search query is limited to 64 words.

Filtering, pagination, histograming, custom synonyms, document level, fine-grained access control are not supported.

## Make a search request call

To call the search service, you must use a search request, which is defined as follows:

    {
      "documentQuery": {
        object (DocumentQuery)
      },
      "qaSizeLimit": integer
    }

The `parent` field must be filled in with the format:

```bash
/projects/PROJECT_ID/locations/LOCATION
```

The [qaSizeLimit](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/projects.locations.documents/search#request-body) field is required for GenAI search.

## Response to a search request

The search response is defined as follows:

    {
      "matchingDocuments": [
        {
          object (MatchingDocument)
        }
      ],
      "metadata": {
        object (ResponseMetadata)
      }
    }

> [!NOTE]
> **Note:** Full reference for [ResponseMetadata](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/ResponseMetadata).

## Document Query

The **document_query** field is defined as follows:

    {
      "query": string,
      "isNlQuery": boolean
    }

> [!NOTE]
> **Note:** Full reference for [DocumentQuery](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/projects.locations.documents/search#documentquery)

The **query** field is for the requesting user's search query words which can be either keywords or natural language questions. Typically, these come from the search field in the UI.
The **isNlQuery** field needs to be set as true for GenAI search.

## Matching document

A matching document looks like this:

    {
      "document": {
        object (Document)
      },
      "searchTextSnippet": string,
      "qaResult": {
        object (QAResult)
      }
    }

The **SearchTextSnippet** field contains a snippet that answers the user's natural-language query. No HTML bold tags will be present, and highlights in the answer snippet can be found in [QAResult.highlights](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/projects.locations.documents/search#highlight).
Note: Full reference for [Matching Document](https://cloud.google.com/document-warehouse/docs/reference/rest/v1/projects.locations.documents/search#matchingdocument).

## GenAI search result

This is GenAI search result information.

    {
      "highlights": {
        object(Highlight)
      }
      "confidence_score": float
    }

## Highlight

This is a text span in the search-text snippet that represents a highlighted section, such as answer context or a highly relevant sentence.

    {
      "start_index": integer
      "end_index": integer
    }

## Questions and answers from a set of documents

To generate an answer using GenAI, you must use a search request with `documentNameFilter`, which is defined as follows:

    {
      "documentQuery": {
        "query": "QUERY",
        "isNlQuery": "true",
        "documentNameFilter" : [
          "projects/PROJECT_NUMBER/locations/LOCATION/documents/DOCUMENT_ID_1",
          "projects/PROJECT_NUMBER/locations/LOCATION/documents/DOCUMENT_ID_2",
        ]
      },
      "qaSizeLimit": integer
    }

Avoid adding other filters to `documentQuery` because the other filters are not yet functional.

If an answer can be found within the given set of documents, the answer is stored in the `questionAnswer` field.

    {
      "document": {
        object (Document)
      },
      questionAnswer: "QUESTION_ANSWER",
    }

## Next steps

- Proceed to [GenAI quickstart guide](https://docs.cloud.google.com/document-warehouse/docs/genai-quickstart)
  to understand and run GenAI in Document AI Warehouse.

- Proceed to [GenAI search guide](https://docs.cloud.google.com/document-warehouse/docs/genai-search-guide)
  to learn how to manage searches on GenAI.