Docs Menu
Docs Home
/
Atlas
/ /

LlamaIndex統合の使用を開始する

Atlas ベクトル検索 を LlamaIndex と統合すると、 LMアプリケーションに検索拡張生成 (RAG)(RAG)を実装できます。このチュートリアルでは、 LlamaIndex と Atlas ベクトル検索を使用してデータのセマンティック検索を実行し、RAG実装を構築する方法を説明します。具体的には、次のアクションを実行します。

  1. 環境を設定します。

  2. カスタム データを Atlas に保存します。

  3. データに Atlas Vector Search インデックスを作成します。

  4. 次のベクトル検索クエリを実行します。

    • セマンティック検索。

    • メタデータの事前フィルタリングによるセマンティック検索。

  5. Atlas Vector Search を使用してデータの質問に答え、 RAGを実装します。

このチュートリアルの実行可能なバージョンを Python エディタとして作業します。

LLMは、カスタム データソースを LM に接続する方法を簡素化するために設計されたオープンソース フレームワークです。 データ コネクター、インデックス、クエリ エンジンなどのいくつかのツールを提供し、 RAGアプリケーションのベクトル埋め込みをロードして準備するのに役立ちます。

RAGAtlas Vector Searchと統合することで、 をベクトルデータベースとして使用し、 を使用してセマンティックで類似したドキュメントを検索してAtlas RG を実装することができます。Atlas Vector SearchRGRAG Atlas Vector Searchの詳細については、「 を使用した 検索拡張生成(RAG ) 」を してください。

Atlas の サンプル データ セット からの映画データを含むコレクションを使用します。

このチュートリアルの環境を設定します。 .ipynb 拡張子を持つファイルを保存して、インタラクティブPythonノートを作成します。 このノートはPythonコード スニペットを個別に実行でき、このチュートリアルのコードを実行するために使用します。

ノートク環境を設定するには、次の手順に従います。

1

次のコマンドを実行します:

pip install --quiet --upgrade llama-index llama-index-vector-stores-mongodb llama-index-llms-openai llama-index-embeddings-voyageai pymongo

次に、次のコードを実行して必要なパッケージをインポートします。

import os, pymongo, pprint
from pymongo.operations import SearchIndexModel
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, StorageContext
from llama_index.core.settings import Settings
from llama_index.core.retrievers import VectorIndexRetriever
from llama_index.core.vector_stores import MetadataFilter, MetadataFilters, ExactMatchFilter, FilterOperator
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.embeddings.voyageai import VoyageEmbedding
from llama_index.llms.openai import OpenAI
from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch
2

次のコードを実行し、プレースホルダーを次の値に置き換えます。

  • OpenAI API キー。

  • あなたの 投票AI APIキー

  • Atlas クラスターのSRV接続文字列。

os.environ["OPENAI_API_KEY"] = "<openai-api-key>"
os.environ["VOYAGEAI_API_KEY"] = "<voyageai-api-key>"
ATLAS_CONNECTION_STRING = "<connection-string>"

注意

接続stringには、次の形式を使用する必要があります。

mongodb+srv://<db_username>:<db_password>@<clusterName>.<hostname>.mongodb.net
3

次のコードを実行して、LlamaIndex に固有の設定を構成します。 これらの設定では、次の項目を指定します。

  • voyage-3-large アプリケーションがデータからベクトル埋め込みを生成するために使用する埋め込みモデルとして、 。

  • OpenAI は、データに対する質問に答えるためにアプリケーションによって使用される LM として、 となります。

  • チャンク サイズとオーバーラップ を使用して、ストレージ用にデータを分割する方法をカスタマイズします。

from llama_index.embeddings.voyageai import VoyageEmbedding
embed_model= VoyageEmbedding(
voyage_api_key = os.environ["VOYAGEAI_API_KEY"],
model_name = "voyage-3-large",
)
Settings.llm = OpenAI()
Settings.embed_model = embed_model
Settings.chunk_size = 100
Settings.chunk_overlap = 10

次に、カスタム データを Atlas にロードし、Atlas をベクトルデータベースとしてインスタンス化します。これは ベクトルストア とも呼ばれますが、 。次のコード スニペットをコピーして、ノートに貼り付けます。

1

このチュートリアルでは、ベクトルストアのデータソースとして、最新のMongoDB収益レポートを含む一般にアクセス可能な PDFドキュメントを使用します。このドキュメントでは、MongoDB の会計年度 4 四半期および 1 年間の MongoDB の財務結果を説明します。2025

サンプル データをロードするには、次のコード スニペットを実行します。 この処理では、次の処理が行われます。

  • dataという新しいディレクトリを作成します。

  • 指定された URL から PDF を検索し、 ディレクトリに ファイルとして保存します。

  • データ コネクタ を使用しますSimpleDirectoryReader ファイルから未加工のテキストとメタデータを抽出します。また、データをドキュメントにフォーマットします。

# Load the sample data
from urllib.request import urlretrieve
urlretrieve("https://investors.mongodb.com/node/13176/pdf", "mongodb-earnings-report.pdf")
sample_data = SimpleDirectoryReader(input_files=["mongodb-earnings-report.pdf"]).load_data()
# Print the first document
sample_data[0]
Document(id_='62b7cace-30c0-4687-9d87-e178547ae357', embedding=None,
metadata={'page_label': '1', 'file_name': 'mongodb-earnings-report.pdf',
'file_path': 'data/mongodb-earnings-report.pdf', 'file_type':
'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28',
'last_modified_date': '2025-05-28'},
excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size',
'creation_date', 'last_modified_date', 'last_accessed_date'],
excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size',
'creation_date', 'last_modified_date', 'last_accessed_date'],
relationships={}, metadata_template='{key}: {value}', metadata_separator='\n',
text_resource=MediaResource(embeddings=None, data=None, text='MongoDB, Inc.
Announces Fourth Quarter and Full Year Fiscal 2025 Financial Results\nMarch 5,
2025\nFourth Quarter Fiscal 2025 Total Revenue of $548.4 million, up 20%
Year-over-Year\nFull Year Fiscal 2025 Total Revenue of $2.01 billion, up 19%
Year-over-Year\nContinued Strong Customer Growth with Over 54,500 Customers as
of January 31, 2025\nMongoDB Atlas Revenue up 24% Year-over-Year; 71% of Total
Q4 Revenue\nNEW YORK , March 5, 2025 /PRNewswire/ -- MongoDB, Inc. (NASDAQ:
MDB) today announced its financial results for the fourth quarter and
fiscal\nyear ended January 31, 2025.\n\xa0\n \xa0\n"MongoDB delivered a
strong end to fiscal 2025 with 24% Atlas revenue growth and significant margin
expansion. Atlas consumption in the quarter\nwas better than expected and we
continue to see good performance in new workload wins due to the flexibility,
scalability and performance of the\nMongoDB platform. In fiscal year 2026 we
expect to see stable consumption growth in Atlas, our main growth driver,"
said Dev Ittycheria, President\nand Chief Executive Officer of MongoDB
.\n"Looking ahead, we remain incredibly excited about our long-term growth
opportunity. MongoDB removes the constraints of legacy databases,\nenabling
businesses to innovate at AI speed with our flexible document model and
seamless scalability. Following the Voyage AI acquisition, we\ncombine
real-time data, sophisticated embedding and retrieval models and semantic
search directly in the database, simplifying the development of\ntrustworthy
AI-powered apps."\nFourth Quarter Fiscal 2025 Financial Highlights\nRevenue:
Total revenue was $548.4 million for the fourth quarter of fiscal 2025, an
increase of 20% year-over-year.\nSubscription revenue was $531.0 million, an
increase of 19% year-over-year, and services revenue was $17.4 million,
an\nincrease of 34% year-over-year.\nGross Profit: Gross profit was $399.4
million for the fourth quarter of fiscal 2025, representing a 73% gross
margin\ncompared to 75% in the year-ago period. Non-GAAP gross profit was
$411.7 million, representing a 75% non-GAAP gross\nmargin, compared to a
non-GAAP gross margin of 77% in the year-ago period.\nLoss from Operations:
Loss from operations was $18.6 million for the fourth quarter of fiscal 2025,
compared to a loss\nfrom operations of $71.0 million in the year-ago period.
Non-GAAP income from operations was $112.5 million, compared\nto non-GAAP
income from operations of $69.2 million in the year-ago period.\nNet Income
(Loss): Net income was $15.8 million, or $0.20 per share, based on 77.6
million weighted-average shares\noutstanding, for the fourth quarter of fiscal
2025. This compares to a net loss of $55.5 million, or $0.77 per share, in
the\nyear-ago period. Non-GAAP net income was $108.4 million, or $1.28 per
share, based on 84.6 million fully diluted\nweighted-average shares
outstanding. This compares to a non-GAAP net income of $71.1 million, or $0.86
per share, in\nthe year-ago period.\nCash Flow: As of January 31, 2025,
MongoDB had $2.3 billion in cash, cash equivalents, short-term investments
and\nrestricted cash. During the three months ended January 31, 2025, MongoDB
generated $50.5 million of cash from\noperations, compared to $54.6 million of
cash from operations in the year-ago period. MongoDB used $26.0 million of
cash\nin capital expenditures and used $1.6 million of cash in principal
payments of finance leases, leading to free cash flow of\n$22.9 million,
compared to free cash flow of $50.5 million in the year-ago period.\nFull Year
Fiscal 2025 Financial Highlights\nRevenue: Total revenue was $2.01 billion for
the full year fiscal 2025, an increase of 19% year-over-year.
Subscription\nrevenue was $1.94 billion, an increase of 19% year-over-year,
and services revenue was $62.6 million, an increase of
12%\nyear-over-year.\nGross Profit: Gross profit was $1.47 billion for the
full year fiscal 2025, representing a 73% gross margin compared to',
path=None, url=None, mimetype=None), image_resource=None, audio_resource=None,
video_resource=None, text_template='{metadata_str}\n\n{content}')
2

次のコードを実行し、 MongoDBAtlasVectorSearchメソッドを使用してatlas_vector_storeという名前のベクトル ストアを作成します。これは以下を指定します。

  • Atlas クラスターへの接続。

  • llamaindex_db.test ドキュメントを保存するために使用される Atlas データベースとコレクション 。

  • vector_index ベクトル ストアをクエリするために使用するインデックスとして 。

次に、ベクトル ストアを ストレージ コンテキスト に保存します これは、ストレージのデータを準備するために使用される LlamaIndex コンテナ オブジェクトです。

# Connect to your Atlas cluster
mongo_client = pymongo.MongoClient(ATLAS_CONNECTION_STRING)
# Instantiate the vector store
atlas_vector_store = MongoDBAtlasVectorSearch(
mongo_client,
db_name = "llamaindex_db",
collection_name = "test",
vector_index_name = "vector_index"
)
vector_store_context = StorageContext.from_defaults(vector_store=atlas_vector_store)
3

データをロードし、Atlas をベクトル ストアとしてインスタンス化したら、データからベクトル埋め込みを生成し、Atlas に保存します。 それには ベクトル ストア インデックス を構築する必要があります 。このタイプのインデックスは、データを分割、埋め込み、ベクトル ストアに保存する LlamaIndex データ構造です。

次のコードでは、 VectorStoreIndex.from_documentsメソッドを使用して、サンプル データにベクトル ストア インデックスを構築します。 サンプル データをベクトル埋め込みに変換し、これらの埋め込みをドキュメントとして Atlas クラスターのllamaindex_db.testコレクションにドキュメントとして保存します(ベクトル ストアのストレージ コンテキストで指定されます)。

注意

このメソッドでは、環境を設定するときに構成した埋め込みモデルとチャンクの設定を使用します。

vector_store_index = VectorStoreIndex.from_documents(
sample_data, storage_context=vector_store_context, show_progress=True
)

Tip

サンプル コードを実行した後、クラスター内のlangchain_db.testコレクションに移動すると、Atlas UI でベクトル埋め込みを表示できます。

注意

Atlas Vector Search インデックスを作成するには、Atlas プロジェクトに対するProject Data Access Admin以上のアクセス権が必要です。

ベクトル ストアでベクトル検索クエリを有効にするには、 llamaindex_db.testコレクションに Atlas Vector Search インデックスを作成します。

エディタで次のコードを実行して、以下のフィールドをインデックスする vectorSearch タイプのインデックスを作成します。

  • embedding ベクトル型としてのフィールド。 embeddingフィールドには、VyageAI のvoyage-3-large 埋め込みモデルを使用して作成された埋め込みが含まれます。インデックス定義では、1024 ベクトル次元を指定し、cosine を使用して類似性を測定します。

  • metadata.page_label PDF 内のページ番号でデータを事前にフィルタリングするためのフィルタータイプとしての フィールド。

# Specify the collection for which to create the index
collection = mongo_client["llamaindex_db"]["test"]
# Create your index model, then create the search index
search_index_model = SearchIndexModel(
definition={
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 1024,
"similarity": "cosine"
},
{
"type": "filter",
"path": "metadata.page_label"
}
]
},
name="vector_index",
type="vectorSearch"
)
collection.create_search_index(model=search_index_model)

インデックスの構築には約 1 分かかります。 構築中、インデックスは最初の同期状態になります。 構築が完了したら、コレクション内のデータのクエリを開始できます。

Atlas の サンプル データ セット からの映画データを含むコレクションを使用します。

  • Atlas アカウントで、MongoDB バージョン 6.0.11 または7.0.2 以降(RCs を含む)のクラスターを実行している。IP アドレスが Atlas プロジェクトのアクセスリストに含まれていることを確認してください。詳細については、クラスターの作成を参照してください。

  • OpenAI API キー。API リクエストに使用できるクレジットを持つ OpenAI アカウントが必要です。OpenAI アカウントの登録について詳しく知りたい場合は、 OpenAI API ウェブサイトをご覧ください。

  • Comb などのインタラクティブ Python ノートを実行するための環境。

このチュートリアルの環境を設定します。 .ipynb 拡張機能のファイルを保存して、インタラクティブPythonノートを作成します。 このノートはPythonコード スニペットを個別に実行でき、このチュートリアルのコードを実行するために使用します。

ノートク環境を設定するには、次の手順に従います。

1

次のコマンドを実行します:

pip install --quiet --upgrade llama-index llama-index-vector-stores-mongodb llama-index-embeddings-openai pymongo

次に、次のコードを実行して必要なパッケージをインポートします。

import os, pymongo, pprint
from pymongo.operations import SearchIndexModel
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, StorageContext
from llama_index.core.settings import Settings
from llama_index.core.retrievers import VectorIndexRetriever
from llama_index.core.vector_stores import MetadataFilter, MetadataFilters, ExactMatchFilter, FilterOperator
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch
2

次のコードを実行し、プレースホルダーを次の値に置き換えます。

os.environ["OPENAI_API_KEY"] = "<api-key>"
ATLAS_CONNECTION_STRING = "<connection-string>"

注意

接続stringには、次の形式を使用する必要があります。

mongodb+srv://<db_username>:<db_password>@<clusterName>.<hostname>.mongodb.net
3

次のコードを実行して、LlamaIndex に固有の設定を構成します。 これらの設定では、次の項目を指定します。

  • OpenAI は、データに対する質問に答えるためにアプリケーションによって使用される LM として、 となります。

  • text-embedding-ada-002 アプリケーションがデータからベクトル埋め込みを生成するために使用する埋め込みモデルとして、 。

  • チャンク サイズとオーバーラップ を使用して、ストレージ用にデータを分割する方法をカスタマイズします。

Settings.llm = OpenAI()
Settings.embed_model = OpenAIEmbedding(model="text-embedding-ada-002")
Settings.chunk_size = 100
Settings.chunk_overlap = 10

次に、カスタム データを Atlas にロードし、Atlas をベクトルデータベースとしてインスタンス化します。これは ベクトルストア とも呼ばれますが、 。次のコード スニペットをコピーして、ノートに貼り付けます。

1

このチュートリアルでは、ベクトルストアのデータソースとして、最新のMongoDB収益レポートを含む一般にアクセス可能な PDFドキュメントを使用します。このドキュメントでは、MongoDB の会計年度 4 四半期および 1 年間の MongoDB の財務結果を説明します。2025

サンプル データをロードするには、次のコード スニペットを実行します。 この処理では、次の処理が行われます。

  • dataという新しいディレクトリを作成します。

  • 指定された URL から PDF を検索し、 ディレクトリに ファイルとして保存します。

  • データ コネクタ を使用しますSimpleDirectoryReader ファイルから未加工のテキストとメタデータを抽出します。また、データをドキュメントにフォーマットします。

# Load the sample data
from urllib.request import urlretrieve
urlretrieve("https://investors.mongodb.com/node/13176/pdf", "mongodb-earnings-report.pdf")
sample_data = SimpleDirectoryReader(input_files=["./data/mongodb-earnings-report.pdf"]).load_data()
# Print the first document
sample_data[0]
Document(id_='62b7cace-30c0-4687-9d87-e178547ae357', embedding=None,
metadata={'page_label': '1', 'file_name': 'mongodb-earnings-report.pdf',
'file_path': 'data/mongodb-earnings-report.pdf', 'file_type':
'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28',
'last_modified_date': '2025-05-28'},
excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size',
'creation_date', 'last_modified_date', 'last_accessed_date'],
excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size',
'creation_date', 'last_modified_date', 'last_accessed_date'],
relationships={}, metadata_template='{key}: {value}', metadata_separator='\n',
text_resource=MediaResource(embeddings=None, data=None, text='MongoDB, Inc.
Announces Fourth Quarter and Full Year Fiscal 2025 Financial Results\nMarch 5,
2025\nFourth Quarter Fiscal 2025 Total Revenue of $548.4 million, up 20%
Year-over-Year\nFull Year Fiscal 2025 Total Revenue of $2.01 billion, up 19%
Year-over-Year\nContinued Strong Customer Growth with Over 54,500 Customers as
of January 31, 2025\nMongoDB Atlas Revenue up 24% Year-over-Year; 71% of Total
Q4 Revenue\nNEW YORK , March 5, 2025 /PRNewswire/ -- MongoDB, Inc. (NASDAQ:
MDB) today announced its financial results for the fourth quarter and
fiscal\nyear ended January 31, 2025.\n\xa0\n \xa0\n"MongoDB delivered a
strong end to fiscal 2025 with 24% Atlas revenue growth and significant margin
expansion. Atlas consumption in the quarter\nwas better than expected and we
continue to see good performance in new workload wins due to the flexibility,
scalability and performance of the\nMongoDB platform. In fiscal year 2026 we
expect to see stable consumption growth in Atlas, our main growth driver,"
said Dev Ittycheria, President\nand Chief Executive Officer of MongoDB
.\n"Looking ahead, we remain incredibly excited about our long-term growth
opportunity. MongoDB removes the constraints of legacy databases,\nenabling
businesses to innovate at AI speed with our flexible document model and
seamless scalability. Following the Voyage AI acquisition, we\ncombine
real-time data, sophisticated embedding and retrieval models and semantic
search directly in the database, simplifying the development of\ntrustworthy
AI-powered apps."\nFourth Quarter Fiscal 2025 Financial Highlights\nRevenue:
Total revenue was $548.4 million for the fourth quarter of fiscal 2025, an
increase of 20% year-over-year.\nSubscription revenue was $531.0 million, an
increase of 19% year-over-year, and services revenue was $17.4 million,
an\nincrease of 34% year-over-year.\nGross Profit: Gross profit was $399.4
million for the fourth quarter of fiscal 2025, representing a 73% gross
margin\ncompared to 75% in the year-ago period. Non-GAAP gross profit was
$411.7 million, representing a 75% non-GAAP gross\nmargin, compared to a
non-GAAP gross margin of 77% in the year-ago period.\nLoss from Operations:
Loss from operations was $18.6 million for the fourth quarter of fiscal 2025,
compared to a loss\nfrom operations of $71.0 million in the year-ago period.
Non-GAAP income from operations was $112.5 million, compared\nto non-GAAP
income from operations of $69.2 million in the year-ago period.\nNet Income
(Loss): Net income was $15.8 million, or $0.20 per share, based on 77.6
million weighted-average shares\noutstanding, for the fourth quarter of fiscal
2025. This compares to a net loss of $55.5 million, or $0.77 per share, in
the\nyear-ago period. Non-GAAP net income was $108.4 million, or $1.28 per
share, based on 84.6 million fully diluted\nweighted-average shares
outstanding. This compares to a non-GAAP net income of $71.1 million, or $0.86
per share, in\nthe year-ago period.\nCash Flow: As of January 31, 2025,
MongoDB had $2.3 billion in cash, cash equivalents, short-term investments
and\nrestricted cash. During the three months ended January 31, 2025, MongoDB
generated $50.5 million of cash from\noperations, compared to $54.6 million of
cash from operations in the year-ago period. MongoDB used $26.0 million of
cash\nin capital expenditures and used $1.6 million of cash in principal
payments of finance leases, leading to free cash flow of\n$22.9 million,
compared to free cash flow of $50.5 million in the year-ago period.\nFull Year
Fiscal 2025 Financial Highlights\nRevenue: Total revenue was $2.01 billion for
the full year fiscal 2025, an increase of 19% year-over-year.
Subscription\nrevenue was $1.94 billion, an increase of 19% year-over-year,
and services revenue was $62.6 million, an increase of
12%\nyear-over-year.\nGross Profit: Gross profit was $1.47 billion for the
full year fiscal 2025, representing a 73% gross margin compared to',
path=None, url=None, mimetype=None), image_resource=None, audio_resource=None,
video_resource=None, text_template='{metadata_str}\n\n{content}')
2

次のコードを実行し、 MongoDBAtlasVectorSearchメソッドを使用してatlas_vector_storeという名前のベクトル ストアを作成します。これは以下を指定します。

  • Atlas クラスターへの接続。

  • llamaindex_db.test ドキュメントを保存するために使用される Atlas データベースとコレクション 。

  • vector_index ベクトル ストアをクエリするために使用するインデックスとして 。

次に、ベクトル ストアを ストレージ コンテキスト に保存します これは、ストレージのデータを準備するために使用される LlamaIndex コンテナ オブジェクトです。

# Connect to your Atlas cluster
mongo_client = pymongo.MongoClient(ATLAS_CONNECTION_STRING)
# Instantiate the vector store
atlas_vector_store = MongoDBAtlasVectorSearch(
mongo_client,
db_name = "llamaindex_db",
collection_name = "test",
vector_index_name = "vector_index"
)
vector_store_context = StorageContext.from_defaults(vector_store=atlas_vector_store)
3

データをロードし、Atlas をベクトル ストアとしてインスタンス化したら、データからベクトル埋め込みを生成し、Atlas に保存します。 それには ベクトル ストア インデックス を構築する必要があります 。このタイプのインデックスは、データを分割、埋め込み、ベクトル ストアに保存する LlamaIndex データ構造です。

次のコードでは、 VectorStoreIndex.from_documentsメソッドを使用して、サンプル データにベクトル ストア インデックスを構築します。 サンプル データをベクトル埋め込みに変換し、これらの埋め込みをドキュメントとして Atlas クラスターのllamaindex_db.testコレクションにドキュメントとして保存します(ベクトル ストアのストレージ コンテキストで指定されます)。

注意

このメソッドでは、環境を設定するときに構成した埋め込みモデルとチャンクの設定を使用します。

vector_store_index = VectorStoreIndex.from_documents(
sample_data, storage_context=vector_store_context, show_progress=True
)

Tip

サンプル コードを実行した後、クラスター内のlangchain_db.testコレクションに移動すると、Atlas UI でベクトル埋め込みを表示できます。

注意

Atlas Vector Search インデックスを作成するには、Atlas プロジェクトに対するProject Data Access Admin以上のアクセス権が必要です。

ベクトル ストアでベクトル検索クエリを有効にするには、 llamaindex_db.testコレクションに Atlas Vector Search インデックスを作成します。

エディタで次のコードを実行して、以下のフィールドをインデックスする vectorSearch タイプのインデックスを作成します。

  • embedding ベクトル型としての フィールド。 embeddingフィールドには、OpenAI のtext-embedding-ada-002埋め込みモデルを使用して作成された埋め込みが含まれます。 インデックス定義では、 1536ベクトル次元を指定し、 cosineを使用して類似性を測定します。

  • metadata.page_label PDF 内のページ番号でデータを事前にフィルタリングするためのフィルタータイプとしての フィールド。

# Specify the collection for which to create the index
collection = mongo_client["llamaindex_db"]["test"]
# Create your index model, then create the search index
search_index_model = SearchIndexModel(
definition={
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 1536,
"similarity": "cosine"
},
{
"type": "filter",
"path": "metadata.page_label"
}
]
},
name="vector_index",
type="vectorSearch"
)
collection.create_search_index(model=search_index_model)

インデックスの構築には約 1 分かかります。 構築中、インデックスは最初の同期状態になります。 構築が完了したら、コレクション内のデータのクエリを開始できます。

Atlas がインデックスを構築したら、ノート PC に戻り、データに対してベクトル検索クエリを実行します。 次の例は、ベクトル化されたデータに対して実行できるさまざまなクエリを示しています。

この例では、 string MongoDB Atlas security の基本的なセマンティック検索を実行し、関連性スコアで順位付けされたドキュメントのリストを返します。 また、次の項目も指定します。

  • 取得 者としての Atlas Vector Search セマンティック検索を実行します。

  • 最も関連性の高いドキュメントを 3 つのドキュメントのみを返すには、 similarity_top_kパラメーターを使用します。

retriever = vector_store_index.as_retriever(similarity_top_k=3)
nodes = retriever.retrieve("MongoDB acquisition")
for node in nodes:
print(node)
Node ID: 479446ef-8a32-410d-a5e0-8650bd10d78d
Text: MongoDB completed the redemption of 2026 Convertible Notes,
eliminating all debt from the balance sheet. Additionally, in
conjunction with the acquisition of Voyage, MongoDB is announcing a
stock buyback program of $200 million, to offset the dilutive impact
of the acquisition consideration.
Score: 0.914
Node ID: 453137d9-8902-4fae-8d81-5f5d9b0836eb
Text: "Looking ahead, we remain incredibly excited about our long-term
growth opportunity. MongoDB removes the constraints of legacy
databases, enabling businesses to innovate at AI speed with our
flexible document model and seamless scalability. Following the Voyage
AI acquisition, we combine real-time data, sophisticated embedding and
retrieval mod...
Score: 0.914
Node ID: f3c35db6-43e5-4da7-a297-d9b009b9d300
Text: Lombard Odier, a Swiss private bank, partnered with MongoDB to
migrate and modernize its legacy banking technology systems on MongoDB
with generative AI. The initiative enabled the bank to migrate code
50-60 times quicker and move applications from a legacy relational
database to MongoDB 20 times faster than previous migrations.
Score: 0.912

コレクション内の別の値とインデックス付きフィールドを比較する MQL 一致式を使用して、データを事前にフィルタリングできます。フィルタリングするメタデータフィールドはすべて、filter タイプとしてインデックスを作成する必要があります。詳細については、「ベクトル検索のフィールドにインデックスを付ける方法」を参照してください。

注意

このチュートリアルのインデックスを作成したときに、metadata.page_labelフィールドをフィルターとして指定しました。

この例では、string MongoDB Atlas securityのセマンティック検索を実行し、関連性スコアで順位付けされたドキュメントのリストを返します。 また、次の項目も指定します。

  • 取得 者としての Atlas Vector Search セマンティック検索を実行します。

  • 最も関連性の高いドキュメントを 3 つのドキュメントのみを返すには、 similarity_top_kパラメーターを使用します。

  • Atlas ベクトル検索 がmetadata.page_labelフィールドのフィルターにより、ページ 2 にのみ表示されるドキュメントが検索されます。

# Specify metadata filters
metadata_filters = MetadataFilters(
filters=[ExactMatchFilter(key="metadata.page_label", value="2")]
)
retriever = vector_store_index.as_retriever(similarity_top_k=3, filters=metadata_filters)
nodes = retriever.retrieve("MongoDB acquisition")
for node in nodes:
print(node)
Node ID: 479446ef-8a32-410d-a5e0-8650bd10d78d
Text: MongoDB completed the redemption of 2026 Convertible Notes,
eliminating all debt from the balance sheet. Additionally, in
conjunction with the acquisition of Voyage, MongoDB is announcing a
stock buyback program of $200 million, to offset the dilutive impact
of the acquisition consideration.
Score: 0.914
Node ID: f3c35db6-43e5-4da7-a297-d9b009b9d300
Text: Lombard Odier, a Swiss private bank, partnered with MongoDB to
migrate and modernize its legacy banking technology systems on MongoDB
with generative AI. The initiative enabled the bank to migrate code
50-60 times quicker and move applications from a legacy relational
database to MongoDB 20 times faster than previous migrations.
Score: 0.912
Node ID: 82a2a0c0-80b9-4a9e-a848-529b4ff8f301
Text: Fourth Quarter Fiscal 2025 and Recent Business Highlights
MongoDB acquired Voyage AI, a pioneer in state-of-the-art embedding
and reranking models that power next-generation AI applications.
Integrating Voyage AI's technology with MongoDB will enable
organizations to easily build trustworthy, AI-powered applications by
offering highly accurate...
Score: 0.911

このセクションでは、RAG Atlas Vector Searchと を使用してアプリケーションに RG を実装する方法を説明します。ベクトル検索クエリを実行してセマンティックに類似したドキュメントを検索する方法を学習したので、次のコードを実行して Atlas Vector Search を使用してドキュメントと LlamaIndex クエリ エンジン を検索します 、それらのドキュメントに基づいて質問に答えます。

この例では、次の処理を行います。

  • Atlas Vector Search を ベクトル インデックス レプリカ としてインスタンス化 、ベクトル ストアの特定のタイプの検索。これには5 similarity_top_kパラメーターが含まれているため、Atlas Vector Search は最も関連性の高いドキュメントのみを検索します。

  • データに関する質問に答えるために、 RetrieverQueryEngineクエリ エンジンをインスタンス化します。 プロンプトが表示されると、クエリ エンジンは次のアクションを実行します。

    • Atlas Vector Search を検索ドライバーとして、 プロンプトに基づいてセマンティック類似ドキュメントを検索します。

    • 環境を設定するときに指定した LM を呼び出し、検索されたドキュメントに基づいてコンテキストを認識する応答を生成します。

  • Atlas のセキュリティ推奨事項に関するサンプルクエリを使用して LM をプロンプトします。

  • LLMの応答とコンテキストとして使用されたドキュメントを返します。 生成される応答は異なる場合があります。

# Instantiate Atlas Vector Search as a retriever
vector_store_retriever = VectorIndexRetriever(index=vector_store_index, similarity_top_k=5)
# Pass the retriever into the query engine
query_engine = RetrieverQueryEngine(retriever=vector_store_retriever)
# Prompt the LLM
response = query_engine.query("What was MongoDB's latest acquisition?")
print(response)
print("\nSource documents: ")
pprint.pprint(response.source_nodes)
MongoDB's latest acquisition was Voyage AI, a pioneer in embedding and reranking models for next-generation AI applications.
Source documents:
[NodeWithScore(node=TextNode(id_='82a2a0c0-80b9-4a9e-a848-529b4ff8f301', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='8cfe6680-8dec-486e-92c5-89ac1733b6c8', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='b6c412af868c29d67a6b030f266cd0e680f4a578a34c209c1818ff9a366c9d44'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='479446ef-8a32-410d-a5e0-8650bd10d78d', node_type='1', metadata={}, hash='b805543bf0ef0efc25492098daa9bd9c037043fb7228fb0c3270de235e668341')}, metadata_template='{key}: {value}', metadata_separator='\n', text="Fourth Quarter Fiscal 2025 and Recent Business Highlights\nMongoDB acquired Voyage AI, a pioneer in state-of-the-art embedding and reranking models that power next-generation\nAI applications. Integrating Voyage AI's technology with MongoDB will enable organizations to easily build trustworthy,\nAI-powered applications by offering highly accurate and relevant information retrieval deeply integrated with operational\ndata.", mimetype='text/plain', start_char_idx=1678, end_char_idx=2101, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.9279670119285583),
NodeWithScore(node=TextNode(id_='453137d9-8902-4fae-8d81-5f5d9b0836eb', embedding=None, metadata={'page_label': '1', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='62b7cace-30c0-4687-9d87-e178547ae357', node_type='4', metadata={'page_label': '1', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='cb1dbd172c17e53682296ccc966ebdbb5605acb4fbf3872286e3a202c1d3650d'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='b6ae7c13-5bec-47f5-887f-835fc7bae374', node_type='1', metadata={'page_label': '1', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='a4835102686cdf03d1106946237d50031d00a0861eea892e38b928dd5e44e295'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='3d4034d3-bac5-4985-8926-9213f8a87318', node_type='1', metadata={}, hash='f103b351f2bda28ec3d2f1bb4f40d93ac1698ea5f7630a5297688a4caa419389')}, metadata_template='{key}: {value}', metadata_separator='\n', text='"Looking ahead, we remain incredibly excited about our long-term growth opportunity. MongoDB removes the constraints of legacy databases,\nenabling businesses to innovate at AI speed with our flexible document model and seamless scalability. Following the Voyage AI acquisition, we\ncombine real-time data, sophisticated embedding and retrieval models and semantic search directly in the database, simplifying the development of\ntrustworthy AI-powered apps."', mimetype='text/plain', start_char_idx=1062, end_char_idx=1519, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.921961784362793),
NodeWithScore(node=TextNode(id_='85dd431c-2d4c-4336-ab39-e87a97b30c59', embedding=None, metadata={'page_label': '4', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='311532cc-f526-4fc3-adb6-49e76afdd580', node_type='4', metadata={'page_label': '4', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='37f0ad7fcb7f204226ea7c6c475360e2db55bb77447f1742a164efb9c1da5dc0'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='6175bcb6-9e2a-4196-85f7-0585bcbbdd3b', node_type='1', metadata={}, hash='0e92e55a50f8b6dbfe7bcaedb0ccc42345a185048efcd440e3ee1935875e7cbf')}, metadata_template='{key}: {value}', metadata_separator='\n', text="Headquartered in New York, MongoDB's mission is to empower innovators to create, transform, and disrupt industries with software and data.\nMongoDB's unified, intelligent data platform was built to power the next generation of applications, and MongoDB is the most widely available, globally\ndistributed database on the market.", mimetype='text/plain', start_char_idx=0, end_char_idx=327, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.9217028021812439),
NodeWithScore(node=TextNode(id_='f3c35db6-43e5-4da7-a297-d9b009b9d300', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='3008736c-29f0-4b41-ac0f-efdb469319b9', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='cd3647350e6d7fcd89e2303fe1995b8f91b633c5f33e14b3b4c18a16738ea86f'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='c9bef874-77ee-40bc-a1fe-ca42d1477cb3', node_type='1', metadata={}, hash='c7d7af8a1b43b587a9c47b27f57e7cb8bc35bd90390a078db21e3f5253ee7cc1')}, metadata_template='{key}: {value}', metadata_separator='\n', text='Lombard Odier, a Swiss private bank, partnered with MongoDB to migrate and modernize its legacy banking technology\nsystems on MongoDB with generative AI. The initiative enabled the bank to migrate code 50-60 times quicker and move\napplications from a legacy relational database to MongoDB 20 times faster than previous migrations.', mimetype='text/plain', start_char_idx=2618, end_char_idx=2951, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.9197831153869629),
NodeWithScore(node=TextNode(id_='479446ef-8a32-410d-a5e0-8650bd10d78d', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='82a2a0c0-80b9-4a9e-a848-529b4ff8f301', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='688872b911c388c239669970f562d4014aaec4753903e75f4bdfcf1eb1daf5ab'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='3008736c-29f0-4b41-ac0f-efdb469319b9', node_type='1', metadata={}, hash='a854a9bf103e429ce78b45603df9e2341e5d0692aa95e544e6c82616be29b28e')}, metadata_template='{key}: {value}', metadata_separator='\n', text='MongoDB completed the redemption of 2026 Convertible Notes, eliminating all debt from the balance sheet. Additionally, in\nconjunction with the acquisition of Voyage, MongoDB is announcing a stock buyback program of $200 million, to offset the\ndilutive impact of the acquisition consideration.', mimetype='text/plain', start_char_idx=2102, end_char_idx=2396, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.9183852672576904)]

この例では、次の処理を行います。

  • Atlas ベクトル検索 が2 ページに表示されるドキュメントのみを検索するように、metadata.page_labelフィールドにメタデータフィルターを定義します。

  • Atlas ベクトル検索 をベクトルインデックスレプリカ (ベクトルストアの特定のタイプの検索ツール)としてインスタンス化します。定義したメタデータフィルターとsimilarity_top_k パラメーターが含まれているため、Atlas ベクトル検索5 はページ 2 から最も関連性の高いドキュメントのみを検索します。

  • データに関する質問に答えるために、 RetrieverQueryEngineクエリ エンジンをインスタンス化します。 プロンプトが表示されると、クエリ エンジンは次のアクションを実行します。

    • Atlas Vector Search を検索ドライバーとして、 プロンプトに基づいてセマンティック類似ドキュメントを検索します。

    • 環境を設定するときに指定した LM を呼び出し、検索されたドキュメントに基づいてコンテキストを認識する応答を生成します。

  • Atlas のセキュリティ推奨事項に関するサンプルクエリを使用して LM をプロンプトします。

  • LLMの応答とコンテキストとして使用されたドキュメントを返します。 生成される応答は異なる場合があります。

# Specify metadata filters
metadata_filters = MetadataFilters(
filters=[ExactMatchFilter(key="metadata.page_label", value="2")]
)
# Instantiate Atlas Vector Search as a retriever
vector_store_retriever = VectorIndexRetriever(index=vector_store_index, filters=metadata_filters, similarity_top_k=5)
# Pass the retriever into the query engine
query_engine = RetrieverQueryEngine(retriever=vector_store_retriever)
# Prompt the LLM
response = query_engine.query("What was MongoDB's latest acquisition?")
print(response)
print("\nSource documents: ")
pprint.pprint(response.source_nodes)
MongoDB's latest acquisition was Voyage AI, a pioneer in embedding and reranking models that power next-generation AI applications.
Source documents:
[NodeWithScore(node=TextNode(id_='82a2a0c0-80b9-4a9e-a848-529b4ff8f301', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='8cfe6680-8dec-486e-92c5-89ac1733b6c8', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='b6c412af868c29d67a6b030f266cd0e680f4a578a34c209c1818ff9a366c9d44'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='479446ef-8a32-410d-a5e0-8650bd10d78d', node_type='1', metadata={}, hash='b805543bf0ef0efc25492098daa9bd9c037043fb7228fb0c3270de235e668341')}, metadata_template='{key}: {value}', metadata_separator='\n', text="Fourth Quarter Fiscal 2025 and Recent Business Highlights\nMongoDB acquired Voyage AI, a pioneer in state-of-the-art embedding and reranking models that power next-generation\nAI applications. Integrating Voyage AI's technology with MongoDB will enable organizations to easily build trustworthy,\nAI-powered applications by offering highly accurate and relevant information retrieval deeply integrated with operational\ndata.", mimetype='text/plain', start_char_idx=1678, end_char_idx=2101, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.9280173778533936),
NodeWithScore(node=TextNode(id_='f3c35db6-43e5-4da7-a297-d9b009b9d300', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='3008736c-29f0-4b41-ac0f-efdb469319b9', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='cd3647350e6d7fcd89e2303fe1995b8f91b633c5f33e14b3b4c18a16738ea86f'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='c9bef874-77ee-40bc-a1fe-ca42d1477cb3', node_type='1', metadata={}, hash='c7d7af8a1b43b587a9c47b27f57e7cb8bc35bd90390a078db21e3f5253ee7cc1')}, metadata_template='{key}: {value}', metadata_separator='\n', text='Lombard Odier, a Swiss private bank, partnered with MongoDB to migrate and modernize its legacy banking technology\nsystems on MongoDB with generative AI. The initiative enabled the bank to migrate code 50-60 times quicker and move\napplications from a legacy relational database to MongoDB 20 times faster than previous migrations.', mimetype='text/plain', start_char_idx=2618, end_char_idx=2951, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.9198455214500427),
NodeWithScore(node=TextNode(id_='479446ef-8a32-410d-a5e0-8650bd10d78d', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='82a2a0c0-80b9-4a9e-a848-529b4ff8f301', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='688872b911c388c239669970f562d4014aaec4753903e75f4bdfcf1eb1daf5ab'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='3008736c-29f0-4b41-ac0f-efdb469319b9', node_type='1', metadata={}, hash='a854a9bf103e429ce78b45603df9e2341e5d0692aa95e544e6c82616be29b28e')}, metadata_template='{key}: {value}', metadata_separator='\n', text='MongoDB completed the redemption of 2026 Convertible Notes, eliminating all debt from the balance sheet. Additionally, in\nconjunction with the acquisition of Voyage, MongoDB is announcing a stock buyback program of $200 million, to offset the\ndilutive impact of the acquisition consideration.', mimetype='text/plain', start_char_idx=2102, end_char_idx=2396, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.918432891368866),
NodeWithScore(node=TextNode(id_='3008736c-29f0-4b41-ac0f-efdb469319b9', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='479446ef-8a32-410d-a5e0-8650bd10d78d', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='833c2af73d617c1fef7d04111e010bfe06eeeb36c71225c0fb72987cd164526b'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='f3c35db6-43e5-4da7-a297-d9b009b9d300', node_type='1', metadata={}, hash='c39c6258ff9fe34b650dd2782ae20e1ed57ed20465176cbf455ee9857e57dba0')}, metadata_template='{key}: {value}', metadata_separator='\n', text='For the third consecutive year, MongoDB was named a Leader in the 2024 Gartner® Magic Quadrant™ for Cloud\nDatabase Management Systems. Gartner evaluated 20 vendors based on Ability to Execute and Completeness of Vision.', mimetype='text/plain', start_char_idx=2397, end_char_idx=2617, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.917201817035675),
NodeWithScore(node=TextNode(id_='d50a3746-84ac-4928-a252-4eda3515f9fc', embedding=None, metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='2171a7d3-482c-4f83-beee-8c37e0ebc747', node_type='4', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='ef623ef7400aa6e120f821b455b2ddce99b94c57365e7552b676abaa3eb23640'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='25e4f1c9-41ba-4344-b775-842a0a15c207', node_type='1', metadata={'page_label': '2', 'file_name': 'mongodb-earnings-report.pdf', 'file_path': 'data/mongodb-earnings-report.pdf', 'file_type': 'application/pdf', 'file_size': 150863, 'creation_date': '2025-05-28', 'last_modified_date': '2025-05-28'}, hash='28af4302a69924722e2ccd2015b8d64fa83790b4f0d4759898ede48e40668fa1'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='13da6584-75b4-4eb8-a071-8297087ce12c', node_type='1', metadata={}, hash='e316923acbe01dede55287258f9649bb9865ef2357f2316e190b97aef84f22ec')}, metadata_template='{key}: {value}', metadata_separator='\n', text="as amended, including statements concerning MongoDB's financial guidance\nfor the first fiscal quarter and full year fiscal 2026 and underlying assumptions, our expectations regarding Atlas consumption growth and the benefits\nof the Voyage AI acquisition.", mimetype='text/plain', start_char_idx=5174, end_char_idx=5428, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}'), score=0.9084539413452148)]

データ コネクタ、インデックス、クエリ エンジンなど、RAMRAG アプリケーション用の の完全なライブラリを確認するには、 LlamaHub を参照してください。

このチュートリアルのアプリケーションを拡張して、双方向のやり取りを行うには、「 チャット エンジン 」を参照してください。

MongoDBは、次の開発者リソースも提供しています。

戻る

LangChain4j

項目一覧