Tool

Load Docugami Documents into Knowledge Graph

Load Docugami-processed PDF, DOCX, or DOC files into LlamaIndex as semantic XML knowledge graphs.

Works with docugamillamaindex

78
Spark score
out of 100
Updated 2 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Ingest and semantically structure documents from Docugami into a hierarchical XML knowledge graph. This loader enables advanced querying and retrieval by preserving document structure and semantic meaning.

Outcomes

What it gets done

01

Load PDF, DOCX, or DOC files processed by Docugami.

02

Generate a Document XML Knowledge Graph representing semantic and structural document characteristics.

03

Process entire sets of documents into forests of XML semantic trees.

04

Facilitate intelligent chunking and semantic annotation for enhanced RAG.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-reader-readers-docugami | bash

Overview

Docugami Loader

A LlamaIndex loader that turns Docugami-processed PDF, DOCX, or DOC files into semantic XML knowledge graphs with cross-document structural annotations. Use for sets of related structured documents needing semantic, structure-aware chunking rather than naive length-based splitting.

What it does

The Docugami Loader takes in IDs of PDF, DOCX, or DOC files that have been processed by Docugami and returns nodes in a Document XML Knowledge Graph for each document - a rich representation capturing the semantic and structural characteristics of the document's chunks as an XML tree. When entire sets of documents are processed, the result is a forest of these XML semantic trees, one per document.

Using it requires a Docugami workspace first: documents are uploaded and Docugami ingests and clusters them into sets of similar documents (for example NDAs, Lease Agreements, or Service Agreements - the clustering is not fixed and depends on your own documents, and doc set assignments can be changed later). An access token is created via the Developer Playground, and the Docugami API can then be explored to find docset IDs and the document IDs within them. DocugamiReader is called with load_data(docset_id=..., document_ids=...), where the document_ids array is optional - omitting it loads every document in the docset.

The source frames Docugami's chunking as distinct from simpler techniques (whitespace-based splitting, recursive chunking by character length) across four dimensions. Intelligent Chunking breaks each document into a hierarchical semantic XML tree of chunks ranging from single words to entire sections, following the document's own semantic contours rather than an arbitrary length cutoff. Structured Representation adds attributes marking headings, paragraphs, lists, tables, and other structural elements consistently across formats - including scanned PDFs or DOCX files - while correctly handling page headers/footers and multi-column layouts for clean text extraction. Semantic Annotations tag chunks coherently across an entire document set, so a query for something like the Landlord, Tenant, or Renewal Date works consistently across a set of differently-formatted lease agreements, down to more complex information like sub-lease wording or jurisdiction-specific termination exceptions. Additional Metadata attaches further annotations (for Docugami users) that support high-accuracy document QA without hitting context window limits.

When to use - and when NOT to

Use it when you need to index a set of related documents (contracts, agreements, or similar structured document families) with chunking that respects their actual semantic and structural layout, rather than naive length-based splitting - particularly when you need consistent cross-document queries like comparing a clause across many lease agreements. Do not use it for one-off documents with no meaningful structure or cross-document comparison need; the value here is specifically in the semantic/structural richness and cross-document consistency Docugami's clustering and XML tree provide.

Capabilities

load_data fetches a Docugami-processed docset (optionally scoped to specific document IDs) and returns each document as a semantic XML knowledge graph node, with structural attributes (headings, paragraphs, lists, tables), cross-document-consistent semantic tags, and optional additional metadata for high-accuracy QA.

How to install

pip install llama-index-readers-docugami

Requires a Docugami workspace with documents already uploaded, clustered into docsets, and an access token created via the Developer Playground.

Who it's for

Developers indexing sets of related structured documents - contracts, agreements, or similar families - who need chunking and cross-document semantic consistency that simple length-based splitting cannot provide.

Source README

Docugami Loader

pip install llama-index-readers-docugami

This loader takes in IDs of PDF, DOCX or DOC files processed by Docugami and returns nodes in a Document XML Knowledge Graph for each document. This is a rich representation that includes the semantic and structural characteristics of various chunks in the document as an XML tree. Entire sets of documents are processed, resulting in forests of XML semantic trees.

Pre-requisites

  1. Create a Docugami workspace: http://www.docugami.com (free trials available)
  2. Add your documents (PDF, DOCX or DOC) and allow Docugami to ingest and cluster them into sets of similar documents, e.g. NDAs, Lease Agreements, and Service Agreements. There is no fixed set of document types supported by the system, the clusters created depend on your particular documents, and you can change the docset assignments later.
  3. Create an access token via the Developer Playground for your workspace. Detailed instructions: https://help.docugami.com/home/docugami-api
  4. Explore the Docugami API at https://api-docs.docugami.com to get a list of your processed docset IDs, or just the document IDs for a particular docset.

Usage

To use this loader, you simply need to pass in a Docugami Doc Set ID, and optionally an array of Document IDs (by default, all documents in the Doc Set are loaded).

from llama_index.readers.docugami import DocugamiReader

docset_id = "tjwrr2ekqkc3"
document_ids = ["ui7pkriyckwi", "1be3o7ch10iy"]

loader = DocugamiReader()
documents = loader.load_data(docset_id=docset_id, document_ids=document_ids)

This loader is designed to be used as a way to load data into LlamaIndex.

See more information about how to use Docugami with LangChain in the LangChain docs.

Advantages vs Other Chunking Techniques

Appropriate chunking of your documents is critical for retrieval from documents. Many chunking techniques exist, including simple ones that rely on whitespace and recursive chunk splitting based on character length. Docugami offers a different approach:

  1. Intelligent Chunking: Docugami breaks down every document into a hierarchical semantic XML tree of chunks of varying sizes, from single words or numerical values to entire sections. These chunks follow the semantic contours of the document, providing a more meaningful representation than arbitrary length or simple whitespace-based chunking.
  2. Structured Representation: In addition, the XML tree indicates the structural contours of every document, using attributes denoting headings, paragraphs, lists, tables, and other common elements, and does that consistently across all supported document formats, such as scanned PDFs or DOCX files. It appropriately handles long-form document characteristics like page headers/footers or multi-column flows for clean text extraction.
  3. Semantic Annotations: Chunks are annotated with semantic tags that are coherent across the document set, facilitating consistent hierarchical queries across multiple documents, even if they are written and formatted differently. For example, in set of lease agreements, you can easily identify key provisions like the Landlord, Tenant, or Renewal Date, as well as more complex information such as the wording of any sub-lease provision or whether a specific jurisdiction has an exception section within a Termination Clause.
  4. Additional Metadata: Chunks are also annotated with additional metadata, if a user has been using Docugami. This additional metadata can be used for high-accuracy Document QA without context window restrictions. See detailed code walk-through in [this notebook](https://github.com/run-llama/lla

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.