> For the complete documentation index, see [llms.txt](https://docs.openagrinet.global/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openagrinet.global/technical/ai-layer/data-ingestion-pipeline/document-processing-and-ocr.md).

# Document Processing and OCR

Unstructured documents often include:

* Scanned PDFs
* Text-based PDFs
* Complex tables (e.g. fertiliser dosages, measurements)

Initial attempts using standard Python PDF extraction libraries resulted in complex table extraction and formatting errors, especially for tabular data. To address this, the pipeline was migrated to the Mistral OCR pipeline, which provides:

* Accurate extraction of tables
* Preservation of headers and document structure
* Cleaner downstream processing

Documents are converted into Markdown format after OCR.

For example, a scanned PDF containing fertiliser dosage tables is processed using the Mistral OCR pipeline. The OCR extracts both the textual content and tabular data, preserving headers and structure. The output is generated in Markdown format, which is then used for downstream cleaning and chunking.

The Markdown output generated after OCR serves as an intermediate artefact in the ingestion pipeline. This intermediate format allows teams to inspect, validate, and review extracted content before further processing.

Maintaining Markdown outputs as part of the setup process improves transparency and makes it easier to identify extraction or formatting issues prior to chunking and ingestion into the vector database.

<div data-with-frame="true"><figure><img src="https://496953384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSb3jldXQwe68uba6eZGW%2Fuploads%2FJFczZI4UVcSkQ3ylQIho%2Funknown.png?alt=media&amp;token=dd64c482-1259-4c70-86b3-a540eea8d2eb" alt=""><figcaption></figcaption></figure></div>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openagrinet.global/technical/ai-layer/data-ingestion-pipeline/document-processing-and-ocr.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
