Skip to main content
SwarmMatcher has been removed from the swarms package (swarms/structs/swarm_matcher.py was deleted, along with its torch/sentence-transformers dependencies) and migrated to a separate, not-yet-published swarms-utils package. As of the current codebase, from swarms.structs.swarm_matcher import SwarmMatcher will raise ModuleNotFoundError — the class is not importable from swarms at all. The parameter and method reference below reflects the last known implementation prior to removal and cannot be verified against current source. Treat this page as historical until SwarmMatcher is reintroduced or its replacement package is published.

Overview

The SwarmMatcher utilizes transformer-based embeddings to determine the best swarm architecture for a given task. By analyzing the semantic meaning of task descriptions and comparing them to known swarm types, it can intelligently select the optimal swarm configuration for any task.

Workflow

Installation

Attributes

SwarmMatcherConfig

str
default:"sentence-transformers/all-MiniLM-L6-v2"
The transformer model to use for generating embeddings.
int
default:"512"
The dimension of the embedding vectors.

SwarmType

str
required
The name of the swarm type.
str
required
A detailed description of the swarm type’s capabilities and ideal use cases.
Optional[List[float]]
default:"None"
The generated embedding vector for this swarm type (auto-populated).

Methods

__init__()

Initializes the SwarmMatcher with a configuration.
Parameters:
  • config (SwarmMatcherConfig): Configuration object for the matcher

get_embedding()

Generates an embedding vector for a given text using the configured model.
Parameters:
  • text (str): The text to embed
Returns: np.ndarray - The embedding vector

add_swarm_type()

Adds a swarm type to the matcher, generating an embedding for its description.
Parameters:
  • swarm_type (SwarmType): The swarm type to add

find_best_match()

Finds the best matching swarm type for a given task.
Parameters:
  • task (str): The task description
Returns: Tuple[str, float] - The name of the best matching swarm type and the similarity score

auto_select_swarm()

Automatically selects the best swarm type for a given task.
Parameters:
  • task (str): The task description
Returns: str - The name of the selected swarm type

run_multiple()

Matches multiple tasks to swarm types in batch.
Parameters:
  • tasks (List[str]): A list of task descriptions
Returns: List[str] - A list of selected swarm type names

save_swarm_types()

Saves the registered swarm types to a JSON file.
Parameters:
  • filename (str): Path where the swarm types will be saved

load_swarm_types()

Loads swarm types from a JSON file.
Parameters:
  • filename (str): Path to the JSON file containing swarm types

Available Swarm Types

SwarmMatcher comes with several pre-defined swarm types:

Usage Examples

Simple Matching

Batch Matching

Advanced Usage with Custom Configuration

Custom Swarm Types

How It Works

SwarmMatcher uses a transformer-based model to generate embeddings (vector representations) of both the task descriptions and the swarm type descriptions. It then calculates the similarity between these embeddings to determine which swarm type is most semantically similar to the given task. The matching process follows these steps:
  1. The task description is converted to an embedding vector
  2. Each swarm type’s description is converted to an embedding vector
  3. The similarity between the task embedding and each swarm type embedding is calculated
  4. The swarm type with the highest similarity score is selected
This approach ensures that the matcher can understand the semantic meaning of tasks, not just keyword matching, resulting in more accurate swarm type selection.

Source Code

View the source code on GitHub