Registry / azure / azure-ai-language-questionanswering

azure-ai-language-questionanswering

JSON →
library1.1.0pypypi✓ verified 84d ago

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
INSTALL
IMPORT
SIG · AZURE-AI-LANGUAGE-
A
azure-ai-language-questionanswering
azurepythonv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

QuestionAnsweringClient
from azure.ai.language.questionanswering import QuestionAnsweringClient
from azure.ai.language.questionanswering.models import QuestionAnsweringClient
Client class is in the top-level module, not models
AnswersFromTextOptions
from azure.ai.language.questionanswering.models import AnswersFromTextOptions
from azure.ai.language.questionanswering import AnswersFromTextOptions
Model classes are under .models
AnswersOptions
from azure.ai.language.questionanswering.models import AnswersOptions

Authenticate using endpoint and key, then query a knowledge base.

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)
Debug
Known issues
breakingIn 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.
affects: <1.1.0 -> 1.1.0
deprecatedThe `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.
affects: <=1.1.0
gotchaBoth `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.
affects: all
gotchaWhen 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`.
affects: all
Errors
Common errors & fixes
AttributeError: 'QuestionAnsweringClient' object has no attribute 'get_answers'
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.
azure.core.exceptions.ResourceNotFoundError: (NotFound) The specified project does not exist.
`project_name` or `deployment_name` missing or incorrect
fix
Ensure both parameters are provided and match exactly the names in Azure AI Language resource.
TypeError: get_answers() got an unexpected keyword argument 'top'
Using `top` parameter which was renamed to `top_answers` in version 1.1.0
fix
Replace `top` with `top_answers` in the call.
Upgrade
Version history
1.1.0latest on PyPI · released Oct 13, 2022
Audit
Dependencies
azure-corerequiredHTTP pipeline and authentication
azure-identityoptionalDefaultAzureCredential for auth
Agent activity
46 hits · last 30 days
node
38
OpenAI (training)
1
Resources
azure-ai-language-questionanswering — pip install azure-ai-language-questionanswering · libregistry