{"record":{"id":"add3af498f904fbc","repo":"BerriAI/litellm","slug":"failed-to-generate-embedding-for-query-e","errorCode":null,"errorMessage":"Failed to generate embedding for query: {e}","messagePattern":"Failed to generate embedding for query: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/vector_stores/transformation.py","lineNumber":158,"sourceCode":"                \"Example: litellm_params['embedding_config'] = {'api_base': 'https://krris-mh44uf7y-eastus2.cognitiveservices.azure.com/', 'api_key': 'os.environ/AZURE_API_KEY', 'api_version': '2025-09-01'}\"\n            )\n\n        # Get vector field name (defaults to contentVector)\n        vector_field: Final = litellm_params.get(\"azure_search_vector_field\", \"contentVector\")\n\n        # Get top_k (number of results to return)\n        top_k: Final = vector_store_search_optional_params.get(\"top_k\", 10)\n\n        # Generate embedding for the query using litellm.embeddings\n        try:\n            embedding_response: Final = litellm.embedding(\n                model=embedding_model,\n                input=[query],\n                **embedding_config,\n            )\n            query_vector: Final = embedding_response.data[0][\"embedding\"]\n        except Exception as e:\n            raise Exception(f\"Failed to generate embedding for query: {e}\")\n\n        # Azure AI Search endpoint for search\n        index_name: Final = vector_store_id  # vector_store_id is the index name\n        url: Final = f\"{api_base}/indexes/{index_name}/docs/search?api-version=2024-07-01\"\n\n        # Build the request body for Azure AI Search with vector search\n        request_body: Final = {\n            \"search\": \"*\",  # Get all documents (filtered by vector similarity)\n            \"vectorQueries\": [\n                {\n                    \"vector\": query_vector,\n                    \"fields\": vector_field,\n                    \"kind\": \"vector\",\n                    \"k\": top_k,  # Number of nearest neighbors to return\n                }\n            ],\n            \"select\": \"id,content\",  # Fields to return (customize based on schema)\n            \"top\": top_k,","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/vector_stores/transformation.py#L140-L176","documentation":"This is a wrapper exception: the search transform calls litellm.embedding(model=embedding_model, input=[query], **embedding_config), and any failure inside that embedding call (auth, bad deployment name, wrong api_version, network) is caught and re-raised as 'Failed to generate embedding for query: <original error>'. The root cause is in the appended message.","triggerScenarios":"Wrong embedding api_base/api_key in litellm_embedding_config; embedding deployment name not matching the model string; api_version rejected by the endpoint; per-call rate limits or throttling during search. The original exception text after the colon identifies which.","commonSituations":"Embedding deployment in a different Azure resource than configured; key rotated in the portal but not in config; using an OpenAI model string with Azure-style config or vice versa; hitting token limits with a very long query.","solutions":["Read the wrapped error after 'Failed to generate embedding for query:' — fix that underlying cause (401 => key, 404 => deployment name/base, 400 => api_version)","Test the embedding in isolation: litellm.embedding(model=emb_model, input=['ping'], **emb_config)","Verify the deployment name in Azure AI Foundry matches the model string after the '/' exactly","For throttling, retry with backoff or raise TPM limits on the deployment"],"exampleFix":"# before\nlitellm_embedding_config={'api_base': 'https://wrong-resource.cognitiveservices.azure.com/', 'api_key': key}\n\n# after\nlitellm_embedding_config={'api_base': 'https://correct-resource.cognitiveservices.azure.com/', 'api_key': key, 'api_version': '2025-09-01'}","handlingStrategy":"retry","validationCode":"try:\n    litellm.embedding(model=emb_model, input=['ping'], **emb_config)\nexcept Exception as e:\n    raise RuntimeError(f'Embedding precheck failed: {e}')","typeGuard":null,"tryCatchPattern":"try:\n    results = vector_store.search(vector_store_id=idx, query=q)\nexcept Exception as e:\n    if 'Failed to generate embedding for query' in str(e):\n        # inspect inner cause; retry on throttling, fix config on auth/404\n        if '429' in str(e) or 'throttl' in str(e).lower():\n            time.sleep(backoff); results = vector_store.search(vector_store_id=idx, query=q)\n        else:\n            raise","preventionTips":["Precheck embedding connectivity before enabling vector search","Parse the inner exception message to distinguish auth/deployment/throttle causes"],"tags":["azure","vector-stores","embeddings","wrapper-exception"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}