الانتقال إلى المحتوى الرئيسي

PDFSearchTool

لا نزال نعمل على تحسين الأدوات، لذا قد يحدث سلوك غير متوقع أو تغييرات في المستقبل.

الوصف

أداة PDFSearchTool هي أداة RAG مصممة لعمليات البحث الدلالي داخل محتوى PDF. تتيح إدخال استعلام بحث ومستند PDF، مستفيدة من تقنيات بحث متقدمة للعثور على المحتوى ذي الصلة بكفاءة. هذه القدرة تجعلها مفيدة بشكل خاص لاستخراج معلومات محددة من ملفات PDF الكبيرة بسرعة.

التثبيت

للبدء مع أداة PDFSearchTool، تأكد أولاً من تثبيت حزمة crewai_tools بالأمر التالي:
pip install 'crewai[tools]'

مثال

إليك كيفية استخدام PDFSearchTool للبحث داخل مستند PDF:
Code
from crewai_tools import PDFSearchTool

# Initialize the tool allowing for any PDF content search if the path is provided during execution
tool = PDFSearchTool()

# OR

# Initialize the tool with a specific PDF path for exclusive search within that document
tool = PDFSearchTool(pdf='path/to/your/document.pdf')

المعاملات

  • pdf: اختياري مسار ملف PDF للبحث. يمكن تقديمه عند التهيئة أو ضمن معاملات طريقة run. إذا قُدم عند التهيئة، تقتصر الأداة في بحثها على المستند المحدد.

النموذج والتضمينات المخصصة

بشكل افتراضي، تستخدم الأداة OpenAI لكل من التضمينات والتلخيص. لتخصيص النموذج، يمكنك استخدام قاموس تكوين كما يلي. ملاحظة: قاعدة بيانات متجهية مطلوبة لأن التضمينات المولّدة يجب تخزينها والاستعلام عنها من قاعدة بيانات متجهية.
Code
from crewai_tools import PDFSearchTool

# - embedding_model (required): choose provider + provider-specific config
# - vectordb (required): choose vector DB and pass its config

tool = PDFSearchTool(
    config={
        "embedding_model": {
            # Supported providers: "openai", "azure", "google-generativeai", "google-vertex",
            # "voyageai", "cohere", "huggingface", "jina", "sentence-transformer",
            # "text2vec", "ollama", "openclip", "instructor", "onnx", "roboflow", "watsonx", "custom"
            "provider": "openai",  # or: "google-generativeai", "cohere", "ollama", ...
            "config": {
                # Model identifier for the chosen provider. "model" will be auto-mapped to "model_name" internally.
                "model": "text-embedding-3-small",
                # Optional: API key. If omitted, the tool will use provider-specific env vars
                # (e.g., OPENAI_API_KEY or EMBEDDINGS_OPENAI_API_KEY for OpenAI).
                # "api_key": "sk-...",

                # Provider-specific examples:
                # --- Google Generative AI ---
                # (Set provider="google-generativeai" above)
                # "model_name": "gemini-embedding-001",
                # "task_type": "RETRIEVAL_DOCUMENT",
                # "title": "Embeddings",

                # --- Cohere ---
                # (Set provider="cohere" above)
                # "model": "embed-english-v3.0",

                # --- Ollama (local) ---
                # (Set provider="ollama" above)
                # "model": "nomic-embed-text",
            },
        },
        "vectordb": {
                    "provider": "chromadb",  # or "qdrant"
                    "config": {
                        # For ChromaDB: pass "settings" (chromadb.config.Settings) or rely on defaults.
                        # Example (uncomment and import):
                        # from chromadb.config import Settings
                        # "settings": Settings(
                        #     persist_directory="/content/chroma",
                        #     allow_reset=True,
                        #     is_persistent=True,
                        # ),

                        # For Qdrant: pass "vectors_config" (qdrant_client.models.VectorParams).
                        # Example (uncomment and import):
                        # from qdrant_client.models import VectorParams, Distance
                        # "vectors_config": VectorParams(size=384, distance=Distance.COSINE),

                        # Note: collection name is controlled by the tool (default: "rag_tool_collection"), not set here.
                    }
        },
    }
)