Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions docs/code_samples/default_v2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ public class SimpleMindeeClient {

// Set inference parameters
// Note: modelId is mandatory.
InferenceParameters inferenceParams = InferenceParameters.builder(modelId)
// If set to `true`, will enable Retrieval-Augmented Generation.
.rag(false)
InferenceParameters inferenceParams = InferenceParameters
// ID of the model, required.
.builder(modelId)

// Options: set to `true` or `false` to override defaults

// Enhance extraction accuracy with Retrieval-Augmented Generation.
.rag(null)
// Extract the full text content from the document as strings.
.rawText(null)
// Calculate bounding box polygons for all fields.
.polygon(null)
// Boost the precision and accuracy of all extractions.
// Calculate confidence scores for all fields.
.confidence(null)

.build();

// Load a file from disk
Expand Down
50 changes: 45 additions & 5 deletions src/main/java/com/mindee/InferenceParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@ public final class InferenceParameters {
*/
private final String modelId;
/**
* Enables Retrieval-Augmented Generation (optional, default: {@code false}).
* Enhance extraction accuracy with Retrieval-Augmented Generation.
*/
private final boolean rag;
private final Boolean rag;
/**
* Extract the full text content from the document as strings.
*/
private final Boolean rawText;
/**
* Calculate bounding box polygons for all fields.
*/
private final Boolean polygon;
/**
* Boost the precision and accuracy of all extractions.
* Calculate confidence scores for all fields.
*/
private final Boolean confidence;
/**
* Optional alias for the file.
*/
Expand Down Expand Up @@ -47,7 +60,10 @@ public static Builder builder(String modelId) {
public static final class Builder {

private final String modelId;
private boolean rag = false;
private Boolean rag = null;
private Boolean rawText = null;
private Boolean polygon = null;
private Boolean confidence = null;
private String alias;
private String[] webhookIds = new String[]{};
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();
Expand All @@ -56,12 +72,33 @@ private Builder(String modelId) {
this.modelId = Objects.requireNonNull(modelId, "modelId must not be null");
}

/** Enable / disable Retrieval-Augmented Generation. */
public Builder rag(boolean rag) {
/** Enhance extraction accuracy with Retrieval-Augmented Generation. */
public Builder rag(Boolean rag) {
this.rag = rag;
return this;
}

/** Extract the full text content from the document as strings. */
public Builder rawText(Boolean rawText) {
this.rawText = rawText;
return this;
}

/** Calculate bounding box polygons for all fields. */
public Builder polygon(Boolean polygon) {
this.polygon = polygon;
return this;
}

/**
* Boost the precision and accuracy of all extractions.
* Calculate confidence scores for all fields.
*/
public Builder confidence(Boolean confidence) {
this.confidence = confidence;
return this;
}

/** Set an alias for the uploaded document. */
public Builder alias(String alias) {
this.alias = alias;
Expand All @@ -84,6 +121,9 @@ public InferenceParameters build() {
return new InferenceParameters(
modelId,
rag,
rawText,
polygon,
confidence,
alias,
webhookIds,
pollingOptions
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/mindee/http/MindeeHttpApiV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,17 @@ private HttpEntity buildHttpBody(
}

builder.addTextBody("model_id", params.getModelId());
if (params.isRag()) {
builder.addTextBody("rag", "true");
if (params.getRag() != null) {
builder.addTextBody("rag", params.getRag().toString().toLowerCase());
}
if (params.getRawText() != null) {
builder.addTextBody("raw_text", params.getRawText().toString().toLowerCase());
}
if (params.getPolygon() != null) {
builder.addTextBody("polygon", params.getPolygon().toString().toLowerCase());
}
if (params.getConfidence() != null) {
builder.addTextBody("confidence", params.getConfidence().toString().toLowerCase());
}
if (params.getAlias() != null) {
builder.addTextBody("alias", params.getAlias());
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/mindee/parsing/v2/Inference.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public class Inference {
@JsonProperty("file")
private InferenceFile file;

/**
* Active options for the inference.
*/
@JsonProperty("active_options")
private InferenceActiveOptions activeOptions;

/**
* Model result values.
*/
Expand All @@ -47,12 +53,12 @@ public String toString() {
joiner
.add("Inference")
.add("#########")
.add("Model")
.add("=====")
.add(":ID: " + (model != null ? model.getId() : ""))
.add(model.toString())
.add("")
.add(file.toString())
.add("")
.add(activeOptions.toString())
.add("")
.add(result != null ? result.toString() : "");
return joiner.toString().trim() + "\n";
}
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/com/mindee/parsing/v2/InferenceActiveOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.mindee.parsing.v2;

import static com.mindee.parsing.SummaryHelper.formatForDisplay;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.StringJoiner;

/**
* Option response for V2 API inference.
*/
public final class InferenceActiveOptions {

@JsonProperty("rag")
private boolean rag;

@JsonProperty("raw_text")
private boolean rawText;

@JsonProperty("polygon")
private boolean polygon;

@JsonProperty("confidence")
private boolean confidence;

/**
* Whether the RAG feature was activated.
*/
public boolean getRag() {
return rag;
}

/**
* Whether the Raw Text feature was activated.
*/
public boolean getRawText() {
return rawText;
}

/**
* Whether the polygon feature was activated.
*/
public boolean getPolygon() {
return polygon;
}

/**
* Whether the confidence feature was activated.
*/
public boolean getConfidence() {
return confidence;
}

@Override
public String toString() {
StringJoiner joiner = new StringJoiner("\n");
return joiner
.add("Active Options")
.add("==============")
.add(":Raw Text: " + formatForDisplay(rawText, 5))
.add(":Polygon: " + formatForDisplay(polygon, 5))
.add(":Confidence: " + formatForDisplay(confidence, 5))
.add(":RAG: " + formatForDisplay(rag, 5))
.toString();
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/mindee/parsing/v2/InferenceModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.StringJoiner;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -22,4 +23,13 @@ public class InferenceModel {
*/
@JsonProperty("id")
private String id;

public String toString() {
StringJoiner joiner = new StringJoiner("\n");
return joiner
.add("Model")
.add("=====")
.add(":ID: " + id)
.toString();
}
}
10 changes: 3 additions & 7 deletions src/main/java/com/mindee/parsing/v2/InferenceResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@ public final class InferenceResult {
/**
* Options.
*/
@JsonProperty("options")
private InferenceResultOptions options;
@JsonProperty("raw_text")
private RawText rawText;

@Override
public String toString() {
StringJoiner joiner = new StringJoiner("\n");
joiner.add("Fields")
.add("======");
joiner.add(fields.toString());
if (this.getOptions() != null) {
joiner.add("Options")
.add("=======")
.add(this.getOptions().toString());
}

return joiner.toString();
}
}
15 changes: 0 additions & 15 deletions src/main/java/com/mindee/parsing/v2/InferenceResultOptions.java

This file was deleted.

23 changes: 16 additions & 7 deletions src/main/java/com/mindee/parsing/v2/RawText.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.StringJoiner;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -17,12 +19,19 @@ public class RawText {
/*
* Page Number the text was found on.
*/
@JsonProperty("page")
private Integer page;
@JsonProperty("pages")
private List<RawTextPage> pages;

/*
* Content of the raw text.
*/
@JsonProperty("content")
private String content;
@Override
public String toString() {
if (pages == null || pages.isEmpty()) {
return "";
}
StringJoiner joiner = new StringJoiner("\n\n");
for (RawTextPage page : pages) {
joiner.add(page.toString());
}
return joiner.toString();

}
}
33 changes: 33 additions & 0 deletions src/main/java/com/mindee/parsing/v2/RawTextPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mindee.parsing.v2;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* Raw text extracted from the page.
*/
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
@AllArgsConstructor
@NoArgsConstructor
public class RawTextPage {
/**
* Page content as a single string.
*/
@JsonProperty("content")
private String content;

/**
* Page contents as a string.
*/
@Override
public String toString() {
if (content == null) {
return "";
}
return content;
}
}
Loading
Loading