Loading
Everything retrieved starts as a file. The Document and Image classes (plus Audio and Video) build files from every source you have, put() stores them with the provider once, and fromId() references the stored copy later without re-uploading.
Putting files in
use Crustum\Ai\Files\Document;
$stored = Document::fromString('CakePHP is a PHP framework.', 'text/plain')->put();
echo $stored->id . PHP_EOL;fake_file_685b6577729e3e4c1287ad1eb6bdbee6Every reader ends at the same put():
use Crustum\Ai\Enums\Lab;
use Crustum\Ai\Files\Document;
$stored = Document::fromPath('/var/www/knowledge.txt')
->withProviderOptions(['purpose' => 'assistants'])
->put(provider: 'openai');
echo $stored->id . PHP_EOL;fake_file_2c8b70838a6eaf4b6dadec6b38eddc75Readers: fromPath(), fromStorage() (filesystem disk), fromUrl(), fromString(), fromUpload(). Options set inline ride along (purpose), or branch per provider with a closure receiving the current Lab. Stored files attach to prompts via Document::fromId($stored->id). See Vector Stores for indexing them instead.
Reading and removing
use Crustum\Ai\Files\Document;
$file = Document::fromId('file-id')->get();
echo $file->mimeType() . PHP_EOL;
Document::fromId('file-id')->delete();text/plainget() returns the stored metadata; delete() drops the provider copy. Removing a file from a store keeps the stored copy unless asked. Re-adding it later is one add() call, not a re-upload.