# Attachments (Documents & Images)

Most advanced LLMs can understand the content of documents and images other than simple text. With Neuron you can attach files to your messages to enrich the context provided to the Agent.

The most common use cases for documents analysis are:

* Caption and answer questions about images
* Transcribe and reason over document contents

You have two options to attach items to your messages: as an URL, or encoded in base64.

{% hint style="warning" %}
Be sure about the possible limitations of your AI provider to handle documents and images in specific formats.
{% endhint %}

## Documents

#### URL

```php
use App\Neuron\MyAgent;
use NeuronAI\Chat\Attachments\Document;
use NeuronAI\Chat\Messages\UserMessage;

// Ollama only support images encoded in base64
$message = (new UserMessage("Describe this document"))
    ->addAttachment(
        new Document('https://url_of/document.pdf')
    );
    
$response = MyAgent::make()->chat($message);
// The document is a contract...
```

#### Base64

```php
use App\Neuron\MyAgent;
use NeuronAI\Chat\Attachments\AttachmentContentType;
use NeuronAI\Chat\Attachments\Document;
use NeuronAI\Chat\Messages\UserMessage;

$content = base64_encode(file_get_contents('/document.pdf'));

$message = (new UserMessage("Describe this document"))
    ->addAttachment(
        new Document(
            content: $content,
            contentType: AttachmentContentType::BASE64,
            mediaType: 'application/pdf'
        )
    );
    
$response = MyAgent::make()->chat($message);
// The document is a contract...
```

## Images

#### URL

```php
use App\Neuron\MyAgent;
use NeuronAI\Chat\Attachments\Image;
use NeuronAI\Chat\Messages\UserMessage;

// Ollama only support images encoded in base64
$message = (new UserMessage("Describe this image"))
    ->addAttachment(
        new Image('https://url_of/image.jpg')
    );
    
$response = MyAgent::make()->chat($message);
// The image shows...
```

#### Base64

```php
use App\Neuron\MyAgent;
use NeuronAI\Chat\Attachments\AttachmentContentType;
use NeuronAI\Chat\Attachments\Image;
use NeuronAI\Chat\Messages\UserMessage;

$content = base64_encode(file_get_contents('/image.jpg'));

$message = (new UserMessage("Describe this image"))
    ->addAttachment(
        new Image(
            content: $content,
            contentType: AttachmentContentType::BASE64,
            mediaType: 'image/jpeg'
        )
    );
    
$response = MyAgent::make()->chat($message);
// The image shows...
```

## Ollama limitations

Ollama only support images in base64 format, so you have to take care to convert the file content and set up the right type for attachments:

```php
use NeuronAI\Chat\Attachments\AttachmentContentType;
use NeuronAI\Chat\Attachments\Image;
use NeuronAI\Chat\Messages\UserMessage;

// Ollama only support images encoded in base64
$message = (new UserMessage("Describe this image"))
    ->addAttachment(
        new Image(
            image: 'base64-encoded-content', 
            type: AttachmentContentType::BASE64, 
            mediaType: 'image/jpeg'
        )
    );
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neuron-ai.dev/v1/getting-started/attachments-documents-and-images.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
