Overview
Adapter implementation that integrates CrewAI's native RAG (Retrieval Augmented Generation) system with the tool framework, supporting multiple vector database backends.
Description
The CrewAIRagAdapter class implements the Adapter interface and serves as the bridge between CrewAI's RAG system and the tool framework. It provides a unified interface for adding diverse content types to vector databases and querying them semantically.
Key capabilities:
- Configurable backends: Supports multiple vector stores through
RagConfigType, including Qdrant and ChromaDB, with special handling for Qdrant-specific configuration (vectors_config) through type-safe duck typing.
- Semantic querying: The
query() method searches the knowledge base with configurable similarity threshold (default 0.6) and result limit (default 5).
- Comprehensive content ingestion: The
add() method supports strings, file paths, URLs, websites, GitHub repos, YouTube videos, and directories with automatic data type detection.
- Recursive directory processing: Walks directories, skipping binary files (pyc, png, jpg, zip, etc.), hidden files/directories, and __pycache__ directories.
- Document chunking: Uses data-type-specific loaders and chunkers to split content into embeddable segments.
- Deterministic IDs: Generates unique chunk IDs using SHA256 hashing of doc_id, chunk index, and content.
- Metadata sanitization: Sanitizes metadata for ChromaDB compatibility before storage.
Usage
Use this adapter when you need to add knowledge from files, URLs, or directories to a vector database for semantic search by CrewAI agents. It is the default RAG adapter for CrewAI's knowledge management system.
Code Reference
Source Location
- Repository: CrewAI
- File: lib/crewai-tools/src/crewai_tools/adapters/crewai_rag_adapter.py
- Lines: 1-355
Signature
class CrewAIRagAdapter(Adapter):
"""Adapter that uses CrewAI's native RAG system."""
collection_name: str = "default"
summarize: bool = False
similarity_threshold: float = 0.6
limit: int = 5
config: RagConfigType | None = None
_client: BaseClient | None = PrivateAttr(default=None)
Import
from crewai_tools.adapters.crewai_rag_adapter import CrewAIRagAdapter
I/O Contract
Inputs (Constructor)
| Name |
Type |
Required |
Description
|
| collection_name |
str |
No |
Name of the vector collection (default: "default")
|
| summarize |
bool |
No |
Whether to summarize content (default: False)
|
| similarity_threshold |
float |
No |
Minimum similarity score for search results (default: 0.6)
|
| limit |
int |
No |
Maximum number of results to return (default: 5)
|
| config |
RagConfigType or None |
No |
Custom vector database configuration (default: None, uses default client)
|
query() Method
| Name |
Type |
Required |
Description
|
| question |
str |
Yes |
The question to search for
|
| similarity_threshold |
float or None |
No |
Override the instance-level threshold
|
| limit |
int or None |
No |
Override the instance-level result limit
|
add() Method
| Name |
Type |
Required |
Description
|
| *args |
ContentItem |
No |
Content items (strings, paths, or document dicts)
|
| data_type |
DataType or str |
No |
Explicit data type ("file", "pdf_file", "text", etc.)
|
| path |
str |
No |
Path to file or directory
|
| file_path |
str |
No |
Alias for path
|
| metadata |
dict |
No |
Additional metadata to attach to documents
|
| url |
str |
No |
URL to fetch content from
|
| website |
str |
No |
Website URL to scrape
|
| github_url |
str |
No |
GitHub repository URL
|
| youtube_url |
str |
No |
YouTube video URL
|
| directory_path |
str |
No |
Path to directory for recursive processing
|
Outputs
| Name |
Type |
Description
|
| query() return |
str |
Concatenated relevant content from the knowledge base, or "No relevant content found."
|
| add() return |
None |
Documents are added to the vector store (no return value)
|
Usage Examples
Basic Usage
from crewai_tools.adapters.crewai_rag_adapter import CrewAIRagAdapter
# Create adapter with default ChromaDB backend
adapter = CrewAIRagAdapter(collection_name="my_knowledge")
# Add a PDF document
adapter.add("path/to/document.pdf", data_type="pdf_file")
# Add from a URL
adapter.add(url="https://example.com/article")
# Add an entire directory
adapter.add(directory_path="path/to/docs/")
# Query the knowledge base
result = adapter.query("What is the main topic?", similarity_threshold=0.7, limit=3)
With Qdrant Backend
from crewai_tools.adapters.crewai_rag_adapter import CrewAIRagAdapter
adapter = CrewAIRagAdapter(
collection_name="qdrant_collection",
config=qdrant_config, # QdrantConfig with vectors_config
similarity_threshold=0.7,
limit=10,
)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.