|
| 1 | +# Documind |
| 2 | + |
| 3 | +**`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. |
| 4 | + |
| 5 | +## **Features** |
| 6 | + |
| 7 | +- Converts PDFs to images for detailed AI processing. |
| 8 | +- Uses OpenAI’s API to extract and structure information. |
| 9 | +- Allows users to specify extraction schemas for various document formats. |
| 10 | +- Designed for flexible deployment on local or cloud environments. |
| 11 | + |
| 12 | +### Try the Hosted Version 🚀 |
| 13 | + |
| 14 | +A demo of the **documind** hosted version will be available soon for you to try out! The hosted version provides a seamless experience with fully managed APIs, so you can skip the setup and start extracting data right away. |
| 15 | + |
| 16 | +For full access to the hosted service, please [request access](https://documind.xyz/signup) and we’ll get you set up. |
| 17 | + |
| 18 | +## **Requirements** |
| 19 | + |
| 20 | +Before using **`documind`**, ensure the following software dependencies are installed: |
| 21 | + |
| 22 | +### **System Dependencies** |
| 23 | + |
| 24 | +- **Ghostscript**: **`documind`** relies on Ghostscript for handling certain PDF operations. |
| 25 | +- **GraphicsMagick**: Required for image processing within document conversions. |
| 26 | + |
| 27 | +Install both on your system before proceeding: |
| 28 | + |
| 29 | +```bash |
| 30 | +# On macOS |
| 31 | +brew install ghostscript graphicsmagick |
| 32 | + |
| 33 | +# On Debian/Ubuntu |
| 34 | +sudo apt-get update |
| 35 | +sudo apt-get install -y ghostscript graphicsmagick |
| 36 | + |
| 37 | +``` |
| 38 | + |
| 39 | +### **Node.js & NPM** |
| 40 | + |
| 41 | +Ensure Node.js (v18+) and NPM are installed on your system. |
| 42 | + |
| 43 | +## **Installation** |
| 44 | + |
| 45 | +You can install **`documind`** via npm: |
| 46 | + |
| 47 | +```bash |
| 48 | +npm install documind |
| 49 | + |
| 50 | +``` |
| 51 | + |
| 52 | +### **Environment Setup** |
| 53 | + |
| 54 | +**`documind`** requires an **`.env`** file to store sensitive information like API keys and Supabase configurations. |
| 55 | + |
| 56 | +Create an **`.env`** file in your project directory and add the following: |
| 57 | + |
| 58 | +```bash |
| 59 | +OPENAI_API_KEY=your_openai_api_key |
| 60 | +SUPABASE_URL=your_supabase_url |
| 61 | +SUPABASE_KEY=your_supabase_key |
| 62 | +SUPABASE_BUCKET=your_supabase_bucket_name |
| 63 | + |
| 64 | +``` |
| 65 | + |
| 66 | +## **Usage** |
| 67 | + |
| 68 | +### **Basic Example** |
| 69 | + |
| 70 | +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. |
| 71 | + |
| 72 | +### **1. Define a Schema** |
| 73 | + |
| 74 | +The schema is an array of objects where each object defines: |
| 75 | + |
| 76 | +- **name**: Field name to extract. |
| 77 | +- **type**: Data type (e.g., **`"string"`**, **`"number"`**, **`"array"`**, **`"object"`**). |
| 78 | +- **description**: Description of the field. |
| 79 | +- **children** (optional): For arrays and objects, define nested fields. |
| 80 | + |
| 81 | +Example schema for a bank statement: |
| 82 | + |
| 83 | +```jsx |
| 84 | +const schema = [ |
| 85 | + { |
| 86 | + name: "accountNumber", |
| 87 | + type: "string", |
| 88 | + description: "The account number of the bank statement." |
| 89 | + }, |
| 90 | + { |
| 91 | + name: "openingBalance", |
| 92 | + type: "number", |
| 93 | + description: "The opening balance of the account." |
| 94 | + }, |
| 95 | + { |
| 96 | + name: "transactions", |
| 97 | + type: "array", |
| 98 | + description: "List of transactions in the account.", |
| 99 | + children: [ |
| 100 | + { |
| 101 | + name: "date", |
| 102 | + type: "string", |
| 103 | + description: "Transaction date." |
| 104 | + }, |
| 105 | + { |
| 106 | + name: "creditAmount", |
| 107 | + type: "number", |
| 108 | + description: "Credit Amount of the transaction." |
| 109 | + }, |
| 110 | + { |
| 111 | + name: "debitAmount", |
| 112 | + type: "number", |
| 113 | + description: "Debit Amount of the transaction." |
| 114 | + }, |
| 115 | + { |
| 116 | + name: "description", |
| 117 | + type: "string", |
| 118 | + description: "Transaction description." |
| 119 | + } |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + name: "closingBalance", |
| 124 | + type: "number", |
| 125 | + description: "The closing balance of the account." |
| 126 | + } |
| 127 | +]; |
| 128 | + |
| 129 | +``` |
| 130 | + |
| 131 | +### **2. Run `documind`** |
| 132 | + |
| 133 | +Use **`documind`** to process a PDF by passing the file URL and the schema. |
| 134 | + |
| 135 | +```jsx |
| 136 | +import { extract } from 'documind'; |
| 137 | + |
| 138 | +const runExtraction = async () => { |
| 139 | + const result = await extract({ |
| 140 | + file: 'https://bank_statement.pdf', |
| 141 | + schema |
| 142 | + }); |
| 143 | + |
| 144 | + console.log("Extracted Data:", result); |
| 145 | +}; |
| 146 | + |
| 147 | +runExtraction(); |
| 148 | + |
| 149 | +``` |
| 150 | + |
| 151 | +### **Example Output** |
| 152 | + |
| 153 | +Here’s an example of what the extracted result might look like: |
| 154 | + |
| 155 | +```json |
| 156 | + { |
| 157 | + "success": true, |
| 158 | + "pages": 1, |
| 159 | + "data": { |
| 160 | + "accountNumber": "100002345", |
| 161 | + "openingBalance": $3200, |
| 162 | + "transactions": [ |
| 163 | + { |
| 164 | + "date": "2021-05-12", |
| 165 | + "creditAmount": null, |
| 166 | + "debitAmount": $100, |
| 167 | + "description": "transfer to Tom" |
| 168 | + }, |
| 169 | + { |
| 170 | + "date": "2021-05-12", |
| 171 | + "creditAmount": $50, |
| 172 | + "debitAmount": null, |
| 173 | + "description": "For lunch the other day" |
| 174 | + }, |
| 175 | + { |
| 176 | + "date": "2021-05-13", |
| 177 | + "creditAmount": $20, |
| 178 | + "debitAmount": null, |
| 179 | + "description": "Refund for voucher" |
| 180 | + }, |
| 181 | + { |
| 182 | + "date": "2021-05-13", |
| 183 | + "creditAmount": null, |
| 184 | + "debitAmount": $750, |
| 185 | + "description": "May's rent" |
| 186 | + } |
| 187 | + ], |
| 188 | + "closingBalance": $2420 |
| 189 | + }, |
| 190 | + "fileName": "bank_statement.pdf", |
| 191 | +} |
| 192 | + |
| 193 | +``` |
| 194 | + |
| 195 | +## **Contributing** |
| 196 | + |
| 197 | +Contributions are welcome! Please submit a pull request with any improvements or features. |
| 198 | + |
| 199 | +## **License** |
| 200 | + |
| 201 | +This project is licensed under the AGPL v3.0 License. |
| 202 | + |
| 203 | +--- |
0 commit comments