Skip to content
Guide
Index V2 (Beta)

Getting Started with Index V2

Create a searchable index over your documents, from directory setup through retrieval, using the beta SDK.

Index V2 is a streamlined API for building searchable indexes over your documents. It works as a three-step model:

  1. Directory — Upload and organize your source documents.
  2. Index — Create an index over a directory. This triggers parsing, chunking, embedding, and vector store indexing automatically.
  3. Retrieve / Chat — Query your indexed documents via hybrid search or a built-in chat agent.
Terminal window
pip install llama-cloud
from llama_cloud import AsyncLlamaCloud
client = AsyncLlamaCloud(api_key="<your-api-key>")

A directory is a container for your source files. You can think of it as a folder that holds the documents you want to index.

directory = await client.beta.directories.create(
name="my-docs",
description="Product documentation",
)
print(directory.id) # e.g. "dir-abc123"

Upload files to LlamaCloud and then add them to your directory.

# Upload a file
with open("report.pdf", "rb") as f:
file_obj = await client.files.create(file=f, purpose="user_data")
# Add the file to the directory
await client.beta.directories.files.add(
directory.id,
file_id=file_obj.id,
)

Creating an index kicks off an automatic pipeline that parses, chunks, embeds, and indexes all files in the source directory.

index = await client.beta.indexes.create(
source_directory_id=directory.id,
)
print(f"Index ID: {index.id}")
print(f"Status: {index.metadata['status']}")

The index builds asynchronously. Poll until the status reaches ready.

import asyncio
while True:
idx = await client.beta.indexes.get(index.id)
status = idx.metadata["status"] if idx.metadata else "unknown"
if status == "ready":
print("Index is ready!")
break
elif status == "failed":
print("Index build failed:", idx.metadata["error_message"])
break
print(f"Status: {status} -- waiting...")
await asyncio.sleep(2)

Once the index is ready, you can run hybrid search queries against it.

results = await client.beta.retrieval.retrieve(
index_id=index.id,
query="What are the key findings?",
top_k=5,
)
for result in results.results:
print(f"Score: {result.score}")
print(result.content[:200])
print("---")
  • Retrieval guide — Hybrid search parameters, filtering, and reranking
  • File operations — Search, grep, and read files within an index
  • Chat — Built-in chat agent with RAG over your indexes
  • Syncing — Re-sync an index after adding or updating files