documind Documentation

repository·main·Indexed 23 days ago

https://github.com/documindhq/documind

An intelligent document processing and extraction tool (v1.1.5) that uses AI to extract structured JSON data or formatted Markdown from unstructured documents such as PDFs, DOCX, images, and HTML. It supports custom extraction schemas, pre-defined templates for invoices and bank statements, and integrates with multiple LLM providers including OpenAI, Google Gemini, and local Ollama instances.

Tokens
5K
Snippets
12
Records
36
Agent score
31%

What's inside documind

  1. Define a custom extraction schema

    main

    A schema is an array of objects that defines the structure of the data you want to extract. Each object must include:

    • name: The field name to extract.
    • type: The data type (e.g., "string", "number", "array", "object", "boolean", or "enum").
    • description: A description of the field to guide the AI.
    • children (optional): An array of nested field objects, used for "array" or "object" types.
    const schema = [
      {
        name: "accountNumber",
        type: "string",
        description: "The account number of the bank statement."
      },
      {
        name: "transactions",
        type: "array",
        description: "List of transactions in the account.",
        children: [
          {
            name: "date",
            type: "string",
            description: "Transaction date."
          }
        ]
      }
    ];
  2. Configure System Dependencies for Documind

    main

    Documind requires Ghostscript (for PDF operations) and GraphicsMagick (for image processing) to be installed on your operating system.

    On macOS:

    brew install ghostscript graphicsmagick

    On Debian/Ubuntu:

    sudo apt-get update
    sudo apt-get install -y ghostscript graphicsmagick
    # On macOS
    brew install ghostscript graphicsmagick
    
    # On Debian/Ubuntu
    sudo apt-get update
    sudo apt-get install -y ghostscript graphicsmagick
  3. Use built-in document templates

    main

    Documind provides pre-defined templates for common documents like invoices and bank statements.

    1. List available templates using templates.list().
    2. Apply a template by passing the template name to the template property in the extract() options object.
  4. Set up Environment Variables

    main

    Documind requires an .env file in your project directory to store your OpenAI API key. Create the file and add the following variable:

    OPENAI_API_KEY=your_openai_api_key

    OPENAI_API_KEY=your_openai_api_key
  5. Extract data using `extract()`

    main

    Use the extract function to process a document. You can provide either a custom schema or a pre-defined template name. The file parameter accepts a URL to the document.

    import { extract } from 'documind';
    
    const runExtraction = async () => {
      const result = await extract({
        file: 'https://bank_statement.pdf',
        schema
      });
    
      console.log("Extracted Data:", result);
    };
    
    runExtraction();
  6. Configure the Ollama provider via environment variables

    main

    The Ollama provider requires the following environment variable to be set:

    • BASE_URL: The base URL of your local Ollama instance (e.g., http://localhost:11434).

    If BASE_URL is not provided, the provider will throw an error: Missing BASE_URL in environment variables.

  7. Configure the GEMINI_API_KEY environment variable

    main

    The Google provider requires a valid API key to authenticate requests to the Google Generative Language API. This must be provided via the GEMINI_API_KEY environment variable.

    If this variable is missing, the provider will throw an error: Missing GEMINI_API_KEY in environment variables.

  8. Understand the `extract()` output format

    main

    The extract function returns a JSON object containing the extraction status, page count, the extracted data, and the filename.

    Example Output Structure:

     {
      "success": true,
      "pages": 1,
      "data": {
        "accountNumber": "100002345",
        "openingBalance": 3200,
        "transactions": [
            {
            "date": "2021-05-12",
            "creditAmount": null,
            "debitAmount": 100,
            "description": "transfer to Tom" 
          }
        ],
        "closingBalance": 2420
      },
      "fileName": "bank_statement.pdf"
    }