apache/beam · error · ValueError

Search strategy must be provided

Error message

Search strategy must be provided

What it means

MilvusSearchParameters is a dataclass whose __post_init__ validates that required fields are set. This error means a MilvusEnricher search configuration was constructed without a search_strategy, so the enricher cannot know whether to run vector, keyword, or hybrid search against the Milvus collection.

Source

Thrown at sdks/python/apache_beam/ml/rag/enrichment/milvus_search.py:246

      only primary fields including distances will be returned.
    timeout: Search operation timeout in seconds. If not specified, the client's
      default timeout is used.
    round_decimal: Number of decimal places for distance/similarity scores.
      Defaults to -1 means no rounding.
  """
  collection_name: str
  search_strategy: SearchStrategyType
  partition_names: list[str] = field(default_factory=list)
  output_fields: list[str] = field(default_factory=list)
  timeout: Optional[float] = None
  round_decimal: int = -1

  def __post_init__(self):
    if not self.collection_name:
      raise ValueError("Collection name must be provided")

    if not self.search_strategy:
      raise ValueError("Search strategy must be provided")


@dataclass
class MilvusCollectionLoadParameters:
  """Parameters that control how Milvus loads a collection into memory.

  This class provides fine-grained control over collection loading, which is
  particularly important in resource-constrained environments. Proper
  configuration can significantly reduce memory usage and improve query
  performance by loading only necessary data.

  Args:
    refresh: If True, forces a reload of the collection even if already loaded.
      Ensures the most up-to-date data is in memory.
    resource_groups: List of resource groups to load the collection into. Can be
      used for load balancing across multiple query nodes.
    load_fields: Specify which fields to load into memory. Loading only
      necessary fields reduces memory usage. If empty, all fields loaded.

View on GitHub (pinned to 12126d8942)

Solutions

  1. Pass search_strategy=VectorSearchStrategy(), KeywordSearchStrategy(), or HybridSearchStrategy() when constructing MilvusSearchParameters
  2. Check the config file/dict actually contains the search_strategy key
  3. Verify no rename/typo in the keyword (it is exactly search_strategy)

Example fix

// before
params = MilvusSearchParameters(collection_name='docs')
// after
params = MilvusSearchParameters(
    collection_name='docs',
    search_strategy=VectorSearchStrategy(embedding_fn=my_embedder))
Defensive patterns

Strategy: validation

Validate before calling

if not params.search_strategy:
    raise ValueError('search_strategy required before MilvusEnricher use')

Type guard

def has_strategy(p) -> bool:
    return getattr(p, 'search_strategy', None) is not None

Try / catch

try:
    enricher = MilvusEnricher(params)
except ValueError as e:
    if 'Search strategy' in str(e): params.search_strategy = VectorSearchStrategy(embedding_fn=fn)
    else: raise

Prevention

When it happens

Trigger: Constructing MilvusSearchParameters (directly or via MilvusEnricher config) with search_strategy omitted or explicitly set to None/empty while collection_name is valid.

Common situations: Copying a config dict and dropping the strategy key; building parameters programmatically from YAML/JSON where the field was absent; refactors that renamed the field so the old keyword is silently swallowed into **kwargs.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/2d4dfee075ea7f68. Report an issue: GitHub.