11import { expect } from "chai" ;
22import path from "node:path" ;
3- import { LocalResponse , InferenceResponse , RawText } from "../../../src" ;
3+ import { LocalResponse , InferenceResponse , RawText , RagMetadata } from "../../../src" ;
44import { FieldConfidence , ListField , ObjectField , SimpleField } from "../../../src/parsing/v2/field" ;
55import { promises as fs } from "node:fs" ;
66import { Polygon } from "../../../src/geometry" ;
@@ -12,20 +12,19 @@ const deepNestedFieldPath = path.join(inferencePath, "deep_nested_fields.json");
1212const standardFieldPath = path . join ( inferencePath , "standard_field_types.json" ) ;
1313const standardFieldRstPath = path . join ( inferencePath , "standard_field_types.rst" ) ;
1414const locationFieldPath = path . join ( findocPath , "complete_with_coordinates.json" ) ;
15- const rawTextPath = path . join ( inferencePath , "raw_texts.json" ) ;
16- const blankPath = path . join ( findocPath , "blank.json" ) ;
17- const completePath = path . join ( findocPath , "complete.json" ) ;
1815
1916async function loadV2Inference ( resourcePath : string ) : Promise < InferenceResponse > {
2017 const localResponse = new LocalResponse ( resourcePath ) ;
2118 await localResponse . init ( ) ;
2219 return localResponse . deserializeResponse ( InferenceResponse ) ;
2320}
2421
25- describe ( "inference " , async ( ) => {
26- describe ( "simple " , async ( ) => {
22+ describe ( "MindeeV2 - Inference Response " , async ( ) => {
23+ describe ( "Financial Document " , async ( ) => {
2724 it ( "should load a blank inference with valid properties" , async ( ) => {
28- const response = await loadV2Inference ( blankPath ) ;
25+ const response = await loadV2Inference (
26+ path . join ( findocPath , "blank.json" )
27+ ) ;
2928 const fields = response . inference . result . fields ;
3029
3130 expect ( fields ) . to . be . not . empty ;
@@ -55,7 +54,9 @@ describe("inference", async () => {
5554 } ) ;
5655
5756 it ( "should load a complete inference with valid properties" , async ( ) => {
58- const response = await loadV2Inference ( completePath ) ;
57+ const response = await loadV2Inference (
58+ path . join ( findocPath , "complete.json" )
59+ ) ;
5960 const inference = response . inference ;
6061
6162 expect ( inference ) . to . not . be . undefined ;
@@ -116,7 +117,7 @@ describe("inference", async () => {
116117 } ) ;
117118 } ) ;
118119
119- describe ( "nested " , async ( ) => {
120+ describe ( "Deeply Nested " , async ( ) => {
120121 it ( "should load a deep nested object" , async ( ) => {
121122 const response = await loadV2Inference ( deepNestedFieldPath ) ;
122123 const fields = response . inference . result . fields ;
@@ -152,7 +153,7 @@ describe("inference", async () => {
152153 } ) ;
153154 } ) ;
154155
155- describe ( "standard field types " , async ( ) => {
156+ describe ( "Standard Field Types " , async ( ) => {
156157 it ( "should recognize simple fields" , async ( ) => {
157158 const response = await loadV2Inference ( standardFieldPath ) ;
158159 const fields = response . inference . result . fields ;
@@ -259,11 +260,14 @@ describe("inference", async () => {
259260 } ) ;
260261 } ) ;
261262
262- describe ( "raw text " , async ( ) => {
263+ describe ( "Raw Text " , async ( ) => {
263264 it ( "raw text should be exposed" , async ( ) => {
264- const response = await loadV2Inference ( rawTextPath ) ;
265- const rawText = response . inference . result . rawText ;
265+ const response = await loadV2Inference (
266+ path . join ( inferencePath , "raw_texts.json" )
267+ ) ;
268+ expect ( response . inference . result . rag ) . to . be . undefined ;
266269
270+ const rawText = response . inference . result . rawText ;
267271 expect ( rawText ) . to . be . instanceOf ( RawText ) ;
268272
269273 const pages = rawText ?. pages ;
@@ -275,7 +279,18 @@ describe("inference", async () => {
275279 } ) ;
276280 } ) ;
277281
278- describe ( "rst display" , async ( ) => {
282+ describe ( "RAG Metadata" , async ( ) => {
283+ it ( "RAG metadata should be exposed" , async ( ) => {
284+ const response = await loadV2Inference (
285+ path . join ( inferencePath , "rag_matched.json" )
286+ ) ;
287+ const rag = response . inference . result . rag ;
288+ expect ( rag ) . to . be . instanceOf ( RagMetadata ) ;
289+ expect ( rag ?. retrievedDocumentId ) . to . eq ( "12345abc-1234-1234-1234-123456789abc" ) ;
290+ } ) ;
291+ } ) ;
292+
293+ describe ( "RST Display" , async ( ) => {
279294 it ( "to be properly exposed" , async ( ) => {
280295 const response = await loadV2Inference ( standardFieldPath ) ;
281296 const rstString = await fs . readFile ( standardFieldRstPath , "utf8" ) ;
@@ -285,7 +300,7 @@ describe("inference", async () => {
285300 } ) . timeout ( 10000 ) ;
286301 } ) ;
287302
288- describe ( "field locations and confidence " , async ( ) => {
303+ describe ( "Field Locations and Confidence " , async ( ) => {
289304 it ( "to be properly exposed" , async ( ) => {
290305 const response = await loadV2Inference ( locationFieldPath ) ;
291306
0 commit comments