microsoft/semantic-kernel · error · VectorStoreModelException

Search type '{search_type}' is not supported.

Error message

Search type '{search_type}' is not supported.

What it means

The Cosmos DB NoSQL store only implements two search modes: VECTOR (pure VectorDistance) and KEYWORD_HYBRID (RRF of VectorDistance and FullTextScore). Any other SearchType enum value falls through to an else branch and raises a VectorStoreModelException. The connector simply has no code path for additional search types, so the request is rejected before any query is built.

Source

Thrown at python/semantic_kernel/connectors/azure_cosmos_db.py:843

        if vector_field.distance_function not in DISTANCE_FUNCTION_MAP_NOSQL:
            raise VectorStoreModelException(
                f"Distance function '{vector_field.distance_function}' is not supported by Azure Cosmos DB NoSQL."
            )
        # Cosmos DB VectorDistance function only accepts 2 parameters: field and vector
        # Distance function is configured in the vector index, not in the query
        if search_type == SearchType.VECTOR:
            distance_clause = f"VectorDistance(c.{vector_field_name}, @vector)"
        elif search_type == SearchType.KEYWORD_HYBRID:
            # Hybrid search: requires both a vector and keywords
            params.append({"name": "@keywords", "value": values})
            text_field = options.additional_property_name
            if not text_field:
                raise VectorStoreModelException("Hybrid search requires 'keyword_field_name' in options.")
            distance_clause = (
                f"RRF(VectorDistance(c.{vector_field_name}, @vector), FullTextScore(c.{text_field}, @keywords))"
            )
        else:
            raise VectorStoreModelException(f"Search type '{search_type}' is not supported.")
        query = (
            f"SELECT TOP @top {select_clause}, "  # nosec: B608
            f"{distance_clause} as {NOSQL_SCORE_PROPERTY_NAME} "  # nosec: B608
            "FROM c "
            f"{where_clauses}"  # nosec: B608
            f"ORDER BY {distance_clause}"  # nosec: B608
        )

        container_proxy = await self._get_container_proxy(self.collection_name, **kwargs)
        try:
            results = container_proxy.query_items(query, parameters=params)
        except Exception as exc:
            raise VectorSearchExecutionException("Failed to search items.") from exc
        return KernelSearchResults(
            results=self._get_vector_search_results_from_results(results, options),
            total_count=None,
        )

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Restrict the SearchType you pass to SearchType.VECTOR or SearchType.KEYWORD_HYBRID when using the Cosmos NoSQL store.
  2. If you need text-only keyword search, that mode is not supported by this connector; switch to a connector that implements it or run a manual Cosmos SQL query.
  3. Guard dynamic search_type values before calling search so unsupported types are rejected with your own validation rather than the library exception.

Example fix

// before
results = await store.search(values, VectorSearchOptions(top=5))  # search_type resolved to unsupported value
// after
if search_type not in (SearchType.VECTOR, SearchType.KEYWORD_HYBRID):
    raise ValueError("Cosmos NoSQL only supports VECTOR and KEYWORD_HYBRID")
results = await store.search(values, VectorSearchOptions(top=5))
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.data import SearchType
SUPPORTED = {SearchType.VECTOR, SearchType.KEYWORD_HYBRID}
if search_type not in SUPPORTED:
    raise ValueError(f"Unsupported search_type for Cosmos NoSQL: {search_type}")

Type guard

def is_supported_cosmos_search(st: SearchType) -> bool:
    return st in (SearchType.VECTOR, SearchType.KEYWORD_HYBRID)

Prevention

When it happens

Trigger: Calling _inner_search / the public search API with a SearchType value that is neither SearchType.VECTOR nor SearchType.KEYWORD_HYBRID (e.g. a pure keyword/text-only search, or a future enum member the installed version does not handle).

Common situations: A caller passes search_type based on dynamic/user input without restricting it to the two supported values, or code written against another connector (which supports more SearchType members) is pointed at the Cosmos NoSQL store.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/9c21ce8f4ace7334. Report an issue: GitHub.