Directory RAG Search
DirectorySearchTool
Section titled “DirectorySearchTool”Description
Section titled “Description”The DirectorySearchTool enables semantic search within the content of specified directories, leveraging the Retrieval-Augmented Generation (RAG) methodology for efficient navigation through files. Designed for flexibility, it allows users to dynamically specify search directories at runtime or set a fixed directory during initial setup.
Installation
Section titled “Installation”To use the DirectorySearchTool, begin by installing the crewai_tools package. Execute the following command in your terminal:
pip install 'crewai[tools]'Initialization and Usage
Section titled “Initialization and Usage”Import the DirectorySearchTool from the crewai_tools package to start. You can initialize the tool without specifying a directory, enabling the setting of the search directory at runtime. Alternatively, the tool can be initialized with a predefined directory.
from crewai_tools import DirectorySearchTool
# For dynamic directory specification at runtimetool = DirectorySearchTool()
# For fixed directory searchestool = DirectorySearchTool(directory='/path/to/directory')Arguments
Section titled “Arguments”directory: A string argument that specifies the search directory. This is optional during initialization but required for searches if not set initially.
Custom Model and Embeddings
Section titled “Custom Model and Embeddings”The DirectorySearchTool uses OpenAI for embeddings and summarization by default. Customization options for these settings include changing the model provider and configuration, enhancing flexibility for advanced users.
from chromadb.config import Settings
tool = DirectorySearchTool( config={ "embedding_model": { "provider": "openai", "config": { "model": "text-embedding-3-small", # "api_key": "sk-...", }, }, "vectordb": { "provider": "chromadb", # or "qdrant" "config": { # "settings": Settings(persist_directory="/content/chroma", allow_reset=True, is_persistent=True), # from qdrant_client.models import VectorParams, Distance # "vectors_config": VectorParams(size=384, distance=Distance.COSINE), } }, })
## Security
### Path Validation
Directory paths provided to this tool are validated against the current working directory. Paths that resolve outside the working directory are rejected with a `ValueError`.
To allow paths outside the working directory (for example, in tests or trusted pipelines), set the environment variable:
```shellCREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true