Uploading files

You can use the files endpoint to upload files directly to Chariot using a pre-signed URL. Chariot uses Amazon S3 to securely store your files so you don't have to manage storage in your own application.

Alternatively, if you want to host your files elsewhere, you can provide file URLs via the content param when adding a source.

How to upload files using a pre-signed URL

The following example demonstrates how to upload a file using a pre-signed url from Chariot:

import { Chariot } from "chariotai";

const chariot = new Chariot(process.env.CHARIOT_API_KEY);

const response = await chariot.getPresignedUrl("file.pdf");
console.log(response);

This will return a presigned_url (expires after 15 minutes) and file_id that you can use to upload your file:

Response

{
  "file_id": "file_YmM3NGQ3",
  "presigned_url": "https://chariotcdkstackbeta-chariotdatastore841d880d-qmn699mdt2xc.s3.amazonaws.com/users/06dc9344-e14b-483b-bd07-904a69ff3f9c/files/file_YTg5MzIx/file.pdf?Signature=JuwOWDenAuAAFN4W27g6TAERBek%3D&Expires=1789659289"
}

To upload your file, make a PUT request with the file contents to the presigned_url:

import fs from 'fs';

const file = fs.readFileSync('/path/to/a/file.pdf');
await fetch(presignedUrl, {
    method: 'PUT',
    body: file
});

You can now add the file as a source to an application using your application_id and the file_id from above:

const source = {
  name: 'file.pdf',
  type: 'file',
  content: "file_YmM3NGQ3",
  application_id: 'app_YmM3NGQ3',
}

await chariot.createSource(source);

Chariot will automatically generate the embeddings for your file and store them in our vector database. To interact with your file, simply start a conversation with your application_id.

Viewing your uploaded files

To get a list of all uploaded files and their file_id's, use the files endpoint:

const files = await chariot.listFiles();
console.log(response);