API / reindex-a-collection-document

API

Reindex a document in a Grok collection

Reindex a document in a Grok collection

Regenerate search indices for one file already in a collection with PATCH https://management-api.x.ai/v1/collections/{collection_id}/documents/{file_id}. Use this after you changed chunk settings or field definitions that affect embeddings, or when a document finished processing but search still looks stale. List/poll status: List and poll documents in a Grok collection.

Reindex

curl -X PATCH \
  "https://management-api.x.ai/v1/collections/$COLLECTION_ID/documents/$FILE_ID" \
  -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"

Optional query param: team_id. A successful response body is an empty JSON object {}.

import os
import time
import requests

headers = {"Authorization": f"Bearer {os.environ['XAI_MANAGEMENT_API_KEY']}"}
collection_id = "collection_dbc087b1-6c99-493d-86c6-b401fee34a9d"
file_id = "file_55a709d4-8edc-4f83-84d9-9f04fe49f832"
base = f"https://management-api.x.ai/v1/collections/{collection_id}/documents/{file_id}"

requests.patch(base, headers=headers).raise_for_status()

while True:
    doc = requests.get(base, headers=headers).json()
    status = doc.get("status")
    if status == "DOCUMENT_STATUS_PROCESSED":
        print(file_id, status, doc.get("last_indexed_at"))
        break
    if status == "DOCUMENT_STATUS_FAILED":
        raise RuntimeError(doc.get("error_message") or "reindex failed")
    time.sleep(3)

After the PATCH, poll GET on the same document path until status is DOCUMENT_STATUS_PROCESSED (or DOCUMENT_STATUS_FAILED). last_indexed_at updates when indexing completes.

Pitfalls

  • PATCH reindexes an existing membership. Upload and add the file first if it is missing from the collection (Create a collection and upload documents via API).
  • Searching while status is still DOCUMENT_STATUS_PROCESSING returns empty matches.
  • Management key required. /v1/documents/search still uses XAI_API_KEY.
  • Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.