Skip to main content

Overview

The WeaviateVectorSearchTool is specifically crafted for conducting semantic searches within documents stored in a Weaviate vector database. This tool allows you to find semantically similar documents to a given query, leveraging the power of vector and keyword search for more accurate and contextually relevant search results. Weaviate is a vector database that stores and queries vector embeddings, enabling semantic search capabilities.

Installation

To incorporate this tool into your project, you need to install the Weaviate client:

Steps to Get Started

To effectively use the WeaviateVectorSearchTool, follow these steps:
  1. Package Installation: Confirm that the crewai[tools] and weaviate-client packages are installed in your Python environment.
  2. Weaviate Setup: Set up a Weaviate cluster. You can follow the Weaviate documentation for instructions.
  3. API Keys: Obtain your Weaviate cluster URL and API key.
  4. OpenAI API Key: Ensure you have an OpenAI API key set in your environment variables as OPENAI_API_KEY.

Example

The following example demonstrates how to initialize the tool and execute a search:
Code

Parameters

The WeaviateVectorSearchTool accepts the following parameters:
  • collection_name: Required. The name of the collection to search within.
  • weaviate_cluster_url: Required. The URL of the Weaviate cluster.
  • weaviate_api_key: Required. The API key for the Weaviate cluster.
  • limit: Optional. The number of results to return. Default is 3.
  • alpha: Optional. Controls the weighting between vector and keyword (BM25) search. alpha = 0 -> BM25 only, alpha = 1 -> vector search only. Default is 0.75.
  • vectorizer: Optional. The vectorizer to use. If not provided, it will use text2vec_openai with the nomic-embed-text model.
  • generative_model: Optional. The generative model to use. If not provided, it will use OpenAI’s gpt-4o.

Advanced Configuration

You can customize the vectorizer and generative model used by the tool:
Code

Preloading Documents

You can preload your Weaviate database with documents before using the tool:
Code

Agent Integration Example

Here’s how to integrate the WeaviateVectorSearchTool with a CrewAI agent:
Code

Conclusion

The WeaviateVectorSearchTool provides a powerful way to search for semantically similar documents in a Weaviate vector database. By leveraging vector embeddings, it enables more accurate and contextually relevant search results compared to traditional keyword-based searches. This tool is particularly useful for applications that require finding information based on meaning rather than exact matches.