Get KeyValuePairs when using modelId="prebuilt-invoice".

Andreas Palm Sivertsen 0 Reputation points
2023-11-14T15:37:56.49+00:00

Hello :)

DocumentAnalysisClient client = new DocumentAnalysisClientBuilder()
	.credential(new AzureKeyCredential(apiKey))
	.endpoint(endpoint)
	.buildClient();
SyncPoller<OperationResult, AnalyzeResult> analyzeInvoicePoller = client.beginAnalyzeDocumentFromUrl("prebuilt-invoice", url);
AnalyzeResult analyzeInvoiceResult = analyzeInvoicePoller.getFinalResult();
List<DocumentKeyValuePair> kartList = analyzeInvoiceResult.getKeyValuePairs();

List of KeyValuePairs is null when the modelId provided is "prebuilt-invoice", but is the actual key value pairs I am after when modelId="prebuilt-document". Is there a way to get key value pairs AND the processed fields you get from the prebuilt invoice model.

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,716 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,902 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VasaviLankipalle-MSFT 17,641 Reputation points
    2023-11-15T23:09:50+00:00

    Hello @Andreas Palm Sivertsen , Thanks for using Microsoft Q&A Platform.

    The key-value pairs are supported for the prebuilt-invoice model. However, to get a better understanding of the features available for each model, I recommend visiting the Analysis feature table. This table provides a comprehensive overview of the features available for each model, including prebuilt and custom models.

    I have reproduced, and the key-values pair are generated. Here is the sample python code snippet for the pre-built invoice model to print the key-value pairs of the analyze result: https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/quickstarts/get-started-sdks-rest-api?view=doc-intel-4.0.0&preserve-view=true&pivots=programming-language-python

    for kv_pair in invoices.key_value_pairs:
        if kv_pair.key:
            print(
                "Key '{}' found within '{}' bounding regions".format(kv_pair.key.content,
                        format_bounding_region(kv_pair.key.bounding_regions),
                )
            )
        if kv_pair.value:
            print(
                "Value '{}' found within '{}' bounding regions\n".format(kv_pair.value.content,
                        format_bounding_region(kv_pair.value.bounding_regions),
                )
            )
    
    
    

    Result:User's image

    I hope this helps.

    Regards,
    Vasavi

    -Please kindly accept the answer and vote 'yes' if you feel helpful to support the community, thanks.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.