Leverage Retrieval Augmented Generation to retrieve relevant information from a a LlamaCloud Index. Requires the llama_cloud_services package and LLAMA_CLOUD_API_KEY as an environment variable.
You can create an index on LlamaCloud using the following code. By default, new indexes use managed embeddings (OpenAI text-embedding-3-small, 1536 dimensions, 1 credit/page):
import os
from llama_index.core import SimpleDirectoryReader
from llama_cloud_services import LlamaCloudIndex
# create a new index (uses managed embeddings by default)
index = LlamaCloudIndex.from_documents(
documents,
"my_first_index",
project_name="default",
api_key="llx-...",
verbose=True,
)
# connect to an existing index
index = LlamaCloudIndex("my_first_index", project_name="default")
You can also configure a retriever for managed retrieval:
# from the existing index
index.as_retriever()
# from scratch
from llama_cloud_services import LlamaCloudRetriever
retriever = LlamaCloudRetriever("my_first_index", project_name="default")
# perform retrieval
result = retriever.retrieve("What is the capital of France?")
And of course, you can use other index shortcuts to get use out of your new managed index:
query_engine = index.as_query_engine(llm=llm)
# perform retrieval and generation
result = query_engine.query("What is the capital of France?")
A full list of retriever settings/kwargs is below:
dense_similarity_top_k: Optional[int] -- If greater than 0, retrieve k nodes using dense retrievalsparse_similarity_top_k: Optional[int] -- If greater than 0, retrieve k nodes using sparse retrievalenable_reranking: Optional[bool] -- Whether to enable reranking or not. Sacrifices some speed for accuracyrerank_top_n: Optional[int] -- The number of nodes to return after reranking initial retrieval resultsalpha Optional[float] -- The weighting between dense and sparse retrieval. 1 = Full dense retrieval, 0 = Full sparse retrieval.The llama_cloud_services and llama-index-core packages must be installed in your environment:
pip install llama-index-core llama_cloud_services
And the LLAMA_CLOUD_API_KEY must be available as an environment variable:
export LLAMA_CLOUD_API_KEY="..."
npx skills add run-llama/Retrieve relevant information through RAG下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer