Getting started

Free Tier

Vertesia Semantic Layer is a pay as go service, priced per processed document pages, which comes with a one time 1000 pages free credit.

Once the free tier credit is exhausted, billing must be activated in your vertesia project in order to continue to use the service.

To activate billing, open Vertesia Studio and go to Setting > Billings

Billing

Vertesia Studio

Vertesia Studio makes it very simple to quickly try the semantic layer service with your own content.

First, go to Objects and upload a PDF file.

Upload

Next, open the object by clicking on the name and go to the tab Analyze PDF

Start Processing

Click on Start Processing

Processing

When processing is completed, click on Browse Processing Results to see a visual presentation of the result

Browse Result

Annotated PDF with XML Viewer

Finally, The XML format is now the default text representation of the document and seamlessly replace plain text in prompt templates

Object XML Text

Vertesia SDK

Vertesia Semantic Layer is fully supported by the Vertesia SDK and no more than a few lines of code are required to integrate the service with your own applications.

Look at the quick start documentation to learn how to set up the client.

The first step is to upload our PDF file to Vertesia

import { StreamSource, VertesiaClient } from "@vertesia/client";
import { createReadableStreamFromReadable } from "node-web-stream-adapters";

// Initialize client
const client = new VertesiaClient({
  apikey,
});

const stream = createReadStream(<FILE_PATH>);
const content = new StreamSource(
  createReadableStreamFromReadable(stream),
  path.basename(<FILE_PATH>),
  "application/pdf",
);
const object = await client.objects.create({
  content: content,
});

Next, the transformation to XML can be triggered using the start function.

// Run analysis
const analysisRun = await client.objects.analyze(object.id).start({
  features: [],
});
console.log("Analysis Started", analysisRun);

Processing is asynchronous and the status can be fetched using the getStatus function

let analysisStatus = await client.objects.analyze(object.id).getStatus();
console.log(analysisStatus)

Once processing is done, the complete result can be fetched with the getResult function. Other function are available to only fetch the xml text, the tables or images.

// Get Results
const results = await client.objects.analyze(object.id).getResults();
console.log(results.document);

// Or get individual pieces of information
const xml = await client.objects.analyze(object.id).getXml();
const tables = await client.objects.analyze(object.id).getTables();
const images = await client.objects.analyze(object.id).getImages();
const annotated = await client.objects.analyze(object.id).getAnnotated();

Finally, let's assume the input document is an invoice and we'd like to extract the line items without any information on the layout nor the exact columns headers and order. This can be easily done with the adaptTables function, simply by providing text instructions and the desired output schema.

import { S } from "fluent-json-schema";

const target_schema = S.object()
  .title("Invoice line item schema")
  .description("A line item")
  .prop(
    "line_item_number",
    S.string().description(
      "A simple identifier number for the line item which is unique and incremental",
    ),
  )
  .prop("product_code", S.string())
  .prop("description", S.string())
  .prop("country_of_origin", S.string())
  .prop("quantity", S.number().minimum(0))
  .prop("unit_price", S.number().minimum(0))
  .prop("amount", S.number().minimum(0))
  .valueOf();

console.log("Target Schema", target_schema);

const instructions = `A valid invoice line item table features rows such as description, quantity, unit price, and amount columns.`;

const adaptTablesRun = await client.objects.analyze(object.id).adaptTables({
  instructions: instructions,
  item_name: "invoice line item",
  target_schema: JSON.stringify(target_schema),
});

const adaptedTable = await client.objects
  .analyze(object.id)
  .getAdaptedTables(adaptTablesRun.workflow_run_id, { format: "json" });

console.log(adaptedTable);

A complete code sample can be found here

Was this page helpful?