Azure AI Language Question Answering
raw JSON → 1.1.0 verified Mon Apr 27 auth: no python
Microsoft Azure Question Answering client library for Python, enabling extraction of answers from custom knowledge bases or FAQ data. Version 1.1.0 supports both custom and prebuilt question answering, with synchronous and asynchronous clients. Released monthly as part of Azure SDK.
pip install azure-ai-language-questionanswering Common errors
error AttributeError: 'QuestionAnsweringClient' object has no attribute 'get_answers' ↓
cause Using an older version of the library (<1.0.0) where method was `query_knowledgebase`
fix
Upgrade to version 1.1.0 and use
get_answers method. error azure.core.exceptions.ResourceNotFoundError: (NotFound) The specified project does not exist. ↓
cause `project_name` or `deployment_name` missing or incorrect
fix
Ensure both parameters are provided and match exactly the names in Azure AI Language resource.
error TypeError: get_answers() got an unexpected keyword argument 'top' ↓
cause Using `top` parameter which was renamed to `top_answers` in version 1.1.0
fix
Replace
top with top_answers in the call. Warnings
breaking In version 1.1.0, the `get_answers` method signature changed: `top` parameter renamed to `top_answers` and `confidence_threshold` renamed to `confidence_score_threshold`. ↓
fix Update calls to use new parameter names.
deprecated The `text_documents` parameter in `get_answers_from_text` is deprecated in favor of `text_documents` as part of `AnswersFromTextOptions`. ↓
fix Use `AnswersFromTextOptions` model to pass text documents.
gotcha Both `project_name` and `deployment_name` are required for custom QnA (non-text queries). Missing them results in a ResourceNotFound error. ↓
fix Ensure both parameters are provided when querying a project.
gotcha When using `get_answers_from_text`, the `text_documents` parameter expects a list of `TextDocument` objects, not raw strings. ↓
fix Import `TextDocument` from models and wrap strings: `from azure.ai.language.questionanswering.models import TextDocument`.
Imports
- QuestionAnsweringClient wrong
from azure.ai.language.questionanswering.models import QuestionAnsweringClientcorrectfrom azure.ai.language.questionanswering import QuestionAnsweringClient - AnswersFromTextOptions wrong
from azure.ai.language.questionanswering import AnswersFromTextOptionscorrectfrom azure.ai.language.questionanswering.models import AnswersFromTextOptions - AnswersOptions
from azure.ai.language.questionanswering.models import AnswersOptions
Quickstart
import os
from azure.ai.language.questionanswering import QuestionAnsweringClient
from azure.core.credentials import AzureKeyCredential
endpoint = os.environ.get('AZURE_QA_ENDPOINT', '')
credential = AzureKeyCredential(os.environ.get('AZURE_QA_KEY', ''))
client = QuestionAnsweringClient(endpoint, credential)
response = client.get_answers(
question="What is a good pet?",
project_name="SampleProject",
deployment_name="production"
)
if response.answers:
print(response.answers[0].answer)