llama_index README

The project's README from github.com/run-llama/llama_index. As one markdown file: README.md.

🗂️ LlamaIndex 🦙

PyPI - Downloads Build GitHub contributors Discord Twitter Reddit

LlamaIndex OSS (by LlamaIndex) is an open-source framework to build agentic applications. Parse is our enterprise platform for agentic OCR, parsing, extraction, indexing and more. You can use LlamaParse with this framework or on its own; see LlamaParse below for signup and product links.

📚 Documentation:

Building with LlamaIndex typically involves working with LlamaIndex core and a chosen set of integrations (or plugins). There are two ways to start building with LlamaIndex in Python:

  1. Starter: llama-index. A starter Python package that includes core LlamaIndex as well as a selection of integrations.

  2. Customized: llama-index-core. Install core LlamaIndex and add your chosen LlamaIndex integration packages on LlamaHub that are required for your application. There are over 300 LlamaIndex integration packages that work seamlessly with core, allowing you to build with your preferred LLM, embedding, and vector store providers.

The LlamaIndex Python library is namespaced such that import statements which include core imply that the core package is being used. In contrast, those statements without core imply that an integration package is being used.

# typical pattern
from llama_index.core.xxx import ClassABC  # core submodule xxx
from llama_index.xxx.yyy import (
    SubclassABC,
)  # integration yyy for submodule xxx

# concrete example
from llama_index.core.llms import LLM
from llama_index.llms.openai import OpenAI

LlamaParse (document agent platform)

LlamaParse is its own platform—focused on document agents and agentic OCR. It includes Parse (parsing), LlamaAgents (deployed document agents), Extract (structured extraction), and Index (ingest and RAG). You can use it with the LlamaIndex framework or standalone.

Documentation

X (formerly Twitter)

LinkedIn

Reddit

Discord

🚀 Overview

NOTE: This README is not updated as frequently as the documentation. Please check out the documentation above for the latest updates!

Context

We need a comprehensive toolkit to help perform this data augmentation for LLMs.

Proposed Solution

That's where LlamaIndex comes in. LlamaIndex is a "data framework" to help you build LLM apps. It provides the following tools:

LlamaIndex provides tools for both beginner users and advanced users. Our high-level API allows beginner users to use LlamaIndex to ingest and query their data in 5 lines of code. Our lower-level APIs allow advanced users to customize and extend any module (data connectors, indices, retrievers, query engines, reranking modules), to fit their needs.

💡 Contributing

Interested in contributing? Contributions to LlamaIndex core as well as contributing integrations that build on the core are both accepted and highly encouraged! See our Contribution Guide for more details.

New integrations should meaningfully integrate with existing LlamaIndex framework components. At the discretion of LlamaIndex maintainers, some integrations may be declined.

📄 Documentation

Full documentation can be found here

Please check it out for the most up-to-date tutorials, how-to guides, references, and other resources!

💻 Example Usage

# custom selection of integrations to work with core
pip install llama-index-core
pip install llama-index-llms-openai
pip install llama-index-llms-ollama
pip install llama-index-embeddings-huggingface

Examples are in the docs/examples folder. Indices are in the indices folder (see list of indices below).

To build a simple vector store index using OpenAI:

import os

os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

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

To build a simple vector store index using non-OpenAI LLMs, e.g. LLMs hosted through Ollama:

from llama_index.core import Settings, VectorStoreIndex, SimpleDirectoryReader
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.ollama import Ollama
from transformers import AutoTokenizer

# set the LLM
Settings.llm = Ollama(
    model="llama-3.1:latest",
    request_timeout=360.0,
)

# set tokenizer to match LLM
Settings.tokenizer = AutoTokenizer.from_pretrained(
    "meta-llama/Llama-3.1-8B-Instruct"
)

# set the embed model
Settings.embed_model = HuggingFaceEmbedding(
    model_name="BAAI/bge-small-en-v1.5"
)

documents = SimpleDirectoryReader("YOUR_DATA_DIRECTORY").load_data()
index = VectorStoreIndex.from_documents(
    documents,
)

To query:

query_engine = index.as_query_engine()
query_engine.query("YOUR_QUESTION")

By default, data is stored in-memory. To persist to disk (under ./storage):

index.storage_context.persist()

To reload from disk:

from llama_index.core import StorageContext, load_index_from_storage

# rebuild storage context
storage_context = StorageContext.from_defaults(persist_dir="./storage")
# load index
index = load_index_from_storage(storage_context)

A note on Verification of Build Assets

By default, llama-index-core includes a _static folder that contains the nltk and tiktoken cache that is included with the package installation. This ensures that you can easily run llama-index in environments with restrictive disk access permissions at runtime.

To verify that these files are safe and valid, we use the github attest-build-provenance action. This action will verify that the files in the _static folder are the same as the files in the llama-index-core/llama_index/core/_static folder.

To verify this, you can run the following script (pointing to your installed package):

#!/bin/bash
STATIC_DIR="venv/lib/python3.13/site-packages/llama_index/core/_static"
REPO="run-llama/llama_index"

find "$STATIC_DIR" -type f | while read -r file; do
    echo "Verifying: $file"
    gh attestation verify "$file" -R "$REPO" || echo "Failed to verify: $file"
done

📖 Citation

Reference to cite if you use LlamaIndex in a paper:

@software{Liu_LlamaIndex_2022,
author = {Liu, Jerry},
doi = {10.5281/zenodo.1234},
month = {11},
title = {{LlamaIndex}},
url = {https://github.com/jerryjliu/llama_index},
year = {2022}
}

llama_index (run-llama/llama_index)

Searching Database…

这是什么?LlamaIndex 是一个开源的 Python 框架,用于构建智能体(agentic)应用。它可以让大语言模型(LLM)结合你自己的私有数据工作,通过基于 LLM 的流水线来导入、索引和查询文档。
它是框架还是独立应用?它是一个数据框架和库,需要导入到 Python 代码中使用,并不是独立的应用程序。另外还有一个单独的商业平台 LlamaParse,用于智能体式的文档解析/OCR,可以配合该框架使用,也可以单独使用。
怎样把它添加到项目中?可以安装入门包 'llama-index',它包含核心功能以及一组精选的集成;也可以安装 'llama-index-core',再按需从 LlamaHub(目前有 300 多个)安装具体的集成包。
使用它需要 LLM 提供商的 API 密钥吗?你需要能够使用一个 LLM,可以通过 OpenAI 这类提供商的 API 密钥来使用,也可以通过 Ollama 之类的工具运行本地部署的模型。README 中对这两种方式都有示例。
这份 README 是最新的吗?维护者明确提醒 README 的内容可能滞后,如需最新信息,请查看完整的文档网站。
这是面向初学者还是高级开发者的?两者都适合:高层 API 让初学者用大约 5 行代码就能导入和查询数据,而底层 API 则允许高级用户自定义数据连接器、索引、检索器和查询引擎。
我的数据默认会留在本地,还是会被发送到其他地方?默认情况下,索引数据存储在你机器的内存中,也可以持久化保存到本地磁盘,除非你选择远程向量存储集成,否则不会涉及任何外部存储。
什么是 LlamaParse?LlamaParse 是 LlamaIndex 旗下独立的企业级平台,用于智能体式 OCR 和文档解析,支持 130 多种格式,还提供结构化提取、索引、切分以及构建文档智能体等功能。它可以配合 LlamaIndex 框架使用,也可以完全独立使用。
我能把 LlamaIndex 和其他应用框架集成吗?可以,它被设计为能够接入 LangChain、Flask、Docker 或基于 ChatGPT 的应用等外层应用框架。
LlamaIndex 支持多少种集成?LlamaHub 上有 300 多个集成包,涵盖不同的 LLM 提供商、嵌入模型和向量存储,它们都可以与核心包配合使用。
LlamaIndex 如何验证其软件包中附带的文件?它使用 GitHub 的 attest-build-provenance 操作,验证 static 文件夹中附带的 nltk/tiktoken 缓存文件与源代码仓库一致,并提供了一个脚本供你自行检查。
Creator
run-llama
Size
486.1 MB
Stars
52.6K
Age
3y
Commits · 90 Days