Skip to content
Guide
Index

Syncing

Re-sync an index after adding, updating, or removing files in the source directory.

After you add, update, or remove files in a directory, you need to sync the index to reflect those changes. Syncing re-parses changed files and re-exports updated chunks to the vector store.

The initial sync is triggered automatically when you create an index. Use the sync endpoint for subsequent updates.

await client.indexes.sync("<your-index-id>")

The sync runs asynchronously. Poll the index to know when it completes — see Typical workflow below for a race-safe polling loop.

Request cancellation of a running index sync with POST /api/v1/indexes/{index_id}/sync/cancel:

  • 202 Accepted means the cancellation request was accepted, not that the sync has stopped.
  • 409 Conflict means there is no running sync to cancel.

Cancellation is asynchronous, so work can continue while the request takes effect. To check whether a sync is running, retrieve the individual index with expand=sync_in_progress. Treat sync_in_progress: null as unknown: the field was not requested or its state is unavailable.

  1. Upload new files or remove outdated files from the directory.
  2. Read the index’s current last_synced_at and status, then call the sync endpoint once.
  3. Poll the index until status is ready and last_synced_at has advanced past the value from step 2, or until status is failed after changing from its step 2 value. Resume retrieval or chat.

Download a one-page metrics report as new-report.pdf to add to the directory:

Terminal window
curl -fL -o new-report.pdf https://raw.githubusercontent.com/run-llama/llama-cloud-py/main/examples/extract/test-files/slide/saas_slide.pdf
import asyncio
import time
# Add a new file to the directory
with open("new-report.pdf", "rb") as f:
file_obj = await client.files.create(file=f, purpose="user_data")
await client.beta.directories.files.add(
directory_id,
file_id=file_obj.id,
)
# Note the state of the index before the sync. A freshly triggered sync keeps
# reporting the previous status until it starts, so we wait for "ready" with
# a newer last_synced_at, and trust "failed" only once the status has changed.
prev = await client.indexes.get(index_id)
before = prev.last_synced_at
before_status = prev.metadata["status"] if prev.metadata else "unknown"
# Trigger a sync once, since the endpoint is rate limited
await client.indexes.sync(index_id)
# Poll until this sync finishes, backing off between attempts and
# giving up after a deadline.
deadline = time.monotonic() + 600 # 10 minutes
delay = 2
started = False # True once the status differs from before the trigger
while True:
idx = await client.indexes.get(index_id)
status = idx.metadata["status"] if idx.metadata else "unknown"
started = started or status != before_status
if status == "ready" and idx.last_synced_at != before:
print("Sync complete!")
break
if status == "failed" and started:
print("Sync failed:", idx.metadata["error_message"])
break
if time.monotonic() >= deadline:
raise TimeoutError("Sync did not complete within 10 minutes")
await asyncio.sleep(delay)
delay = min(delay * 2, 30) # exponential backoff, capped at 30s
# Get an index by ID
idx = await client.indexes.get("<your-index-id>")
print(f"{idx.id}: status={idx.metadata['status']}")

Deleting an index removes the sync and export configuration. The source directory and its files are not affected.

await client.indexes.delete("<your-index-id>")
Note for AI agents: this documentation is built for programmatic access. - Overview of all docs: https://developers.llamaindex.ai/llms.txt - Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md - Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters. - A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/for-agents/mcp/ - Other LlamaIndex tooling for agents — the LlamaParse Platform MCP server, agent skills and plugins, and the n8n node — is mapped at https://developers.llamaindex.ai/for-agents/