LlamaIndex

Stephen M. Walker II · Co-Founder / CEO

What is LlamaIndex?

LlamaIndex, formerly known as GPT Index, is a data framework that connects custom data sources to large language models (LLMs). It helps developers ingest, structure, and query private or domain-specific data, and is available in Python and TypeScript.

LlamaIndex caters to both novice and expert users with an intuitive high-level API for simple data ingestion and querying, alongside low-level APIs for more intricate operations. It supports customization and extension of any module, including data connectors, indices, retrievers, query engines, and reranking modules.

LLM pre-training on large public datasets gives models strong general language capabilities, but those models have no built-in access to private or domain-specific data. LlamaIndex addresses this gap with three core building blocks:

  • Data Connectors — Ingest data from sources such as APIs, PDFs, SQL databases, and other custom formats.
  • Data Indexing — Structure ingested data into intermediate representations optimized for fast, relevant retrieval by an LLM.
  • Query Interface — Offer a natural language interface for querying indexed data and returning relevant information to the LLM.

What functionality does LlamaIndex provide?

LlamaIndex acts as the interface between an LLM and external data: it builds an index from input data, then uses that index to answer questions about it. It supports several index types — vector, tree, list, and keyword — depending on the use case, and provides:

  • Data connectors — Ingest data from various sources and formats, such as APIs, PDFs, SQL databases, and more, via the Llama Hub.
  • Data indexes — Structure data into intermediate representations optimized for LLMs. Documents are split into "Node" objects, which are then organized into an index.
  • Query engines and chat interfaces — Support natural language querying and conversation over indexed data.
  • Composability — Build an index out of other indexes, enabling search or summarization across multiple heterogeneous data sources.
  • Document operations — Insert, delete, update, and refresh documents within an existing index.
  • Routing — Pick between different query engines based on the query.
  • Integrations — Connect with frameworks such as LangChain, web frameworks like Flask, deployment tooling like Docker, various vector stores, and OpenAI's function-calling API.

LlamaIndex is built around Retrieval Augmented Generation (RAG): an indexing stage, where private data is indexed (typically into a vector index), and a querying stage, where the index is searched to surface information that grounds the LLM's response.

What are the use cases for LlamaIndex?

LlamaIndex is foundational for Retrieval Augmented Generation (RAG) use cases: indices are built from documents and then used to power query engines and chat engines. It supports a wide range of applications, including:

  • Question and Answering (Q&A) over Documents — LlamaIndex can be used to answer questions about a set of documents. It supports many forms of Q&A, including semantic search (finding data that matches not just your query terms, but your intent and the meaning behind your question), and summarization (condensing a large amount of data into a short summary relevant to your current question).

  • Chatbots — LlamaIndex can be used to build chatbots that can interpret and respond to user queries by leveraging the indexed data.

  • Agents — LlamaIndex can be used to build intelligent agents that can interact with users and provide relevant responses based on the indexed data.

  • Knowledge Graphs — LlamaIndex can be used to build knowledge graphs that can provide structured and semantically rich responses to user queries.

  • Structured Data — LlamaIndex can be used to query structured data such as SQL databases, JSON files, and other structured formats.

  • Full-Stack Web Application — LlamaIndex can be used in the backend of a full-stack web application to provide data-driven responses to user queries.

  • Private Setup — LlamaIndex can be used to index and query private data, providing a way to leverage LLMs while maintaining data privacy.

  • Text Generation — LlamaIndex can be used for various text generation tasks such as generating stories, TODOs, emails, and more.

  • Building a Powerful Query Engine — LlamaIndex can be used to build and scale a powerful query engine that can handle complex queries over different data sources and scale indexing to thousands or millions of documents.

  • Building Personal Assistants — LlamaIndex can be used to build personal assistants like Siri that respond to your questions by interpreting your private data.

Workflow

The workflow of LlamaIndex can be broken down into two primary aspects: data processing and querying.

  • Data Processing: In the data processing phase, LlamaIndex partitions your knowledge base (for example, organizational documents) into chunks stored as ‘node’ objects. These nodes collectively form an ‘index’ or a graph.
  • Querying: During the querying stage, the RAG pipeline searches for the most relevant information based on the user's query. This information is then given to the LLM, along with the query, to create an accurate response.

How to get started with LlamaIndex

To use LlamaIndex, you import your documents, optionally break them down into nodes, build an index, optionally compose further indices on top of it, and then query the index. By default, LlamaIndex uses an OpenAI model for text generation and an OpenAI embedding model for retrieval unless you configure a different LLM or embedding model through its Settings object — check the official documentation for the current default model names, since OpenAI periodically deprecates and replaces models.

Installation

  1. Install LlamaIndex using pip. Open your terminal and type:
pip install llama-index

This command will install LlamaIndex and its dependencies.

  1. To use LlamaIndex's default OpenAI-backed models, you must have an OPENAI_API_KEY set up as an environment variable. You can obtain an API key by logging into your OpenAI account.

On MacOS, you can set the API key as an environment variable using the following command:

export OPENAI_API_KEY=your_api_key

Replace your_api_key with your actual OpenAI API key.

Getting Started

After installing LlamaIndex and setting up the OpenAI API key, you can start using it. Here's a simple example of how to load data and build an index:

  1. Create a new Python file, for example, starter.py.

  2. Add the following code to starter.py:

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)

This code will load the documents from the data directory and build an index over them.

Remember to replace data with the path to your actual data directory. The data directory should contain the text files you want to index.

With these steps, you should be able to install and get started with LlamaIndex. For more detailed information and advanced usage, refer to the official LlamaIndex documentation.

More terms

Continue exploring the glossary.

Learn how teams define, measure, and improve LLM systems.

Glossary term

What is multi-swarm optimization?

Multi-swarm optimization is a variant of particle swarm optimization (PSO), a computational method that optimizes a problem by iteratively improving a candidate solution. This method is inspired by the behavior of natural swarms, such as flocks of birds or schools of fish, where each individual follows simple rules that result in the collective behavior of the group.
Read term

Glossary term

Llama 2

Llama 2: The second iteration of Meta's open-source LLM, released in three publicly available sizes — 7B, 13B, and 70B parameters (a 34B variant was trained but not released).
Read term

It's time to build

Collaborate with your team on reliable Generative AI features.
Want expert guidance? Book a 1:1 onboarding session from your dashboard.

Talk to sales