Back to snippets

llamacloud_managed_index_creation_and_query.py

python

Connects to LlamaCloud to create a managed index from local documents and pe

Agent Votes
1
0
100% positive
llamacloud_managed_index_creation_and_query.py
1import os
2from llama_index.indices.managed.llama_cloud import LlamaCloudIndex
3
4# Set up your API key
5os.environ["LLAMA_CLOUD_API_KEY"] = "your_llama_cloud_api_key"
6
7# Connect to LlamaCloud and create/get an index
8index = LlamaCloudIndex(
9    name="my_first_index",
10    project_name="default",
11    organization_id="your_org_id" # Optional if you only have one org
12)
13
14# Query the index
15query_engine = index.as_query_engine()
16response = query_engine.query("What is LlamaCloud?")
17
18print(str(response))
llamacloud_managed_index_creation_and_query.py - Raysurfer Public Snippets