この記事の要点
• LlamaIndex 0.11系でIngestion Pipelineが安定化、ETL処理の定型化が完了
• 100種類以上のDocumentLoader、30種類以上のVector Store統合
• PythonメインだがTypeScript版(LlamaIndex.TS)も成熟中
• Agentic RAGで検索・推論・ツール実行を統合したエージェント構築が可能
LlamaIndexとは何か
LlamaIndex(旧称GPT Index)は2022年11月にJerry Liu氏が開発を開始したPython製のLLMデータフレームワークで、RAG(Retrieval-Augmented Generation)パイプラインの構築に特化しています。ドキュメントの読み込み・チャンク分割・インデックス構築・検索・LLM統合までを一貫して扱え、特に社内文書検索・ナレッジベース・FAQボットなど「大量の文書に対する質問応答」に強みを持ちます。
2026年4月時点でバージョン0.11.8に到達し、月間ダウンロード数は380万回超(PyPI、2026年4月時点)を記録しています(公式ブログ、2026年3月)。RAG 2025で解説した通り、RAG実装のデファクトツールとしてLangChainと双璧をなしています。
LlamaIndex 2026のアーキテクチャ
1. コアコンポーネント
LlamaIndexは以下の主要モジュールで構成されます。
| コンポーネント | 役割 | 主要クラス |
|---|---|---|
| DocumentLoader | 文書の読み込み | SimpleDirectoryReader, PDFReader |
| NodeParser | チャンク分割 | SentenceSplitter, SemanticSplitter |
| VectorStore | ベクトルDB統合 | Pinecone, Weaviate, Chroma |
| Index | インデックス管理 | VectorStoreIndex, SummaryIndex |
| QueryEngine | 検索・質問応答 | RetrieverQueryEngine |
| ChatEngine | 会話型RAG | CondenseQuestionChatEngine |
ポイント: LlamaIndexの設計思想は「データ構造に応じた適切なインデックス選択」です。VectorStoreIndexは意味検索、SummaryIndexは全文要約、TreeIndexは階層的要約など、ユースケースごとに最適化されたインデックスが提供されています。
2. パッケージ構成の分離
LlamaIndex 0.10以降、LangChainと同様にモジュラー設計に移行しました。
# コアパッケージ(必須)
pip install llama-index-core
# LLMプロバイダー(個別インストール)
pip install llama-index-llms-anthropic
pip install llama-index-llms-openai
# ベクトルストア(必要なもののみ)
pip install llama-index-vector-stores-pinecone
pip install llama-index-vector-stores-qdrant
# 埋め込みモデル
pip install llama-index-embeddings-openai
# オールインワン(非推奨、依存肥大化)
pip install llama-index
この分離により、Docker イメージサイズが平均35%削減されました(公式ベンチマーク、2026年2月)。
基本的なRAGパイプラインの実装
シンプルなドキュメント検索
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.anthropic import Anthropic
from llama_index.embeddings.openai import OpenAIEmbedding
# 1. ドキュメント読み込み
documents = SimpleDirectoryReader("./data").load_data()
# 2. LLMと埋め込みモデル設定
llm = Anthropic(model="claude-4-sonnet-20260229", temperature=0)
embed_model = OpenAIEmbedding(model="text-embedding-3-large")
# 3. インデックス構築
index = VectorStoreIndex.from_documents(
documents,
llm=llm,
embed_model=embed_model
)
# 4. 検索・質問応答
query_engine = index.as_query_engine(similarity_top_k=3)
response = query_engine.query("LlamaIndexの特徴を教えて")
print(response)
わずか15行でエンドツーエンドのRAGシステムが完成します。LangChainと比較して、インデックス構築の抽象度が高く、初学者に優しい設計です。
Ingestion Pipelineによる前処理の定型化
LlamaIndex 0.11ではIngestion Pipelineが成熟し、ドキュメント読み込みから埋め込み生成までを宣言的に定義できます。
from llama_index.core import VectorStoreIndex
from llama_index.core.ingestion import IngestionPipeline
from llama_index.core.node_parser import SentenceSplitter
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.vector_stores.pinecone import PineconeVectorStore
import pinecone
# Pinecone初期化
pinecone.init(api_key="...", environment="us-west1-gcp")
index = pinecone.Index("company-docs")
vector_store = PineconeVectorStore(pinecone_index=index)
# パイプライン定義
pipeline = IngestionPipeline(
transformations=[
SentenceSplitter(chunk_size=512, chunk_overlap=50),
OpenAIEmbedding(model="text-embedding-3-large"),
],
vector_store=vector_store
)
# ドキュメント投入(自動でチャンク分割・埋め込み・保存)
documents = SimpleDirectoryReader("./docs").load_data()
pipeline.run(documents=documents)
# インデックスから検索
index = VectorStoreIndex.from_vector_store(vector_store)
query_engine = index.as_query_engine()
response = query_engine.query("2026年の売上計画は?")
実践メモ: Ingestion Pipelineは中間状態をキャッシュできるため、大量文書の再処理時に高速化されます。`pipeline.persist("./cache")`で永続化し、次回実行時に`IngestionPipeline.from_persist_dir("./cache")`で読み込むことで、処理時間が平均70%短縮されます。
高度なRAG手法の実装
1. ハイブリッド検索(ベクトル + キーワード)
ベクトル検索だけでは固有名詞・製品番号などの完全一致検索が弱いため、BM25キーワード検索と組み合わせます。
from llama_index.core import VectorStoreIndex
from llama_index.retrievers.bm25 import BM25Retriever
from llama_index.core.retrievers import VectorIndexRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.core.postprocessor import SimilarityPostprocessor
# ベクトル検索
vector_retriever = VectorIndexRetriever(
index=index,
similarity_top_k=10
)
# BM25キーワード検索
bm25_retriever = BM25Retriever.from_defaults(
nodes=index.docstore.docs.values(),
similarity_top_k=10
)
# 両者を統合(Reciprocal Rank Fusion)
from llama_index.core.retrievers import QueryFusionRetriever
fusion_retriever = QueryFusionRetriever(
[vector_retriever, bm25_retriever],
similarity_top_k=5,
num_queries=1,
mode="reciprocal_rerank"
)
# クエリエンジン構築
query_engine = RetrieverQueryEngine.from_args(
retriever=fusion_retriever,
node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.7)]
)
response = query_engine.query("製品番号XYZ-12345の仕様は?")
ハイブリッド検索により、検索精度(MRR)が単純なベクトル検索比で平均22%向上します(公式ベンチマーク、2026年1月)。
2. セマンティックチャンキング
従来の固定長チャンク分割ではなく、意味的なまとまりでチャンクを分割する手法です。
from llama_index.core.node_parser import SemanticSplitterNodeParser
# 埋め込みモデルで意味的境界を判定
splitter = SemanticSplitterNodeParser(
buffer_size=1, # 前後1文との意味的類似度を評価
breakpoint_percentile_threshold=95, # 類似度が低い箇所で分割
embed_model=OpenAIEmbedding()
)
nodes = splitter.get_nodes_from_documents(documents)
index = VectorStoreIndex(nodes)
この手法により、チャンク境界が不自然な位置で分割されるリスクが減少し、検索品質が向上します。
3. リランキングとコンテキスト圧縮
検索結果をLLMで再評価し、関連度の低いチャンクをフィルタリングします。
from llama_index.core.postprocessor import CohereRerank
# Cohereリランカー(多言語対応)
rerank = CohereRerank(
api_key="...",
model="rerank-multilingual-v3.0",
top_n=3
)
query_engine = index.as_query_engine(
similarity_top_k=10,
node_postprocessors=[rerank]
)
response = query_engine.query("LlamaIndexの最新機能は?")
リランキングにより、最終回答の精度(F1スコア)が平均18%向上します(LlamaIndex公式レポート)。
Agentic RAG - 検索とツール実行の統合
LlamaIndex 0.11ではAgentic RAGが正式機能として提供され、検索結果に基づいてツールを実行するエージェントが構築できます。
from llama_index.core.agent import ReActAgent
from llama_index.core.tools import QueryEngineTool, ToolMetadata
from llama_index.llms.anthropic import Anthropic
# 複数のインデックスをツール化
financial_tool = QueryEngineTool(
query_engine=financial_index.as_query_engine(),
metadata=ToolMetadata(
name="financial_search",
description="2020〜2026年の財務データを検索します"
)
)
technical_tool = QueryEngineTool(
query_engine=technical_index.as_query_engine(),
metadata=ToolMetadata(
name="technical_search",
description="技術仕様書・API ドキュメントを検索します"
)
)
# ReActエージェント構築
llm = Anthropic(model="claude-4-sonnet-20260229")
agent = ReActAgent.from_tools(
[financial_tool, technical_tool],
llm=llm,
verbose=True
)
# エージェントが自動で適切なツールを選択
response = agent.chat("2025年Q4の売上と、その期間にリリースされた製品を教えて")
print(response)
このパターンはAI Agents 2025で解説したツール駆動型エージェントの典型例です。
ベクトルデータベース統合
LlamaIndexは30種類以上のベクトルDBに対応しています。
| ベクトルDB | パッケージ | 主な用途 |
|---|---|---|
| Pinecone | llama-index-vector-stores-pinecone | 本番環境・マネージド |
| Weaviate | llama-index-vector-stores-weaviate | セルフホスト・GraphQL |
| Qdrant | llama-index-vector-stores-qdrant | ローカル開発 |
| Chroma | llama-index-vector-stores-chroma | 軽量・プロトタイプ |
| Supabase | llama-index-vector-stores-supabase | PostgreSQL拡張 |
| FAISS | llama-index-vector-stores-faiss | インメモリ |
Supabase VectorやVector DB 2026で詳述した通り、本番環境ではPinecone・Weaviate・Qdrantが主流です。
from llama_index.vector_stores.qdrant import QdrantVectorStore
import qdrant_client
# Qdrant接続
client = qdrant_client.QdrantClient(url="http://localhost:6333")
vector_store = QdrantVectorStore(
client=client,
collection_name="my_collection"
)
# インデックス構築
index = VectorStoreIndex.from_documents(
documents,
vector_store=vector_store
)
LangChainとの比較
LangChain 2026とLlamaIndexは補完関係にあります。
| 観点 | LlamaIndex | LangChain |
|---|---|---|
| 主要ユースケース | RAG・データインデックス | エージェント・汎用チェーン |
| データローダー種類 | 100種類以上 | 150種類以上 |
| インデックス抽象度 | 高(VectorStoreIndex等) | 低(Retriever) |
| エージェント機能 | Agentic RAG | LCEL + LangGraph |
| TypeScript対応 | 限定的 | 充実 |
| 学習曲線 | やや急(概念多い) | 緩やか |
| 本番実績 | RAG特化で豊富 | 広範囲に実績 |
実際には併用するケースも多く、LlamaIndexでインデックスを構築し、LangChainのRetrieverとして利用する統合が公式サポートされています。
from llama_index.core import VectorStoreIndex
from langchain.retrievers import LlamaIndexRetriever
from langchain.chains import RetrievalQA
from langchain_anthropic import ChatAnthropic
# LlamaIndexでインデックス構築
index = VectorStoreIndex.from_documents(documents)
# LangChainのRetrieverとして利用
retriever = LlamaIndexRetriever(index=index.as_retriever())
llm = ChatAnthropic(model="claude-4-sonnet-20260229")
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
retriever=retriever
)
result = qa_chain.invoke({"query": "..."})
会話型RAGの実装
ChatEngineによる履歴管理
from llama_index.core import VectorStoreIndex
from llama_index.core.memory import ChatMemoryBuffer
# メモリ付きチャットエンジン
memory = ChatMemoryBuffer.from_defaults(token_limit=3000)
chat_engine = index.as_chat_engine(
chat_mode="condense_question", # 質問を会話履歴で補完
memory=memory,
verbose=True
)
# 会話
response1 = chat_engine.chat("LlamaIndexとは?")
print(response1)
# 前の文脈を引き継ぐ
response2 = chat_engine.chat("具体的な使い方を教えて")
print(response2)
ポイント: `condense_question`モードでは、ユーザーの質問を会話履歴と統合して「スタンドアロンな質問」に変換してから検索を実行します。これにより「それ」「前述の」などの代名詞を含む質問でも正しく検索できます。
マルチモーダルRAG
LlamaIndex 0.11では画像・音声を含むマルチモーダルドキュメントのインデックス化が可能です。
from llama_index.core import VectorStoreIndex
from llama_index.multi_modal_llms.anthropic import AnthropicMultiModal
from llama_index.core.schema import ImageDocument
# 画像ドキュメント読み込み
image_documents = [
ImageDocument(image_path="./images/diagram1.png"),
ImageDocument(image_path="./images/chart2.png")
]
# マルチモーダルLLM
llm = AnthropicMultiModal(model="claude-4-opus-20260301")
# インデックス構築(画像の説明文を自動生成)
index = VectorStoreIndex.from_documents(
image_documents,
llm=llm
)
# 画像内容に対する質問
response = index.as_query_engine().query("売上グラフの2025年Q4の数値は?")
この機能はMultimodal AI 2025で解説したマルチモーダルLLMの実用化を背景としています。
TypeScript版の状況
LlamaIndex.TSは2026年時点でバージョン0.8.12に到達し、Python版の主要機能を60%カバーしています。
import { VectorStoreIndex, SimpleDirectoryReader } from "llamaindex";
// ドキュメント読み込み
const reader = new SimpleDirectoryReader();
const documents = await reader.loadData("./data");
// インデックス構築
const index = await VectorStoreIndex.fromDocuments(documents);
// 検索
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query("LlamaIndexの特徴は?");
console.log(response.toString());
ただし、Ingestion Pipeline・Agentic RAG・一部のベクトルDB統合など、Python版の最新機能は2〜3ヶ月遅れでリリースされる傾向があります。
注意: TypeScript版はメンテナーが少なく、Python版と比べてドキュメント・コミュニティサポートが限定的です。本番環境での採用は慎重に評価してください。
実用的なユースケース
ケース1: 社内文書検索システム
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores.pinecone import PineconeVectorStore
from llama_index.llms.anthropic import Anthropic
import pinecone
# Pinecone初期化
pinecone.init(api_key="...", environment="us-west1-gcp")
index_pinecone = pinecone.Index("company-knowledge")
vector_store = PineconeVectorStore(pinecone_index=index_pinecone)
# 複数フォーマットの文書を読み込み
documents = SimpleDirectoryReader(
"./company_docs",
file_extractor={
".pdf": "PDFReader",
".docx": "DocxReader",
".xlsx": "PandasExcelReader"
}
).load_data()
# インデックス構築(メタデータでフィルタリング可能)
for doc in documents:
doc.metadata["department"] = "engineering"
doc.metadata["year"] = 2026
index = VectorStoreIndex.from_documents(
documents,
vector_store=vector_store,
llm=Anthropic(model="claude-4-haiku-20260307")
)
# 部門フィルタ付き検索
query_engine = index.as_query_engine(
filters={"department": "engineering"}
)
response = query_engine.query("Kubernetes移行計画は?")
ケース2: 技術サポートチャットボット
from llama_index.core import VectorStoreIndex
from llama_index.core.tools import QueryEngineTool
from llama_index.core.agent import ReActAgent
# 複数のナレッジベースを構築
faq_index = VectorStoreIndex.from_documents(faq_docs)
api_index = VectorStoreIndex.from_documents(api_docs)
troubleshooting_index = VectorStoreIndex.from_documents(troubleshooting_docs)
# ツール化
faq_tool = QueryEngineTool.from_defaults(
query_engine=faq_index.as_query_engine(),
name="faq_search",
description="よくある質問とその回答を検索します"
)
api_tool = QueryEngineTool.from_defaults(
query_engine=api_index.as_query_engine(),
name="api_search",
description="API仕様・エンドポイント情報を検索します"
)
troubleshooting_tool = QueryEngineTool.from_defaults(
query_engine=troubleshooting_index.as_query_engine(),
name="troubleshooting_search",
description="エラー解決方法・トラブルシューティング手順を検索します"
)
# マルチツールエージェント
agent = ReActAgent.from_tools(
[faq_tool, api_tool, troubleshooting_tool],
llm=Anthropic(model="claude-4-sonnet-20260229"),
verbose=True
)
# 自動でツール選択して回答
response = agent.chat("APIエラー500が出た時の対処法は?")
実践メモ: 本番環境では、ユーザーフィードバック(「回答が役立った」ボタン)をログに記録し、定期的にインデックスを再構築・チューニングすることで、継続的な品質改善が可能です。
よくある質問
LlamaIndexはLangChainより優れていますか?
「優劣」ではなく「特化分野」の違いです。LlamaIndexはRAG・データインデックスに特化し、複雑なインデックス構築が簡潔に書けます。LangChainはエージェント・汎用チェーンに強く、幅広いユースケースに対応します。RAG中心のプロジェクトならLlamaIndex、多様な処理を統合するならLangChainが適しています。
本番環境での実績はありますか?
2026年時点でスタートアップから大企業まで幅広く採用されています。特に社内文書検索・カスタマーサポート・技術ドキュメント検索での実績が豊富です。ただしベクトルDBの選定・チャンクサイズのチューニング・リランキングの導入など、実用化には細かな調整が必要です。
初心者はLlamaIndexとLangChainのどちらを学ぶべきですか?
RAGに絞るならLlamaIndexの方が学習曲線が緩やかです。VectorStoreIndex.from_documents()だけで動くサンプルが多く、初期体験が良好です。一方、エージェント・ツール連携・ワークフロー制御も学びたい場合はLangChainの方が包括的です。最終的には両方を理解し、適材適所で使い分けることが理想です。
まとめ
LlamaIndex 2026はRAGパイプライン構築のデファクトツールとして成熟しています。以下のポイントを再確認します。
- Ingestion Pipelineで前処理の定型化、ETL処理が宣言的に記述可能
- ハイブリッド検索・セマンティックチャンキング・リランキングで高精度RAG実現
- Agentic RAGで検索とツール実行を統合したエージェント構築
- 30種類以上のベクトルDB統合、本番環境ではPinecone/Weaviate/Qdrantが主流
- LangChainと併用可能、役割分担で相乗効果
社内文書検索・ナレッジベース・技術サポートなど、大量文書に対する質問応答システムを構築する際は、LlamaIndexを第一候補として検討する価値があります。
参考リソース
- LlamaIndex公式ドキュメント - API リファレンスと実装例
- LlamaIndex GitHub - ソースコードとIssue管理
- LlamaIndex Community - Discord コミュニティ
- LlamaHub - データローダー・ツールのカタログ