> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image OCR Extraction

> Print the text an image becomes before you ingest it: the vision-model transcription plus appended OCR text

A minimal guide to inspecting what Cognee extracts from an image. Run it against a screenshot, a scanned page, or a dense chart to see exactly which text would reach the knowledge graph — before spending an ingestion run on it.

## Before You Start

* Complete [Quickstart](/getting-started/quickstart) to understand basic operations
* Ensure you have [LLM Providers](/setup-configuration/llm-providers) configured with a vision-capable `LLM_MODEL` — the transcription step calls it
* Install the OCR engine: `pip install "cognee[rapidocr]"`
* Read [Loaders](/core-concepts/further-concepts/loaders) for how Cognee picks a loader per file and for the full set of image environment variables
* Have an image file on disk. The script reads `revenue_chart.png` from the example's [`multimedia_audio_image_processing_example_data/`](https://github.com/topoteretes/cognee/tree/dev/examples/guides/multimedia_audio_image_processing_example_data) directory in the Cognee repo — download it from there to reproduce the run exactly, or point `image_path` at your own file to check that one instead

## Code in Action

```python theme={null}
import asyncio
import os
import pathlib

from cognee.infrastructure.loaders.core.image_loader import ImageLoader

os.environ.setdefault("IMAGE_EXTRACTION_ENABLED", "true")
os.environ.setdefault("IMAGE_OCR_ENABLED", "true")


async def main():
    image_path = os.path.join(
        pathlib.Path(__file__).parent,
        "multimedia_audio_image_processing_example_data/revenue_chart.png",
    )
    text = await ImageLoader().load(image_path, persist=False)

    print("=== Text extracted from the image ===")
    print(text)


if __name__ == "__main__":
    asyncio.run(main())
```

## What Just Happened

### Step 1: Enable Extraction and OCR

```python theme={null}
import asyncio
import os
import pathlib

from cognee.infrastructure.loaders.core.image_loader import ImageLoader

os.environ.setdefault("IMAGE_EXTRACTION_ENABLED", "true")
os.environ.setdefault("IMAGE_OCR_ENABLED", "true")
```

`ImageLoader` is the loader `remember()` would pick for an image, imported directly here so you can call it on its own. `IMAGE_EXTRACTION_ENABLED` asks the vision model for entities, relationships, and verbatim text rather than a short caption; `IMAGE_OCR_ENABLED` adds a local OCR pass on top. Both are read when the image loads, and `setdefault` leaves any value you already set in the environment or `.env` untouched.

### Step 2: Point at an Image File

```python theme={null}
image_path = os.path.join(
    pathlib.Path(__file__).parent,
    "multimedia_audio_image_processing_example_data/revenue_chart.png",
)
```

The path is resolved relative to the script so the example runs from any working directory. Swap in a path to your own screenshot or scan to check what Cognee makes of it.

### Step 3: Load the Image and Print the Text

```python theme={null}
text = await ImageLoader().load(image_path, persist=False)

print("=== Text extracted from the image ===")
print(text)
```

`load()` runs the transcription and, when OCR is on, appends the recognized text to it. `persist=False` returns that text directly; the default `persist=True` writes it into Cognee's data directory and returns the file path instead — useful in a pipeline, unhelpful when you just want to read the result.

## Advanced Usage

<AccordionGroup>
  <Accordion title="Reading the two halves of the output">
    The vision transcription comes first. If the OCR pass recognized anything, it follows under an `[OCR extracted text]` heading, so you can tell which half produced which text. OCR output is truncated at 8000 characters, and a failing OCR pass is logged and skipped rather than raising — so a result with no `[OCR extracted text]` block means OCR found nothing, was disabled, or failed.
  </Accordion>

  <Accordion title="Checking one flag at a time">
    To see what each stage contributes, run the script twice. `IMAGE_OCR_ENABLED="false"` gives the vision transcription alone; `IMAGE_EXTRACTION_ENABLED="false"` restores the legacy short-caption prompt. Both flags, and the transcription prompt and token-cap settings around them, are documented in [Loaders](/core-concepts/further-concepts/loaders).
  </Accordion>

  <Accordion title="From check to ingestion">
    Nothing here writes to memory. Once the extracted text looks right, pass the same image path to `remember()` — it selects `ImageLoader` for you and reads the same environment variables, so the text you just printed is the text that gets chunked and turned into graph memory.
  </Accordion>
</AccordionGroup>

<Columns cols={2}>
  <Card title="Loaders" icon="download" href="/core-concepts/further-concepts/loaders">
    See every format Cognee reads and each image transcription setting
  </Card>

  <Card title="Remember" icon="brain" href="/core-concepts/main-operations/remember">
    Ingest the image once its extracted text looks right
  </Card>
</Columns>
