Skip to content
Guide
Index
Guides
Retrieval

Basic

Getting started with the LlamaCloud Retrieval API to fetch relevant text chunks for a query, with Python framework and SDK examples.

Data Retrieval is a key step in any RAG application. The most common use case is to retrieve relevant context from your data to help with a question.

Once data has been ingested into LlamaCloud, you can use the Retrieval API to retrieve relevant context from your data.

Our Retrieval API allows you to retrieve relevant ground truth text chunks that have been ingested into a Index for a given query. The following snippets show how to run this basic form of retrieval:

import os
os.environ[
"LLAMA_CLOUD_API_KEY"
] = "llx-..." # can provide API-key in env or in the constructor later on
from llama_cloud.lib.index import LlamaCloudIndex
# connect to existing index
index = LlamaCloudIndex("my_first_index", project_name="Default")
# configure retriever
# alpha=1.0 restricts it to vector search.
retriever = index.as_retriever(
dense_similarity_top_k=3,
alpha=1.0,
enable_reranking=False,
)
nodes = retriever.retrieve("Example query")

We can build upon this basic form of retrieval by including things like hybrid search, reranking, and metadata filtering to improve the accuracy of the retrieval. These advanced retrieval parameters are described in greater detail in the next section ➡️

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/python/shared/mcp/