AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

MongoDBと [CbrewAI] との統合

MongoDB (具体的には、 MongoDB ベクトル検索 Tools を使用して、チーム内のAIエージェントがデータから関連情報を取得し、タスクを完了できるようにします。

CredeAI とMongoDBを使用してチュートリアルを完了するには、CRUI とMongoDBを使用してエージェント RAG アプリケーションを構築する を参照してください。

CRUDAI 用のMongoDBベクトル検索ツールをインストールするには、 Pythonパッケージマネージャーに応じて次のいずれかのコマンドを実行します。

pip install 'crewai-tools[mongodb]'

注意

Pythonバージョンの互換性は、CbrewAI の公式ドキュメントとは異なる場合があります。書き込み時に、crewai-toolsパッケージはembedchain に依存しています。これには、3.9 から 3.13.2 までのPythonバージョンが必要です。(この値を含む)。

MongoDB ベクトル検索ツールを使用するには、それを初期化し、それをエージェントに渡します。

ツールを初期化するには、以下を指定する必要があります。

from crewai_tools import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
connection_string="<connection-string>",
database_name="<database-name>",
collection_name="<collection-name>",
# Other optional parameters...
)
# To test the tool
print(tool.run(query="<test-query>"))
# To use the tool in an agent
rag_agent = Agent(
name="rag_agent",
role="You are a helpful assistant that can answer questions with the help of the MongoDBVectorSearchTool.",
goal="...",
backstory="...",
tools=[tool],
)

MongoDBVectorSearchToolクラスは次のメソッドを提供します。

  • add_texts(): 指定されたMongoDBコレクションにテキスト ドキュメントを追加します。

  • create_vector_search_index():コレクションにベクトル検索インデックスを作成します。

  • run(): データに対してベクトル検索クエリーを実行します。

import os
from crewai_tools import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
connection_string="<connection-string>",
database_name="<database-name>",
collection_name="<collection-name>"
)
# Example of loading text content from a local folder
texts = []
for fname in os.listdir("knowledge"):
path = os.path.join("knowledge", fname)
if os.path.isfile(path):
with open(path, "r", encoding="utf-8") as f:
texts.append(f.read())
# Method to add documents to the vector store
tool.add_texts(texts)
# Method to create the vector search index
tool.create_vector_search_index(dimensions=<number-of-dimensions>)
# Method to test the tool by running a vector search query
tool.run(query="<search-query>")