Skip to content

Commit 18b7378

Browse files
committed
✨ add new options to inference parameters
1 parent 1fbde68 commit 18b7378

File tree

5 files changed

+133
-44
lines changed

5 files changed

+133
-44
lines changed

docs/code_samples/default_v2.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,22 @@ public class SimpleMindeeClient {
1919

2020
// Set inference parameters
2121
// Note: modelId is mandatory.
22-
InferenceParameters inferenceParams = InferenceParameters.builder(modelId)
23-
// If set to `true`, will enable Retrieval-Augmented Generation.
24-
.rag(false)
22+
InferenceParameters inferenceParams = InferenceParameters
23+
// ID of the model, required.
24+
.builder(modelId)
25+
26+
// Options: set to `true` or `false` to override defaults
27+
28+
// Enhance extraction accuracy with Retrieval-Augmented Generation.
29+
.rag(null)
30+
// Extract the full text content from the document as strings.
31+
.rawText(null)
32+
// Calculate bounding box polygons for all fields.
33+
.polygon(null)
34+
// Boost the precision and accuracy of all extractions.
35+
// Calculate confidence scores for all fields.
36+
.confidence(null)
37+
2538
.build();
2639

2740
// Load a file from disk

src/main/java/com/mindee/InferenceParameters.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@ public final class InferenceParameters {
1515
*/
1616
private final String modelId;
1717
/**
18-
* Enables Retrieval-Augmented Generation (optional, default: {@code false}).
18+
* Enhance extraction accuracy with Retrieval-Augmented Generation.
1919
*/
20-
private final boolean rag;
20+
private final Boolean rag;
21+
/**
22+
* Extract the full text content from the document as strings.
23+
*/
24+
private final Boolean rawText;
25+
/**
26+
* Calculate bounding box polygons for all fields.
27+
*/
28+
private final Boolean polygon;
29+
/**
30+
* Boost the precision and accuracy of all extractions.
31+
* Calculate confidence scores for all fields.
32+
*/
33+
private final Boolean confidence;
2134
/**
2235
* Optional alias for the file.
2336
*/
@@ -47,7 +60,10 @@ public static Builder builder(String modelId) {
4760
public static final class Builder {
4861

4962
private final String modelId;
50-
private boolean rag = false;
63+
private Boolean rag = null;
64+
private Boolean rawText = null;
65+
private Boolean polygon = null;
66+
private Boolean confidence = null;
5167
private String alias;
5268
private String[] webhookIds = new String[]{};
5369
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();
@@ -56,12 +72,33 @@ private Builder(String modelId) {
5672
this.modelId = Objects.requireNonNull(modelId, "modelId must not be null");
5773
}
5874

59-
/** Enable / disable Retrieval-Augmented Generation. */
60-
public Builder rag(boolean rag) {
75+
/** Enhance extraction accuracy with Retrieval-Augmented Generation. */
76+
public Builder rag(Boolean rag) {
6177
this.rag = rag;
6278
return this;
6379
}
6480

81+
/** Extract the full text content from the document as strings. */
82+
public Builder rawText(Boolean rawText) {
83+
this.rawText = rawText;
84+
return this;
85+
}
86+
87+
/** Calculate bounding box polygons for all fields. */
88+
public Builder polygon(Boolean polygon) {
89+
this.polygon = polygon;
90+
return this;
91+
}
92+
93+
/**
94+
* Boost the precision and accuracy of all extractions.
95+
* Calculate confidence scores for all fields.
96+
*/
97+
public Builder confidence(Boolean confidence) {
98+
this.confidence = confidence;
99+
return this;
100+
}
101+
65102
/** Set an alias for the uploaded document. */
66103
public Builder alias(String alias) {
67104
this.alias = alias;
@@ -84,6 +121,9 @@ public InferenceParameters build() {
84121
return new InferenceParameters(
85122
modelId,
86123
rag,
124+
rawText,
125+
polygon,
126+
confidence,
87127
alias,
88128
webhookIds,
89129
pollingOptions

src/main/java/com/mindee/http/MindeeHttpApiV2.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,17 @@ private HttpEntity buildHttpBody(
259259
}
260260

261261
builder.addTextBody("model_id", params.getModelId());
262-
if (params.isRag()) {
263-
builder.addTextBody("rag", "true");
262+
if (params.getRag() != null) {
263+
builder.addTextBody("rag", params.getRag().toString().toLowerCase());
264+
}
265+
if (params.getRawText() != null) {
266+
builder.addTextBody("raw_text", params.getRawText().toString().toLowerCase());
267+
}
268+
if (params.getPolygon() != null) {
269+
builder.addTextBody("polygon", params.getPolygon().toString().toLowerCase());
270+
}
271+
if (params.getConfidence() != null) {
272+
builder.addTextBody("confidence", params.getConfidence().toString().toLowerCase());
264273
}
265274
if (params.getAlias() != null) {
266275
builder.addTextBody("alias", params.getAlias());

src/test/java/com/mindee/MindeeClientV2IT.java

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
import com.mindee.http.MindeeHttpExceptionV2;
44
import com.mindee.input.LocalInputSource;
55
import com.mindee.input.URLInputSource;
6+
import com.mindee.parsing.v2.Inference;
67
import com.mindee.parsing.v2.InferenceActiveOptions;
8+
import com.mindee.parsing.v2.InferenceFile;
79
import com.mindee.parsing.v2.InferenceResponse;
10+
import com.mindee.parsing.v2.InferenceResult;
11+
import com.mindee.parsing.v2.RawText;
12+
import com.mindee.parsing.v2.field.InferenceFields;
13+
import com.mindee.parsing.v2.field.SimpleField;
814
import java.io.File;
915
import java.io.IOException;
1016
import org.junit.jupiter.api.*;
@@ -34,6 +40,9 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep
3440
InferenceParameters params = InferenceParameters
3541
.builder(modelId)
3642
.rag(false)
43+
.rawText(true)
44+
.polygon(null)
45+
.confidence(null)
3746
.alias("java-integration-test")
3847
.pollingOptions(
3948
AsyncPollingOptions.builder()
@@ -45,24 +54,33 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep
4554
.build();
4655

4756
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, params);
48-
4957
assertNotNull(response);
50-
assertNotNull(response.getInference());
51-
52-
assertNotNull(response.getInference().getFile());
53-
assertEquals("multipage_cut-2.pdf", response.getInference().getFile().getName());
58+
Inference inference = response.getInference();
59+
assertNotNull(inference);
5460

55-
assertNotNull(response.getInference().getModel());
56-
assertEquals(modelId, response.getInference().getModel().getId());
61+
InferenceFile file = inference.getFile();
62+
assertNotNull(file);
63+
assertEquals("multipage_cut-2.pdf", file.getName());
64+
assertEquals(2, file.getPageCount());
5765

58-
assertNotNull(response.getInference().getResult());
66+
assertNotNull(inference.getModel());
67+
assertEquals(modelId, inference.getModel().getId());
5968

60-
InferenceActiveOptions activeOptions = response.getInference().getActiveOptions();
69+
InferenceActiveOptions activeOptions = inference.getActiveOptions();
6170
assertNotNull(activeOptions);
6271
assertFalse(activeOptions.getRag());
63-
assertFalse(activeOptions.getRawText());
72+
assertTrue(activeOptions.getRawText());
6473
assertFalse(activeOptions.getPolygon());
6574
assertFalse(activeOptions.getConfidence());
75+
76+
InferenceResult result = inference.getResult();
77+
assertNotNull(result);
78+
79+
RawText rawText = result.getRawText();
80+
assertEquals(2, rawText.getPages().size());
81+
82+
InferenceFields fields = result.getFields();
83+
assertNotNull(fields);
6684
}
6785

6886
@Test
@@ -71,35 +89,44 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc
7189
LocalInputSource source = new LocalInputSource(
7290
new File("src/test/resources/products/financial_document/default_sample.jpg"));
7391

74-
InferenceParameters options = InferenceParameters
92+
InferenceParameters params = InferenceParameters
7593
.builder(modelId)
7694
.rag(false)
7795
.alias("java-integration-test")
7896
.build();
7997

80-
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, options);
81-
98+
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, params);
8299
assertNotNull(response);
83-
assertNotNull(response.getInference());
100+
Inference inference = response.getInference();
101+
assertNotNull(inference);
84102

85-
assertNotNull(response.getInference().getFile());
86-
assertEquals("default_sample.jpg", response.getInference().getFile().getName());
87-
88-
assertNotNull(response.getInference().getModel());
89-
assertEquals(modelId, response.getInference().getModel().getId());
90-
91-
assertNotNull(response.getInference().getResult());
92-
assertNotNull(response.getInference().getResult().getFields());
93-
assertNotNull(response.getInference().getResult().getFields().get("supplier_name"));
94-
assertEquals(
95-
"John Smith",
96-
response.getInference()
97-
.getResult()
98-
.getFields()
99-
.get("supplier_name")
100-
.getSimpleField()
101-
.getValue()
102-
);
103+
InferenceFile file = inference.getFile();
104+
assertNotNull(file);
105+
assertEquals("default_sample.jpg", file.getName());
106+
assertEquals(1, file.getPageCount());
107+
108+
assertNotNull(inference.getModel());
109+
assertEquals(modelId, inference.getModel().getId());
110+
111+
InferenceActiveOptions activeOptions = inference.getActiveOptions();
112+
assertNotNull(activeOptions);
113+
assertFalse(activeOptions.getRag());
114+
assertFalse(activeOptions.getRawText());
115+
assertFalse(activeOptions.getPolygon());
116+
assertFalse(activeOptions.getConfidence());
117+
118+
InferenceResult result = inference.getResult();
119+
assertNotNull(result);
120+
121+
RawText rawText = result.getRawText();
122+
assertNull(rawText);
123+
124+
InferenceFields fields = result.getFields();
125+
assertNotNull(fields);
126+
127+
SimpleField supplierName = fields.getSimpleField("supplier_name");
128+
assertNotNull(supplierName);
129+
assertEquals("John Smith", supplierName.getStringValue());
103130
}
104131

105132

src/test/java/com/mindee/parsing/v2/InferenceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ class RawTexts {
451451
@Test
452452
@DisplayName("raw texts option must be parsed and exposed")
453453
void rawTexts_mustBeAccessible() throws IOException {
454-
InferenceResponse resp = loadFromResource("v2/inference/raw_texts.json");
455-
Inference inference = resp.getInference();
454+
InferenceResponse response = loadFromResource("v2/inference/raw_texts.json");
455+
Inference inference = response.getInference();
456456
assertNotNull(inference);
457457

458458
InferenceActiveOptions activeOptions = inference.getActiveOptions();

0 commit comments

Comments
 (0)