[错误]: 使用 AzureOpenAI 进行嵌入时,还需要提供 `azure_deployment`
作者: pavlovmilen创建于 2024年2月24日更新于 2026年9月24日
标签buggood first issue
What happened?
As a chromadb user, when I use Azure Open AI, I want to be able to use my embedding function with collection creation, but currently it does not let me specify azure_deployment so it throws DeploymentNotFound exception (see logs):
my_azure_openai_ef= embedding_functions.OpenAIEmbeddingFunction(
api_key=OPEN_AI_API_KEY,
model_name="text-embedding-ada-002",
api_base="https://my_azure_open_ai_endpoint.OpenAI.Azure.com",
api_type="Azure",
api_version="2023-05-15",
)
`client.get_or_create_collection("my_collection", embedding_function=my_azure_openai_ef)`
In embedding_functions.py there is a code execution path that gets triggered when `api_type="Azure"` self._client = OpenAI.AzureOpenAI(
api_key=api_key,
api_version=api_version,
azure_endpoint=api_base,
default_headers=default_headers,
).embeddings
The issue is that it is missing azure_deployment="your_deployment_name_here"
Without it my Azure deployment cannot be reached. See attached log for more details
To test it I have this setup:
client = AzureOpenAI(
api_key=OPEN_AI_API_KEY,
azure_endpoint="https://my_azure_open_ai_endpoint.OpenAI.Azure.com",
azure_deployment="my_azure_open_ai_deployment",
api_version="2023-05-15")
def text_embedding(text):
response = client.embeddings.create(model="text-embedding-ada-002", input=[text])
return response.data[0].embedding
When I skip `azure_deployment="my_azure_open_ai_deployment",` my text embedding function throws not found exception. Azure Open AI endpoints need the deployment name in order for it to work. See https://GitHub.com/OpenAI/OpenAI-Python?tab=readme-ov-file#microsoft-Azure-OpenAI for more details
Also can you update docs to include link to api versioning in Azure:
https://Azure.com/ZZTERM22ZZ/ZZTERM23ZZ-ZZTERM24ZZ?tab=readme-ov-file#microsoft-ZZTERM25ZZ-ZZTERM26ZZ
### Versions
ChromaDB 0.4.21, Python 3.11.5
### Relevant log output
```shell
Cell In[2], line 14
13 def text_embedding(text):
---> 14 response = client.embeddings.create(model="text-embedding-ada-002", input=[text])
15 return response.data[0].embedding
File c:\Python\Lib\site-packages\OpenAI\resources\embeddings.py:113, in Embeddings.create(self, input, model, dimensions, encoding_format, user, extra_headers, extra_query, extra_body, timeout)
107 embedding.embedding = np.frombuffer( # type: ignore[no-untyped-call]
108 base64.b64decode(data), dtype="float32"
109 ).tolist()
111 return obj
--> 113 return self._post(
114 "/embeddings",
115 body=maybe_transform(params, embedding_create_params.EmbeddingCreateParams),
116 options=make_request_options(
...
...内容来源: chroma-core/chroma