Implementation:CrewAIInc CrewAI Weaviate Vector Search Tool
| Knowledge Sources | |
|---|---|
| Domains | Tools, Vector_Database, RAG |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
WeaviateVectorSearchTool performs hybrid vector searches against a Weaviate cloud vector database to retrieve semantically relevant documents.
Description
The WeaviateVectorSearchTool extends BaseTool and requires collection_name, weaviate_cluster_url, and weaviate_api_key at initialization. It uses default factory functions for the vectorizer (text2vec_openai with nomic-embed-text model) and generative model (openai gpt-4o), both of which can be overridden. On initialization, it retrieves the OPENAI_API_KEY from the environment for the Weaviate client headers. If the weaviate-client package is missing, it prompts for installation via click.confirm. The _run method connects to Weaviate cloud, retrieves the specified collection (or creates it if not found), performs a hybrid query with configurable limit (default 3) and alpha (default 0.75, balancing keyword and vector search), serializes results to JSON, then closes the client connection.
Usage
Use this tool when a CrewAI agent needs to query an enterprise-grade Weaviate vector database for semantically relevant internal documents using hybrid search combining keyword and vector similarity.
Code Reference
Source Location
- Repository: CrewAI
- File: lib/crewai-tools/src/crewai_tools/tools/weaviate_tool/vector_search.py
- Lines: 1-138
Signature
class WeaviateToolSchema(BaseModel):
query: str = Field(..., description="The query to search retrieve relevant information ...")
class WeaviateVectorSearchTool(BaseTool):
name: str = "WeaviateVectorSearchTool"
description: str = "A tool to search the Weaviate database for relevant information on internal documents."
args_schema: type[BaseModel] = WeaviateToolSchema
collection_name: str = Field(description="The name of the Weaviate collection to search")
limit: int | None = Field(default=3)
alpha: float = Field(default=0.75)
weaviate_cluster_url: str = Field(...)
weaviate_api_key: str = Field(...)
vectorizer: Any = Field(default_factory=_set_vectorizer)
generative_model: Any = Field(default_factory=_set_generative_model)
env_vars: list[EnvVar] # OPENAI_API_KEY
def _run(self, query: str) -> str:
...
Import
from crewai_tools import WeaviateVectorSearchTool
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| query | str | Yes | The search query to retrieve relevant information from Weaviate |
Outputs
| Name | Type | Description |
|---|---|---|
| _run() returns | str | JSON string containing the properties of matching objects from the Weaviate collection |
Usage Examples
Basic Usage
from crewai_tools import WeaviateVectorSearchTool
tool = WeaviateVectorSearchTool(
collection_name="InternalDocs",
weaviate_cluster_url="https://my-cluster.weaviate.network",
weaviate_api_key="my-weaviate-api-key",
)
result = tool._run(query="quarterly revenue report")