microsoft/semantic-kernel · error · VectorSearchExecutionException
Failed to search the collection.
Error message
Failed to search the collection.
What it means
CosmosMongoCollection._inner_vector_search wraps the MongoDB aggregation pipeline in a try/except. Any exception from collection.aggregate (network, auth, server-side aggregation error, malformed pipeline) is caught and re-raised as VectorSearchExecutionException with the generic message. The original exception is chained via 'from exc'.
Source
Thrown at python/semantic_kernel/connectors/azure_cosmos_db.py:469
}
if filter := self._build_filter(options.filter): # type: ignore
vector_search_query["filter"] = filter if isinstance(filter, dict) else {"$and": filter}
projection_query: dict[str, int | dict] = {
field: 1
for field in self.definition.get_names(
include_vector_fields=options.include_vectors,
include_key_field=False, # _id is always included
)
}
projection_query[MONGODB_SCORE_FIELD] = {"$meta": "searchScore"}
try:
raw_results = await collection.aggregate([
{"$search": {"cosmosSearch": vector_search_query}},
{"$project": projection_query},
])
except Exception as exc:
raise VectorSearchExecutionException("Failed to search the collection.") from exc
return KernelSearchResults(
results=self._get_vector_search_results_from_results(raw_results, options),
total_count=None, # no way to get a count before looping through the result cursor
)
# region: Mongo Store
@release_candidate
class CosmosMongoStore(MongoDBAtlasStore):
"""Azure Cosmos DB for MongoDB store."""
def __init__(
self,
connection_string: str | None = None,
database_name: str | None = None,
mongo_client: AsyncMongoClient | None = None,View on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the chained __cause__ for the real server error and HTTP status.
- Verify the vector index exists and is built (vector-ivf/hnsw/diskann) before querying.
- Check connectivity, credentials, and Cosmos DB throughput/RU provisioning.
- Ensure the vector field path and dimensions in the query match the index definition.
Defensive patterns
Strategy: retry
Try / catch
try:
results = await collection.search(...)
except VectorSearchExecutionException as e:
cause = e.__cause__
# classify: 429/network -> retry with backoff; auth -> refresh; bad pipeline -> fix filter
Prevention
- Ensure the vector index is online before querying (poll create result).
- Provision enough RU/s for your query load.
- Implement retry with exponential backoff for transient failures.
- Centralize exception classification of chained causes.
When it happens
Trigger: Raised in CosmosMongoCollection._inner_vector_search when collection.aggregate([...]) raises. Common causes: expired credentials, throttling (429), the cosmosSearch index not yet built, a filter pipeline that the server rejects, network outage, or an indexing/policy mismatch detected server-side.
Common situations: Running a search immediately after creating a collection before the vector index is ready. RU exhaustion under load. Expired Entra ID tokens. Network blips. A bug in _build_filter producing an invalid $match that the server rejects.
Related errors
- Vector field '{options.vector_property_name}' not found in t
- Failed to check if database '{self.database_name}' exists, w
- Failed to get database proxy for '{id}'.
- Failed to get container proxy for '{container_name}'.
- Index kind '{field.index_kind}' is not supported by Azure Co
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/105084344f2077de.
Report an issue: GitHub.