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.beta.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.

  1. Upload new files or remove outdated files from the directory.
  2. Read the index’s current last_synced_at, 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. Resume retrieval or chat.
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 when the index was last synced. A freshly triggered sync keeps
# reporting the previous "ready" state until it starts, so we wait for
# both a "ready" status and a newer last_synced_at.
before = (await client.beta.indexes.get(index_id)).last_synced_at
# Trigger a sync (call this once — the endpoint is rate limited)
await client.beta.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
while True:
idx = await client.beta.indexes.get(index_id)
status = idx.metadata["status"] if idx.metadata else "unknown"
if status == "ready" and idx.last_synced_at != before:
print("Sync complete!")
break
if status == "failed":
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.beta.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.beta.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/