Open-source platform for extracting structured data from documents using AI.
See the code
Documind is an advanced document processing tool that leverages AI to extract structured data from PDFs. It is built to handle PDF conversions, extract relevant information, and format results as specified by customizable schemas.
The hosted version provides a seamless experience with fully managed APIs, so you can skip the setup and start extracting data right away. Join the beta to get access to the hosted service.
Before using documind, ensure the following software dependencies are installed:
documind relies on Ghostscript for handling certain PDF operations.Install both on your system before proceeding:
# On macOS
brew install ghostscript graphicsmagick
# On Debian/Ubuntu
sudo apt-get update
sudo apt-get install -y ghostscript graphicsmagick
Ensure Node.js (v18+) and NPM are installed on your system.
You can install documind via npm:
npm install documind
documind requires an .env file to store sensitive information like your OpenAI API key.
Create an .env file in your project directory and add the following:
OPENAI_API_KEY=your_openai_api_key
First, import documind and define your schema. The schema outline what information documind should look for in each document. Here’s a quick setup to get started.
The schema is an array of objects where each object defines:
"string", "number", "array", "object").Example schema for a bank statement:
const schema = [
{
name: "accountNumber",
type: "string",
description: "The account number of the bank statement."
},
{
name: "openingBalance",
type: "number",
description: "The opening balance of the account."
},
{
name: "transactions",
type: "array",
description: "List of transactions in the account.",
children: [
{
name: "date",
type: "string",
description: "Transaction date."
},
{
name: "creditAmount",
type: "number",
description: "Credit Amount of the transaction."
},
{
name: "debitAmount",
type: "number",
description: "Debit Amount of the transaction."
},
{
name: "description",
type: "string",
description: "Transaction description."
}
]
},
{
name: "closingBalance",
type: "number",
description: "The closing balance of the account."
}
];
documindUse documind to process a PDF by passing the file URL and the schema.
import { extract } from 'documind';
const runExtraction = async () => {
const result = await extract({
file: 'https://bank_statement.pdf',
schema
});
console.log("Extracted Data:", result);
};
runExtraction();
Here’s an example of what the extracted result might look like:
{
"success": true,
"pages": 1,
"data": {
"accountNumber": "100002345",
"openingBalance": 3200,
"transactions": [
{
"date": "2021-05-12",
"creditAmount": null,
"debitAmount": 100,
"description": "transfer to Tom"
},
{
"date": "2021-05-12",
"creditAmount": 50,
"debitAmount": null,
"description": "For lunch the other day"
},
{
"date": "2021-05-13",
"creditAmount": 20,
"debitAmount": null,
"description": "Refund for voucher"
},
{
"date": "2021-05-13",
"creditAmount": null,
"debitAmount": 750,
"description": "May's rent"
}
],
"closingBalance": 2420
},
"fileName": "bank_statement.pdf"
}
Read the documentation for more on how to define schemas and and enable auto-generation.
Documind comes with built-in templates for extracting data from popular document types like invoices, bank statements, and more. These templates make it easier to get started without defining your own schema.
List available templates
You can list all available templates using the templates.list function.
import { templates } from 'documind';
const templates = templates.list();
console.log(templates); // Logs all available template names
Use a template
To use a template, simply pass its name to the extract function along with the file you want to extract data from. Here's an example:
import { extract } from 'documind';
const runExtraction = async () => {
const result = await extract({
file: 'https://bank_statement.pdf',
template: 'bank_statement'
});
console.log("Extracted Data:", result);
};
runExtraction();
Read the templates documentation for more details on templates and how to contribute yours.
Read more on how to use local models here.
Contributions are welcome! Please submit a pull request with any improvements or features.
This project is licensed under the AGPL v3.0 License.
This repo was built on top of Zerox. The MIT license from Zerox is included in the core folder and is also mentioned in the root license file.
72 followers · starred Nov 2024
109 followers · starred Dec 2024
328 followers · starred Nov 2024
92 followers · starred Nov 2024
Open-source platform for extracting structured data from documents using AI.
See the code
Documind is an advanced document processing tool that leverages AI to extract structured data from PDFs. It is built to handle PDF conversions, extract relevant information, and format results as specified by customizable schemas.
The hosted version provides a seamless experience with fully managed APIs, so you can skip the setup and start extracting data right away. Join the beta to get access to the hosted service.
Before using documind, ensure the following software dependencies are installed:
documind relies on Ghostscript for handling certain PDF operations.Install both on your system before proceeding:
# On macOS
brew install ghostscript graphicsmagick
# On Debian/Ubuntu
sudo apt-get update
sudo apt-get install -y ghostscript graphicsmagick
Ensure Node.js (v18+) and NPM are installed on your system.
You can install documind via npm:
npm install documind
documind requires an .env file to store sensitive information like your OpenAI API key.
Create an .env file in your project directory and add the following:
OPENAI_API_KEY=your_openai_api_key
First, import documind and define your schema. The schema outline what information documind should look for in each document. Here’s a quick setup to get started.
The schema is an array of objects where each object defines:
"string", "number", "array", "object").Example schema for a bank statement:
const schema = [
{
name: "accountNumber",
type: "string",
description: "The account number of the bank statement."
},
{
name: "openingBalance",
type: "number",
description: "The opening balance of the account."
},
{
name: "transactions",
type: "array",
description: "List of transactions in the account.",
children: [
{
name: "date",
type: "string",
description: "Transaction date."
},
{
name: "creditAmount",
type: "number",
description: "Credit Amount of the transaction."
},
{
name: "debitAmount",
type: "number",
description: "Debit Amount of the transaction."
},
{
name: "description",
type: "string",
description: "Transaction description."
}
]
},
{
name: "closingBalance",
type: "number",
description: "The closing balance of the account."
}
];
documindUse documind to process a PDF by passing the file URL and the schema.
import { extract } from 'documind';
const runExtraction = async () => {
const result = await extract({
file: 'https://bank_statement.pdf',
schema
});
console.log("Extracted Data:", result);
};
runExtraction();
Here’s an example of what the extracted result might look like:
{
"success": true,
"pages": 1,
"data": {
"accountNumber": "100002345",
"openingBalance": 3200,
"transactions": [
{
"date": "2021-05-12",
"creditAmount": null,
"debitAmount": 100,
"description": "transfer to Tom"
},
{
"date": "2021-05-12",
"creditAmount": 50,
"debitAmount": null,
"description": "For lunch the other day"
},
{
"date": "2021-05-13",
"creditAmount": 20,
"debitAmount": null,
"description": "Refund for voucher"
},
{
"date": "2021-05-13",
"creditAmount": null,
"debitAmount": 750,
"description": "May's rent"
}
],
"closingBalance": 2420
},
"fileName": "bank_statement.pdf"
}
Read the documentation for more on how to define schemas and and enable auto-generation.
Documind comes with built-in templates for extracting data from popular document types like invoices, bank statements, and more. These templates make it easier to get started without defining your own schema.
List available templates
You can list all available templates using the templates.list function.
import { templates } from 'documind';
const templates = templates.list();
console.log(templates); // Logs all available template names
Use a template
To use a template, simply pass its name to the extract function along with the file you want to extract data from. Here's an example:
import { extract } from 'documind';
const runExtraction = async () => {
const result = await extract({
file: 'https://bank_statement.pdf',
template: 'bank_statement'
});
console.log("Extracted Data:", result);
};
runExtraction();
Read the templates documentation for more details on templates and how to contribute yours.
Read more on how to use local models here.
Contributions are welcome! Please submit a pull request with any improvements or features.
This project is licensed under the AGPL v3.0 License.
This repo was built on top of Zerox. The MIT license from Zerox is included in the core folder and is also mentioned in the root license file.
72 followers · starred Nov 2024
109 followers · starred Dec 2024
328 followers · starred Nov 2024
92 followers · starred Nov 2024