Search managed ingestion data with the SearchDocuments API

The SearchDocuments API provides an entry point to search unstructured and video data imported with the managed ingestion pipeline. You can use it without the need to configure embedding field names, output field configurations, or handling underlying Agent Retrieval primitives such as Collections, Data Objects, and Indexes.

The SearchDocuments API takes a query and a data store, and returns text (for unstructured data) and offsets (for video data), a URI, and other location information. The SearchDocuments API also lets you filter by document IDs, custom metadata, and page or time ranges.

The following table shows the differences between Agent Retrieval APIs and the SearchDocuments API.

Feature Agent Retrieval APIs SearchDocuments API
Parent Read collectionName from the data store and pass it as parent Pass the data store itself as parent
Vector field name Know the vector field name (multimodal_embedding) Not needed; the service reads it off the collection
Task type Set task_type to RETRIEVAL_QUERY Not needed
Output fields Set output_fields or get no text back Snippets, page ranges, and source URIs come back by default
Hybrid search Wire hybrid search (semantic + text) yourself using BatchSearchDataObjects Hybrid search (semantic + text) runs automatically
Reranking Configure reranking manually One toggle: ranking_spec.reranking_spec.enabled
Filtering Filter on stored field names (category, google_unstructured_details.start_page) and convert video offsets to nanoseconds Filter on the paths a result carries (metadata.category, unstructured_details.page_range.start_page, video_details.start_offset in seconds)
Metadata List each metadata property in output_fields.data_fields Name properties in output_fields.metadata, or pass "*" for all of them

Prerequisites

Before you begin, do the following:

Everything from the ingestion guide's "Before you start" section applies. You need:

  • The following APIs enabled: vectorsearch.googleapis.com, aiplatform.googleapis.com

  • The vectorsearch.documents.search permission.

    • The vectorsearch.viewer role.
  • (Optional) The Discovery Engine API enabled if you plan to use reranking.

The following examples show how to call SearchDocuments to perform a basic text search on unstructured data.

curl

PROJECT=acme-prod
LOCATION=us-east4
DATA_STORE=acme-financials
AUTH="Authorization: Bearer $(gcloud auth print-access-token)"

curl -X POST -H "${AUTH}" -H "Content-Type: application/json" \
  "https://vectorsearch.googleapis.com/v1beta/projects/${PROJECT}/locations/${LOCATION}/dataStores/${DATA_STORE}/documents:search" \
  -d '{
    "text_query": {
      "text": "covenant capping leverage at 3x"
    },
    "top_k": 10
  }'

python

import google.auth
from google.auth.transport.requests import AuthorizedSession

PROJECT = "acme-prod"
LOCATION = "us-east4"
DATA_STORE = "acme-financials"

credentials, _ = google.auth.default(
    scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
session = AuthorizedSession(credentials)

response = session.post(
    PARENT + "/documents:search",
    json={
        "text_query": {
            "text": "covenant capping leverage at 3x"
        },
        "top_k": 10
    },
).json()

The following is a sample JSON response.

{
  "results": [
    {
      "document": {
        "name": "projects/acme-prod/locations/us-east4/dataStores/acme-financials/documents/d8a3f...",
        "content": {
          "gcsUri": "gs://my-bucket-1/my-file-1"
        }
      },
      "unstructuredDetails": {
        "contentSnippet": "The credit agreement includes a leverage covenant capping total debt to EBITDA at 3.0x...",
        "pageRange": {
          "startPage": 14,
          "endPage": 14
        }
      }
    }
  ]
}

Each result is a segment of a document, not a whole document (unless the document only has one segment). The document.name field tells you which document it came from and document.content.gcs_uri shares the associated Cloud Storage URI of the ingested document. Multiple results can point to the same document if several segments match.

Search a video data store

Searching video data is similar to searching unstructured data, except:

  • Each result has video_details in place of unstructured_details. A result is one video segment. Its start_offset and end_offset specify where it starts and ends in the source video. A video segment has no text, so there is no content_snippet.

  • Only semantic search runs. The query is matched against the segment embeddings: the frames, plus the audio when the data store has audio_mode: ENABLED. No keyword matching happens.

  • Reranking isn't available. A request with ranking_spec.reranking_spec.enabled: true fails with INVALID_ARGUMENT.

The following examples show how to search a video data store.

curl

DATA_STORE=acme-training-video
curl -X POST -H "${AUTH}" -H "Content-Type: application/json" \
  "https://vectorsearch.googleapis.com/v1beta/projects/${PROJECT}/locations/${LOCATION}/dataStores/${DATA_STORE}/documents:search" \
  -d '{
    "text_query": {
      "text": "otters swimming underwater"
    },
    "top_k": 2
  }'

python

VIDEO_PARENT = (
    "https://vectorsearch.googleapis.com/v1beta/projects/" + PROJECT
    + "/locations/" + LOCATION + "/dataStores/acme-training-video"
)
response = session.post(
    VIDEO_PARENT + "/documents:search",
    json={
        "text_query": {
            "text": "otters swimming underwater"
        },
        "top_k": 2,
    },
).json()

The following is a sample JSON response.

{
  "results": [
    {
      "document": {
        "name": "projects/acme-prod/locations/us-east4/dataStores/acme-training-video/documents/animals",
        "content": {
          "gcsUri": "gs://acme-media/training/animals.mp4"
        }
      },
      "videoDetails": {
        "startOffset": "60s",
        "endOffset": "70s"
      }
    },
    {
      "document": {
        "name": "projects/acme-prod/locations/us-east4/dataStores/acme-training-video/documents/animals",
        "content": {
          "gcsUri": "gs://acme-media/training/animals.mp4"
        }
      },
      "videoDetails": {
        "startOffset": "50s",
        "endOffset": "60s"
      }
    }
  ]
}

In the response, startOffset and endOffset are durations written as seconds with an s suffix, for example 60s. A fractional value has the form 57.210s. Segment durations match the data store's segment_duration, except the final segment of a video can be shorter.

The example shows that a query can match several segments of the same video. Search results often match neighboring segments of the same video, as in the example. To get one hit per scene instead of one per segment, group the results by document.name.

Jump to the moment a result describes

The start offset is relative to the start of the source file. Use the video_details.start_offset to jump to the start of a segment.

The following example demonstrates how to get the start and end offsets for each result.

for result in response.get("results", []):
    uri = result["document"]["content"]["gcsUri"]
    start_s = float(result["videoDetails"]["startOffset"].rstrip("s"))
    end_s = float(result["videoDetails"]["endOffset"].rstrip("s"))
    print(f"{uri}  {start_s:.0f}s - {end_s:.0f}s")

Return document metadata

By default, results carry no metadata. Set output_fields.metadata to the properties you want included with each result, named as declared in your schema, without the metadata prefix. Pass * to return every declared property.

The following examples show how to return document metadata.

curl

curl -X POST -H "${AUTH}" -H "Content-Type: application/json" \
  "https://vectorsearch.googleapis.com/v1beta/projects/${PROJECT}/locations/${LOCATION}/dataStores/${DATA_STORE}/documents:search" \
  -d '{
    "text_query": {
      "text": "covenant capping leverage at 3x"
    },
    "top_k": 10,
    "output_fields": {
      "metadata": ["category", "year", "issuer.country"]
    }
  }'

python

response = session.post(
    PARENT + "/documents:search",
    json={
        "text_query": {
            "text": "covenant capping leverage at 3x"
        },
        "top_k": 10,
        "output_fields": {
            "metadata": ["category", "year", "issuer.country"]
        },
    },
).json()

The following is a sample JSON response.

{
  "results": [
    {
      "document": {
        "name": "projects/acme-prod/locations/us-east4/dataStores/acme-financials/documents/q3-earnings",
        "content": {
          "gcsUri": "gs://acme-docs/reports/2025-q3-earnings.pdf"
        },
        "metadata": {
          "value": {
            "category": "earnings",
            "year": 2025,
            "issuer": {"country": "US"}
          }
        }
      },
      "unstructuredDetails": {
        "contentSnippet": "The credit agreement includes a leverage covenant capping total debt to EBITDA at 3.0x...",
        "pageRange": {
          "startPage": 14,
          "endPage": 14
        }
      }
    }
  ]
}

The response keeps the same structure as the metadata schema (nested properties are returned in the same nested structure). If a property has no value, it isn't returned. The metadata property isn't included if the document has none of the requested properties.

Filter by metadata, page range, or time range

Pass filter to search only the segments that match your filter criteria.

The following examples show how to filter results.

curl

curl -X POST -H "${AUTH}" -H "Content-Type: application/json" \
  "https://vectorsearch.googleapis.com/v1beta/projects/${PROJECT}/locations/${LOCATION}/dataStores/${DATA_STORE}/documents:search" \
  -d '{
    "text_query": {
      "text": "covenant capping leverage at 3x"
    },
    "top_k": 10,
    "filter": {
      "$and": [
        {"metadata.category": {"$eq": "earnings"}},
        {"metadata.year": {"$gte": 2024}},
        {"unstructured_details.page_range.start_page": {"$lte": 20}}
      ]
    }
  }'

python

response = session.post(
    PARENT + "/documents:search",
    json={
        "text_query": {
            "text": "covenant capping leverage at 3x"
        },
        "top_k": 10,
        "filter": {
            "$and": [
                {"metadata.category": {"$eq": "earnings"}},
                {"metadata.year": {"$gte": 2024}},
                {"unstructured_details.page_range.start_page": {"$lte": 20}},
            ]
        },
    },
).json()
Path Data store document_type Notes
metadata.<property> Any Must be declared in the data store's document_metadata_schema. Name a nested property by its dotted path, such as metadata.issuer.country.
unstructured_details.page_range.start_page / end_page UNSTRUCTURED Page ranges depend on the file type. PDF, PowerPoint, and Excel results always carry a page range. For HTML, plain-text, Markdown, JSON, XML, and Word files, page ranges are set only when the data store uses page_segmentation_config with digital parsing.
video_details.start_offset / end_offset VIDEO In seconds. Fractions are allowed.

Comparison operators are $eq, $ne, $lt, $lte, $gt, $gte, $in, $nin, $all and $exists. Combine conditions with $and, $or and $not, nested up to two logical operators deep (for example, an $or inside an $and).

Each object holds one field or one operator as the following example shows:

{"metadata.year": {"$eq": 2025}}

Leaving out the $eq operator will fail (such as {"metadata.year": 2025}).

The following example demonstrates how to filter on an array property.

{"metadata.tags": {"$in": ["credit", "debt"]}}

This matches a document carrying either credit or debt. If the $all operator were used instead, both properties would be required for a match to be made.

Be aware of the following:

  • Page ranges need page segmentation. Page ranges depend on the file type. PDF, PowerPoint, and Excel results always carry a page range. For HTML, plain-text, Markdown, JSON, XML, and Word files, page ranges are set only when the data store uses page_segmentation_config with digital parsing; otherwise a page-range filter matches none of those files and no error is returned.

  • Matches can be made on missing properties: $ne and $not also match documents that don't have the property. Add {"metadata.<property>": {"$exists": true}} to exclude them.

  • $in and $nin require strings. A numeric $in or $nin returns INVALID_ARGUMENT with a generic message. For numbers, use a range or an $or of $eq conditions.

Filter by time range and metadata

You can filter on video_details.start_offset and video_details.end_offset, which are in seconds (fractions are allowed) and on any metadata.<property> your data store declares. Filters on page range paths are rejected for a video data store.

The following examples show how to filter on video metadata and time ranges.

curl

curl -X POST -H "${AUTH}" -H "Content-Type: application/json" \
  "https://vectorsearch.googleapis.com/v1beta/projects/${PROJECT}/locations/${LOCATION}/dataStores/${DATA_STORE}/documents:search" \
  -d '{
    "text_query": {
      "text": "smartphone camera features"
    },
    "top_k": 3,
    "filter": {
      "$and": [
        {"metadata.category": {"$eq": "product"}},
        {"video_details.start_offset": {"$gte": 10}},
        {"video_details.end_offset": {"$lte": 60}}
      ]
    },
    "output_fields": {
      "metadata": ["category", "year"]
    }
  }'

python

response = session.post(
    VIDEO_PARENT + "/documents:search",
    json={
        "text_query": {
            "text": "smartphone camera features"
        },
        "top_k": 3,
        "filter": {
            "$and": [
                {"metadata.category": {"$eq": "product"}},
                {"video_details.start_offset": {"$gte": 10}},
                {"video_details.end_offset": {"$lte": 60}},
            ]
        },
        "output_fields": {
            "metadata": ["category", "year"]
        },
    },
).json()

This returns segments that begin no earlier than 0:10 and end by 1:00, in videos whose category is product. Each result carries category and year:

{
  "results": [
    {
      "document": {
        "name": "projects/acme-prod/locations/us-east4/dataStores/acme-training-video/documents/pixel8",
        "content": {
          "gcsUri": "gs://acme-media/training/pixel8.mp4"
        },
        "metadata": {
          "value": {
            "category": "product",
            "year": 2023
          }
        }
      },
      "videoDetails": {
        "startOffset": "30s",
        "endOffset": "40s"
      }
    },
    {
      "document": {
        "name": "projects/acme-prod/locations/us-east4/dataStores/acme-training-video/documents/pixel8",
        "content": {
          "gcsUri": "gs://acme-media/training/pixel8.mp4"
        },
        "metadata": {
          "value": {
            "category": "product",
            "year": 2023
          }
        }
      },
      "videoDetails": {
        "startOffset": "10s",
        "endOffset": "20s"
      }
    }
  ]
}

Restrict to specific documents

Pass document_ids to search only within specific documents. This is useful when you already know which documents are relevant and want to narrow the search.

curl

curl -X POST -H "${AUTH}" -H "Content-Type: application/json" \
  "https://vectorsearch.googleapis.com/v1beta/projects/${PROJECT}/locations/${LOCATION}/dataStores/${DATA_STORE}/documents:search" \
  -d '{
    "text_query": {
      "text": "dividend payout ratio"
    },
    "top_k": 5,
    "document_ids": [
      "d8a3f1b2c4e5f6a7b8c9d0e1f2a3b4c5",
      "da1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d"
    ]
  }'

python

response = session.post(
    PARENT + "/documents:search",
    json={
        "text_query": {
            "text": "dividend payout ratio"
        },
        "top_k": 5,
        "document_ids": [
            "d8a3f1b2c4e5f6a7b8c9d0e1f2a3b4c5",
            "da1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d",
        ],
    },
).json()

You can pass up to 100 document IDs. You can list them from the data store, as shown in the following example.

curl

curl -H "${AUTH}" "${INGEST}/dataStores/acme-financials/documents"

Python

docs = session.get(INGEST + "/dataStores/acme-financials/documents").json()
print(len(docs.get("documents", [])))

Enable reranking

By default, results are returned in RRF-fused order (semantic and text search scores combined). Enable reranking to run a second pass with the Vertex ranking model (semantic-ranker-fast@latest), which improves relevance at the cost of some added latency. Reranking is available only for UNSTRUCTURED data stores; on a VIDEO data store the request fails with INVALID_ARGUMENT.

curl

curl -X POST -H "${AUTH}" -H "Content-Type: application/json" \
  "https://vectorsearch.googleapis.com/v1beta/projects/${PROJECT}/locations/${LOCATION}/dataStores/${DATA_STORE}/documents:search" \
  -d '{
    "text_query": {
      "text": "risk factors related to supply chain"
    },
    "top_k": 10,
    "ranking_spec": {
      "reranking_spec": {
        "enabled": true
      }
    }
  }'

python

response = session.post(
    PARENT + "/documents:search",
    json={
        "text_query": {
            "text": "risk factors related to supply chain"
        },
        "top_k": 10,
        "ranking_spec": {
            "reranking_spec": {
                "enabled": True
            }
        },
    },
).json()

When reranking is enabled, the service retrieves min(rank_oversampling_factor * top_k, 200) candidates before reranking, then trims to the specified top_k. The default oversampling factor is 5, so if top_k is 10, 50 candidates would be retrieved from each search type, reranked, and the top 10 are returned.

Add rank_oversampling_factor to ranking_spec to explicitly control oversampling, as shown in the following example.

"ranking_spec": {
  "reranking_spec": {
    "enabled": true,
    "rank_oversampling_factor": 3
  }
}

Set rank_oversampling_factor to 1 to rerank only the initial result set without oversampling.