{"record":{"id":"7c27d8847b4cb972","repo":"microsoft/semantic-kernel","slug":"failed-to-search-the-collection","errorCode":null,"errorMessage":"Failed to search the collection.","messagePattern":"Failed to search the collection\\.","errorType":"exception","errorClass":"VectorSearchExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_ai_search.py","lineNumber":629,"sourceCode":"                vector = await self._generate_vector_from_values(values, options) if vector is None else vector\n                if vector is not None:\n                    search_args[\"vector_queries\"] = [\n                        VectorizedQuery(\n                            vector=vector,  # type: ignore\n                            fields=vector_field.name if vector_field else None,\n                        )\n                    ]\n                else:\n                    search_args[\"vector_queries\"] = [\n                        VectorizableTextQuery(\n                            text=values,\n                            fields=vector_field.name if vector_field else None,\n                        )\n                    ]\n        try:\n            raw_results = await self.search_client.search(**search_args, **kwargs)\n        except Exception as exc:\n            raise VectorSearchExecutionException(\"Failed to search the collection.\") from exc\n        return KernelSearchResults(\n            results=self._get_vector_search_results_from_results(raw_results, options),\n            total_count=await raw_results.get_count() if options.include_total_count else None,\n        )\n\n    @override\n    def _lambda_parser(self, node: ast.AST) -> Any:\n        def _parse_attribute_chain(attr_node: ast.Attribute) -> str:\n            parts = []\n            current = attr_node\n            while isinstance(current, ast.Attribute):\n                parts.append(current.attr)\n                current = current.value  # type: ignore\n            if isinstance(current, ast.Name):\n                # skip the root variable name (e.g., 'x')\n                pass\n            else:\n                raise NotImplementedError(f\"Unsupported attribute chain root: {type(current)}\")","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_ai_search.py#L611-L647","documentation":"Raised by _inner_search when the underlying await self.search_client.search(**search_args, **kwargs) raises any Exception. The connector wraps every failure — network, auth, throttling, bad query syntax, missing index — into a VectorSearchExecutionException with this generic message, chaining the original via 'from exc'. The real cause is on exc.__cause__.","triggerScenarios":"Any Azure AI Search service-side or client-side failure during a search call: HTTP 401 (bad/expired credential), 403 (forbidden), 404 (index not found), 429 (throttling), 400 (malformed OData filter / vector dimensions mismatch), or a transient network error. The broad 'except Exception' catches all of them.","commonSituations":"Expired key or managed identity token; querying an index that was never created (ensure_collection_exists not called); a filter lambda referencing a non-existent field; vector dimension mismatch between query and index; hitting Azure AI Search throughput limits.","solutions":["Inspect exc.__cause__ for the actual azure.core exception and its status_code to determine the real failure.","For 429/throttling, implement exponential backoff retry (e.g. via tenacity) on VectorSearchExecutionException.","For 404, call ensure_collection_exists() before searching.","For 401/403, refresh/verify credentials (see error 1220).","For 400, validate filter field names and vector dimensions against the index schema."],"exampleFix":"// before\nresults = await collection.search(values=q)\n\n// after\ntry:\n    results = await collection.search(values=q)\nexcept VectorSearchExecutionException as e:\n    cause = e.__cause__          # real azure.core exception\n    code = getattr(cause, \"status_code\", None)\n    if code == 429:\n        await asyncio.sleep(backoff); ...   # retry\n    raise","handlingStrategy":"retry","validationCode":"def build_search_kwargs(options, vector=None, values=None) -> dict:\n    # validate filter fields & vector dims before calling search\n    if options.filter:\n        for name in extract_filter_field_names(options.filter):\n            assert name in collection.definition.storage_names, f\"filter field {name} not in model\"\n    return {\"options\": options, \"vector\": vector, \"values\": values}","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import VectorSearchExecutionException\nimport asyncio\n\nasync def search_with_retry(collection, **kw, retries=3):\n    delay = 0.5\n    for attempt in range(retries):\n        try:\n            return await collection.search(**kw)\n        except VectorSearchExecutionException as e:\n            code = getattr(e.__cause__, \"status_code\", None)\n            if code == 429 and attempt < retries - 1:\n                await asyncio.sleep(delay); delay *= 2\n                continue\n            raise","preventionTips":["Always inspect e.__cause__ and its status_code to classify the real failure.","Retry only transient errors (429, 5xx) with exponential backoff; do not retry 400/401/403/404.","Call ensure_collection_exists() before searching to avoid 404.","Validate filter field names and vector dimensions against the index schema before searching."],"tags":["network","azure-ai-search","runtime","transient"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}