azure-ai-formrecognizer-java
द्वारा microsoft
रीब्रांडिंग: Azure AI Form Recognizer अब Azure AI Document Intelligence है। नए प्रोजेक्ट्स को com.azure:azure-ai-documentintelligence का उपयोग करना चाहिए। लीगेसी azure-ai-formrecognizer पैकेज केवल API संस्करण 2023-07-31 को लक्षित करता है। माइग्रेशन गाइड देखें।
npx skills add https://github.com/microsoft/skills --skill azure-ai-formrecognizer-javaAzure AI Document Intelligence SDK for Java
Rebranding: Azure AI Form Recognizer is now Azure AI Document Intelligence. New projects should use
com.azure:azure-ai-documentintelligence. The legacyazure-ai-formrecognizerpackage targets API version 2023-07-31 only. See Migration Guide.
Before Implementation
Search microsoft-docs MCP for current API patterns:
- Query:
"azure-ai-documentintelligence Java SDK" - Verify: Parameters match installed SDK version (latest GA: 1.0.7)
Installation
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-documentintelligence</artifactId>
<version>1.0.0</version>
</dependency>
<!-- For DefaultAzureCredential -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.14.2</version>
</dependency>
Environment Variables
DOCUMENT_INTELLIGENCE_ENDPOINT=https://<resource>.cognitiveservices.azure.com/ # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
Authentication
DefaultAzureCredential (Recommended)
import com.azure.ai.documentintelligence.DocumentIntelligenceClient;
import com.azure.ai.documentintelligence.DocumentIntelligenceClientBuilder;
import com.azure.core.credential.TokenCredential;
import com.azure.identity.AzureIdentityEnvVars;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.identity.ManagedIdentityCredentialBuilder;
TokenCredential credential = new DefaultAzureCredentialBuilder()
.requireEnvVars(AzureIdentityEnvVars.AZURE_TOKEN_CREDENTIALS)
.build();
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes
// TokenCredential credential = new ManagedIdentityCredentialBuilder().build();
DocumentIntelligenceClient client = new DocumentIntelligenceClientBuilder()
.endpoint(System.getenv("DOCUMENT_INTELLIGENCE_ENDPOINT"))
.credential(credential)
.buildClient();
API Key
import com.azure.core.credential.AzureKeyCredential;
DocumentIntelligenceClient client = new DocumentIntelligenceClientBuilder()
.endpoint(System.getenv("DOCUMENT_INTELLIGENCE_ENDPOINT"))
.credential(new AzureKeyCredential(System.getenv("DOCUMENT_INTELLIGENCE_KEY")))
.buildClient();
Administration Client
import com.azure.ai.documentintelligence.DocumentIntelligenceAdministrationClient;
import com.azure.ai.documentintelligence.DocumentIntelligenceAdministrationClientBuilder;
import com.azure.core.credential.TokenCredential;
import com.azure.identity.AzureIdentityEnvVars;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.identity.ManagedIdentityCredentialBuilder;
TokenCredential credential = new DefaultAzureCredentialBuilder()
.requireEnvVars(AzureIdentityEnvVars.AZURE_TOKEN_CREDENTIALS)
.build();
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes
// TokenCredential credential = new ManagedIdentityCredentialBuilder().build();
DocumentIntelligenceAdministrationClient adminClient = new DocumentIntelligenceAdministrationClientBuilder()
.endpoint(System.getenv("DOCUMENT_INTELLIGENCE_ENDPOINT"))
.credential(credential)
.buildClient();
Async Client
import com.azure.ai.documentintelligence.DocumentIntelligenceAsyncClient;
import com.azure.core.credential.TokenCredential;
import com.azure.identity.AzureIdentityEnvVars;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.identity.ManagedIdentityCredentialBuilder;
TokenCredential credential = new DefaultAzureCredentialBuilder()
.requireEnvVars(AzureIdentityEnvVars.AZURE_TOKEN_CREDENTIALS)
.build();
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes
// TokenCredential credential = new ManagedIdentityCredentialBuilder().build();
DocumentIntelligenceAsyncClient asyncClient = new DocumentIntelligenceClientBuilder()
.endpoint(System.getenv("DOCUMENT_INTELLIGENCE_ENDPOINT"))
.credential(credential)
.buildAsyncClient();
Prebuilt Models
| Model ID | Purpose |
|---|---|
prebuilt-read | Extract text, lines, words, languages |
prebuilt-layout | Text, tables, selection marks, structure |
prebuilt-receipt | Receipt data extraction |
prebuilt-invoice | Invoice field extraction |
prebuilt-idDocument | ID documents (passport, license) |
prebuilt-tax.us.w2 | US W2 tax forms |
prebuilt-healthInsuranceCard.us | US health insurance cards |
prebuilt-contract | Contract field extraction |
Retired models:
prebuilt-businessCardandprebuilt-documentare retired in API version 2024-11-30. Use the legacyazure-ai-formrecognizerpackage for these.
Core Patterns
Analyze from File
import com.azure.ai.documentintelligence.models.*;
import com.azure.core.util.BinaryData;
import com.azure.core.util.polling.SyncPoller;
import java.io.File;
File document = new File("document.pdf");
BinaryData documentData = BinaryData.fromFile(document.toPath(), (int) document.length());
SyncPoller<AnalyzeOperationDetails, AnalyzeResult> poller =
client.beginAnalyzeDocument("prebuilt-layout",
new AnalyzeDocumentOptions(documentData));
AnalyzeResult result = poller.getFinalResult();
Analyze from URL
String documentUrl = "https://example.com/invoice.pdf";
SyncPoller<AnalyzeOperationDetails, AnalyzeResult> poller =
client.beginAnalyzeDocument("prebuilt-invoice",
new AnalyzeDocumentOptions(documentUrl));
AnalyzeResult result = poller.getFinalResult();
Extract Layout
AnalyzeResult result = poller.getFinalResult();
for (DocumentPage page : result.getPages()) {
System.out.printf("Page has width: %.2f and height: %.2f, measured with unit: %s%n",
page.getWidth(), page.getHeight(), page.getUnit());
// Lines
for (DocumentLine line : page.getLines()) {
System.out.printf("Line '%s' is within bounding box %s.%n",
line.getContent(), line.getPolygon());
}
// Selection marks
for (DocumentSelectionMark mark : page.getSelectionMarks()) {
System.out.printf("Selection mark is '%s' with confidence %.2f.%n",
mark.getState(), mark.getConfidence());
}
}
// Tables
for (DocumentTable table : result.getTables()) {
System.out.printf("Table: %d rows x %d columns%n",
table.getRowCount(), table.getColumnCount());
for (DocumentTableCell cell : table.getCells()) {
System.out.printf("Cell[%d,%d]: %s%n",
cell.getRowIndex(), cell.getColumnIndex(), cell.getContent());
}
}
Extract Document Fields
SyncPoller<AnalyzeOperationDetails, AnalyzeResult> poller =
client.beginAnalyzeDocument("prebuilt-receipt",
new AnalyzeDocumentOptions(receiptUrl));
AnalyzeResult result = poller.getFinalResult();
for (AnalyzedDocument doc : result.getDocuments()) {
Map<String, DocumentField> fields = doc.getFields();
DocumentField merchantName = fields.get("MerchantName");
if (merchantName != null && merchantName.getType() == DocumentFieldType.STRING) {
System.out.printf("Merchant: %s (confidence: %.2f)%n",
merchantName.getValueString(), merchantName.getConfidence());
}
DocumentField transactionDate = fields.get("TransactionDate");
if (transactionDate != null && transactionDate.getType() == DocumentFieldType.DATE) {
System.out.printf("Date: %s%n", transactionDate.getValueDate());
}
}
Analyze with Options
SyncPoller<AnalyzeOperationDetails, AnalyzeResult> poller =
client.beginAnalyzeDocument("my-custom-model",
new AnalyzeDocumentOptions(documentUrl)
.setPages(Collections.singletonList("1-3"))
.setLocale("en-US")
.setDocumentAnalysisFeatures(Arrays.asList(DocumentAnalysisFeature.LANGUAGES))
.setOutputContentFormat(DocumentContentFormat.TEXT));
Custom Models
Build Custom Model
String blobContainerUrl = "{SAS_URL_of_training_data}";
SyncPoller<DocumentModelBuildOperationDetails, DocumentModelDetails> poller =
adminClient.beginBuildDocumentModel(
new BuildDocumentModelOptions("my-custom-model", DocumentBuildMode.TEMPLATE)
.setAzureBlobSource(new AzureBlobContentSource(blobContainerUrl)));
DocumentModelDetails model = poller.getFinalResult();
System.out.printf("Model ID: %s%n", model.getModelId());
System.out.printf("Created: %s%n", model.getCreatedOn());
model.getDocumentTypes().forEach((docType, details) -> {
details.getFieldSchema().forEach((field, schema) -> {
System.out.printf("Field: %s (%s)%n", field, schema.getType());
});
});
Manage Models
// Resource limits
DocumentIntelligenceResourceDetails resourceDetails = adminClient.getResourceDetails();
System.out.printf("Models: %d / %d%n",
resourceDetails.getCustomDocumentModels().getCount(),
resourceDetails.getCustomDocumentModels().getLimit());
// List models
PagedIterable<DocumentModelDetails> models = adminClient.listModels();
for (DocumentModelDetails model : models) {
System.out.printf("Model: %s, Created: %s%n",
model.getModelId(), model.getCreatedOn());
}
// Get model
DocumentModelDetails model = adminClient.getModel("model-id");
// Delete model
adminClient.deleteModel("model-id");
Document Classification
Build Classifier
Map<String, ClassifierDocumentTypeDetails> docTypes = new HashMap<>();
docTypes.put("invoice", new ClassifierDocumentTypeDetails()
.setAzureBlobSource(new AzureBlobContentSource(containerUrl).setPrefix("invoices/")));
docTypes.put("receipt", new ClassifierDocumentTypeDetails()
.setAzureBlobSource(new AzureBlobContentSource(containerUrl).setPrefix("receipts/")));
SyncPoller<DocumentClassifierBuildOperationDetails, DocumentClassifierDetails> poller =
adminClient.beginBuildClassifier(
new BuildDocumentClassifierOptions("my-classifier", docTypes));
DocumentClassifierDetails classifier = poller.getFinalResult();
Classify Document
SyncPoller<AnalyzeOperationDetails, AnalyzeResult> poller =
client.beginClassifyDocument("my-classifier",
new ClassifyDocumentOptions(documentUrl));
AnalyzeResult result = poller.getFinalResult();
for (AnalyzedDocument doc : result.getDocuments()) {
System.out.printf("Classified as: %s (confidence: %.2f)%n",
doc.getDocumentType(), doc.getConfidence());
}
Error Handling
import com.azure.core.exception.HttpResponseException;
try {
client.beginAnalyzeDocument("prebuilt-receipt",
new AnalyzeDocumentOptions("invalid-url"));
} catch (HttpResponseException e) {
System.out.printf("Status: %d, Error: %s%n",
e.getResponse().getStatusCode(), e.getMessage());
}
Migration from azure-ai-formrecognizer
| Old (formrecognizer v4.x) | New (documentintelligence v1.x) |
|---|---|
DocumentAnalysisClient | DocumentIntelligenceClient |
DocumentAnalysisClientBuilder | DocumentIntelligenceClientBuilder |
DocumentModelAdministrationClient | DocumentIntelligenceAdministrationClient |
beginAnalyzeDocumentFromUrl(modelId, url) | beginAnalyzeDocument(modelId, new AnalyzeDocumentOptions(url)) |
beginAnalyzeDocument(modelId, data) | beginAnalyzeDocument(modelId, new AnalyzeDocumentOptions(data)) |
SyncPoller<OperationResult, AnalyzeResult> | SyncPoller<AnalyzeOperationDetails, AnalyzeResult> |
field.getValueAsString() | field.getValueString() |
field.getValueAsDate() | field.getValueDate() |
field.getValueAsDouble() | field.getValueNumber() |
field.getValueAsList() | field.getValueList() |
field.getValueAsMap() | field.getValueObject() |
mark.getSelectionMarkState() | mark.getState() |
adminClient.beginBuildDocumentModel(url, mode, prefix, options, ctx) | adminClient.beginBuildDocumentModel(new BuildDocumentModelOptions(id, mode).setAzureBlobSource(...)) |
adminClient.getResourceDetails() → .getCustomDocumentModelCount() | adminClient.getResourceDetails() → .getCustomDocumentModels().getCount() |
FORM_RECOGNIZER_ENDPOINT | DOCUMENT_INTELLIGENCE_ENDPOINT |
Reference Files
| File | Contents |
|---|---|
| references/examples.md | Complete code examples for all scenarios |
microsoft की और Skills
oss-growth
microsoft
OSS ग्रोथ हैकर व्यक्तित्व
official
microsoft-foundry
microsoft
Foundry एजेंटों को एंड-टू-एंड डिप्लॉय, मूल्यांकन और प्रबंधित करें: Docker बिल्ड, ACR पुश, होस्टेड/प्रॉम्प्ट एजेंट क्रिएट, कंटेनर स्टार्ट, बैच इवैल्यूएशन, कंटीन्यूअस इवैल्यूएशन, प्रॉम्प्ट ऑप्टिमाइज़र वर्कफ़्लो, agent.yaml, ट्रेस से डेटासेट क्यूरेशन। इसका उपयोग करें: Foundry पर एजेंट डिप्लॉय करना, होस्टेड एजेंट, एजेंट बनाना, एजेंट को इनवोक करना, एजेंट का मूल्यांकन
officialdevelopmentdevops
azure-ai
microsoft
Azure AI के लिए उपयोग करें: खोज, वाक्, OpenAI, दस्तावेज़ बुद्धिमत्ता। खोज, वेक्टर/हाइब्रिड खोज, वाक्-से-पाठ, पाठ-से-वाक्, प्रतिलेखन, OCR में सहायता करता है। कब उपयोग करें: AI खोज, क्वेरी खोज, वेक्टर खोज, हाइब्रिड खोज, सिमैंटिक खोज, वाक्-से-पाठ, पाठ-से-वाक्, प्रतिलेखन, OCR, पाठ को वाक् में बदलना।
officialdevelopmentapi
azure-deploy
microsoft
पहले से तैयार एप्लिकेशनों के लिए Azure डिप्लॉयमेंट निष्पादित करें जिनमें मौजूदा .azure/deployment-plan.md और इंफ्रास्ट्रक्चर फ़ाइलें हों। इस स्किल का उपयोग तब न करें जब उपयोगकर्ता कोई नया एप्लिकेशन बनाने के लिए कहे — इसके बजाय azure-prepare का उपयोग करें। यह स्किल azd up, azd deploy, terraform apply, और az deployment कमांड को बिल्ट-इन एरर रिकवरी के साथ चलाती है। इसके लिए azure-prepare से .azure/deployment-plan.md और azure-validate से सत्यापित स्थिति आवश्यक है। कब: "azd
officialdevopsaws
azure-storage
microsoft
Azure Storage सेवाएँ जिनमें Blob Storage, File Shares, Queue Storage, Table Storage और Data Lake शामिल हैं। स्टोरेज एक्सेस टियर (हॉट, कूल, कोल्ड, आर्काइव), प्रत्येक टियर का उपयोग कब करें और टियर तुलना के बारे में प्रश्नों के उत्तर देता है। ऑब्जेक्ट स्टोरेज, SMB फ़ाइल शेयर, एसिंक्रोनस मैसेजिंग, NoSQL की-वैल्यू और बिग डेटा एनालिटिक्स प्रदान करता है। लाइफसाइकिल प्रबंधन शामिल है। उपयोग करें: ब्लॉब स्टोरेज, फ़ाइल शेयर, क्य
officialdevelopmentdatabase
azure-diagnostics
microsoft
Azure पर AppLens, Azure Monitor, संसाधन स्वास्थ्य और सुरक्षित ट्राइएज का उपयोग करके Azure उत्पादन समस्याओं को डीबग करें। कब: उत्पादन समस्याओं को डीबग करना, ऐप सेवा समस्या निवारण, ऐप सेवा उच्च CPU, ऐप सेवा परिनियोजन विफलता, कंटेनर ऐप्स समस्या निवारण, फंक्शन्स समस्या निवारण, AKS समस्या निवारण, kubectl कनेक्ट नहीं हो सकता, kube-system/CoreDNS विफलताएँ, पॉड लंबित, क्रैशलूप, नोड तैयार नहीं, अपग्रेड विफ
officialdevopsdevelopment
azure-prepare
microsoft
Azure ऐप्स को तैनाती के लिए तैयार करें (infra Bicep/Terraform, azure.yaml, Dockerfiles)। निर्माण/आधुनिकीकरण या निर्माण+तैनाती के लिए उपयोग करें; क्रॉस-क्लाउड माइग्रेशन के लिए नहीं (azure-cloud-migrate का उपयोग करें)। इसका उपयोग न करें: copilot-sdk ऐप्स के लिए (azure-hosted-copilot-sdk का उपयोग करें)। कब: "create app", "build web app", "create API", "create serverless HTTP API", "create frontend", "create back end", "build a service", "modernize application", "update application", "add authentication", "add caching", "host on Azure", "create and...
officialdevelopmentdevops
azure-validate
microsoft
Azure तैनाती-पूर्व तत्परता के लिए सत्यापन। तैनाती से पहले कॉन्फ़िगरेशन, इंफ्रास्ट्रक्चर (Bicep या Terraform), RBAC भूमिका असाइनमेंट, प्रबंधित पहचान अनुमतियाँ और पूर्वापेक्षाओं की गहन जाँच करें। कब: मेरे ऐप को सत्यापित करें, तैनाती तत्परता की जाँच करें, प्रीफ्लाइट जाँच चलाएँ, कॉन्फ़िगरेशन सत्यापित करें, तैनाती के लिए तैयार है या नहीं जाँचें, azure.yaml सत्यापित करें, Bicep सत्यापित
officialdevopstesting