Llama-Index Managed Llama Cloud Indices
This library provides integration for LlamaIndex to create, manage, and query indices hosted on Llama Cloud. It enables persistent, scalable, and production-ready Retrieval-Augmented Generation (RAG) solutions without needing to manage vector databases or other infrastructure directly. The current version is `0.11.1`, and it follows the frequent release cadence of the broader LlamaIndex ecosystem, often tied to Llama Cloud service updates.
Warnings
- gotcha The `LLAMA_CLOUD_API_KEY` environment variable or `api_key` parameter in `LlamaCloudIndex` initialization is mandatory for authentication with Llama Cloud. Forgetting to set it will result in authentication errors and prevent index operations.
- breaking The LlamaIndex ecosystem undergoes rapid development. Frequent updates in the core `llama-index` library can introduce API changes that might affect the `llama-index-indices-managed-llama-cloud` package. This can lead to breaking changes between minor versions.
- gotcha When creating or connecting to an index, the `name` parameter in `LlamaCloudIndex` must be unique within your Llama Cloud project. If you call `from_documents` or `from_index_name` with an existing name, it will connect to that index. If new documents are provided, they will be upserted into the existing index, which might not be the intended behavior if you expect a fresh index.
Install
-
pip install llama-index-indices-managed-llama-cloud
Imports
- LlamaCloudIndex
from llama_index.indices.managed.llama_cloud import LlamaCloudIndex
Quickstart
import os
from llama_index.indices.managed.llama_cloud import LlamaCloudIndex
from llama_index.core.schema import Document
# Set your Llama Cloud API key as an environment variable
# You can obtain one from app.llamacloud.ai
api_key = os.environ.get("LLAMA_CLOUD_API_KEY", "")
if not api_key:
print("Warning: LLAMA_CLOUD_API_KEY environment variable not set. The example will not fully function without it.")
# Define some documents to be indexed
documents = [
Document(text="The quick brown fox jumps over the lazy dog."),
Document(text="LlamaIndex helps build LLM applications with external data.")
]
# Create a new managed index or connect to an existing one by name.
# If the index 'my_managed_index_example' doesn't exist, it will be created.
# If it exists, the documents will be upserted.
print(f"Attempting to create/connect to Llama Cloud Index 'my_managed_index_example'...")
index = LlamaCloudIndex.from_documents(
documents,
name="my_managed_index_example", # Use a unique name for your index
api_key=api_key
)
print(f"Successfully connected to Llama Cloud Index: {index.index_name}")
# Query the index using a query engine
query_engine = index.as_query_engine()
query_text = "What does LlamaIndex help with?"
print(f"\nQuery: {query_text}")
response = query_engine.query(query_text)
print(f"Response: {response}")