Files
crewAI/docs/edge/ar/tools/database-data/mongodbvectorsearchtool.mdx
T
Nora Reidy c0eda9f538
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Vulnerability Scan / Detect changes (push) Has been cancelled
Vulnerability Scan / pip-audit (push) Has been cancelled
Check Documentation Broken Links / Check broken links (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
docs: consolidate MongoDB documentation improvements (#8097)
* docs: consolidate MongoDB documentation improvements

Combines previously closed MongoDB docs PRs (#6847, #6845, #6721,
#6626, #6760, #6759) into a single PR per the updated contribution
guidelines requiring a linked open issue.

RagTool only supports chromadb and qdrant as vector store backends;
MongoDB Atlas is covered separately by MongoDBVectorSearchTool, which
is already listed in the database-data tools overview, so the RagTool
data-sources bullet was dropped rather than reintroduced.

Fixes #8096

* revert gemini change

* ai review feedback

* memory wording

* translations
2026-10-13 11:36:15 +05:30

179 lines
7.5 KiB
Plaintext

---
title: أداة البحث المتجهي في MongoDB
description: تقوم `MongoDBVectorSearchTool` بإجراء بحث متجهي على MongoDB Atlas مع أدوات مساعدة اختيارية لإنشاء الفهارس.
icon: "leaf"
mode: "wide"
---
# `MongoDBVectorSearchTool`
## الوصف
تُمكّن `MongoDBVectorSearchTool` من إجراء استعلامات التشابه المتجهي على مجموعات MongoDB Atlas. يدعم
MongoDB Atlas البحث المتجهي الأصلي. كما تدعم الأداة أدوات مساعدة لإنشاء الفهارس وإدراج النصوص المضمنة بكميات كبيرة.
يُعد البحث المتجهي في MongoDB مفيدًا للتطبيقات التي تريد استخدام قاعدة بيانات بحث متجهي للاستعلام عن البيانات
باستخدام البحث الدلالي، أو تصفية الاستعلامات حسب حقول أخرى في مجموعتك، أو تشغيل تطبيقات الذكاء الاصطناعي
وأنظمة الوكلاء الخاصة بك من خلال تنفيذ التوليد المعزز بالاسترجاع (RAG).
اعرف المزيد: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/
## التثبيت
قم بالتثبيت مع إضافة MongoDB:
```shell
pip install crewai-tools[mongodb]
```
أو
```shell
uv add crewai-tools --extra mongodb
```
## معاملات التهيئة
- `connection_string` (str): مطلوب. بيانات اعتماد سلسلة الاتصال بـ MongoDB Atlas للاتصال بمجموعتك (cluster).
- `database_name` (str): مطلوب. اسم قاعدة بيانات MongoDB المراد استخدامها.
- `collection_name` (str): مطلوب. المجموعة ضمن قاعدة البيانات حيث تُخزَّن المستندات والتضمينات (embeddings).
- `vector_index_name` (str، الافتراضي: `vector_index`): اختياري. اسم فهرس البحث المتجهي في MongoDB المراد
الاستعلام عنه (يجب أن يطابق الفهرس الذي تم إنشاؤه في Atlas).
- `text_key` (str، الافتراضي: `text`): اختياري. اسم حقل المستند الذي يُخزَّن فيه النص الخام.
- `embedding_key` (str، الافتراضي: `embedding`): اختياري. اسم حقل المستند الذي يُخزَّن فيه التضمين المتجهي.
- `dimensions` (int، الافتراضي: `1536`): اختياري. عدد أبعاد نموذج التضمين (يجب أن يطابق نموذجك).
- `query_config` (MongoDBVectorSearchConfig): اختياري. كائن `MongoDBVectorSearchConfig` لإعدادات الاستعلام
المتقدمة، مثل `limit` و `oversampling_factor`.
## طرق MongoDBVectorSearchTool
- `run(query=...)`: يُضمّن استعلامًا وينفّذ بحث تشابه متجهي، ويُعيد المستندات المطابقة. يأخذ معامل
`query` (`str`) بلغة طبيعية لتضمينه والبحث عنه.
- `add_texts(list of strings)`: يأخذ قائمة من النصوص لتضمينها وإدراجها كمستندات في قاعدة بيانات MongoDB Atlas الخاصة بك.
- `create_vector_search_index(dimensions=...)`: يُنشئ فهرس بحث متجهي في MongoDB بالأبعاد والتشابه الصحيحين.
يأخذ معامل `dimensions` (int).
## بداية سريعة
يوضح المثال التالي كيفية تهيئة الأداة وتنفيذ بحث تشابه متجهي على مجموعة MongoDB Atlas المحددة:
```python Code
from crewai_tools import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
connection_string="mongodb+srv://...",
database_name="mydb",
collection_name="docs",
)
print(tool.run(query="how to create vector index"))
```
## المشكلات الشائعة
- فشل المصادقة: تأكد من أن قائمة الوصول إلى عناوين IP في Atlas تسمح بخادمك وأن سلسلة الاتصال تتضمن بيانات الاعتماد.
- الفهرس غير موجود: أنشئ الفهرس المتجهي أولاً؛ يجب أن يتطابق الاسم مع `vector_index_name`.
- عدم تطابق الأبعاد: قم بمحاذاة أبعاد نموذج التضمين مع `dimensions`.
## أمثلة
### تحميل قاعدة البيانات مسبقًا وإنشاء الفهرس
يوضح المثال التالي كيفية تحميل قاعدة بيانات MongoDB Atlas الخاصة بك مسبقًا بالمستندات
وإنشاء فهرس بحث متجهي في MongoDB للاستعلام عن مجموعتك:
```python Code
import os
from crewai_tools import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
database_name="example_database",
collection_name="example_collection",
connection_string="<your_mongodb_connection_string>",
dimensions=3072,
)
# Load text content from a local folder and add to your MongoDB collection
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())
tool.add_texts(texts)
# Create the MongoDB Vector Search index (e.g., 3072 dims for text-embedding-3-large)
tool.create_vector_search_index(dimensions=3072)
```
### تكوين استعلام مخصص وتكامل مع الوكيل
يوضح المثال التالي كيفية توفير تكوين استعلام مخصص لـ `MongoDBVectorSearchTool`
ودمجها مع وكيل CrewAI:
```python Code
from crewai_tools import MongoDBVectorSearchConfig, MongoDBVectorSearchTool
query_config = MongoDBVectorSearchConfig(limit=10, oversampling_factor=2)
tool = MongoDBVectorSearchTool(
database_name="example_database",
collection_name="example_collection",
connection_string="<your_mongodb_connection_string>",
query_config=query_config,
vector_index_name="my_vector_index",
)
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],
)
```
### تشغيل سير عمل CrewAI
يوضح المثال التالي كيفية دمج `MongoDBVectorSearchTool` مع Agent و Task و Crew
لإنشاء وتشغيل سير عمل RAG قائم على الوكلاء في CrewAI:
```python Code
from crewai import Agent, Task, Crew
from crewai_tools import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
connection_string="mongodb+srv://...",
database_name="mydb",
collection_name="docs",
)
agent = Agent(
role="RAG Agent",
goal="Answer using MongoDB vector search",
backstory="Knowledge retrieval specialist",
tools=[tool],
verbose=True,
)
task = Task(
description="Find relevant content for 'indexing guidance'",
expected_output="A concise answer citing the most relevant matches",
agent=agent,
)
crew = Crew(
agents=[agent],
tasks=[task],
verbose=True,
)
result = crew.kickoff()
```
## لمعرفة المزيد
لمعرفة المزيد حول تكاملات CrewAI مع MongoDB، راجع أدلة MongoDB التالية:
- [دمج MongoDB مع CrewAI](https://www.mongodb.com/docs/atlas/ai-integrations/crewai/)
- [بناء تطبيق RAG قائم على الوكلاء باستخدام CrewAI و MongoDB](https://www.mongodb.com/docs/atlas/ai-integrations/crewai/build-agents/)