Guides
Upload and index your documents
Learn how to upload documents to EasyRAG and make them searchable.
When you upload a file to EasyRAG:
After upload, you can immediately search and query the content.
| Format | Extension | Max Size |
|---|---|---|
.pdf | 100 MB | |
| Word | doc, .docx | 100 MB |
| Excel | .xlsx, .xls | 100 MB |
| PowerPoint | .pptx, .ppt | 100 MB |
| CSV | .csv | 100 MB |
| Markdown | .md | 100 MB |
| JSON | .json | 100 MB |
| TXT | .txt | 100 MB |
| Format | Extension | Max Size |
|---|---|---|
| Audio | .mp3, .wav | 2 GB |
| Video | .mp4 | 2 GB |
Note: Audio and video files are automatically transcribed using Whisper, then the transcription is indexed for search.
bashcurl -X POST https://api.easyrag.com/v1/files/upload \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "datasetId=my-documents" \ -F "file=@document.pdf"
javascriptconst formData = new FormData(); formData.append('datasetId', 'my-documents'); formData.append('file', fileInput.files[0]); const response = await fetch('https://api.easyrag.com/v1/files/upload', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}` }, body: formData }); const result = await response.json(); console.log('Uploaded:', result.files[0].originalName);
json{ "success": true, "message": "Files processed and indexed successfully!", "files": [ { "fileId": "f7a3b2c1-4d5e-6f7g", "originalName": "document.pdf", "datasetId": "my-documents", "size": 245678, "created": "2024-12-13T10:30:00.000Z" } ], "billed": { "fileCount": 1, "uploadUnits": 1 } }
You can upload multiple files in a single request:
javascriptconst formData = new FormData(); formData.append('datasetId', 'my-documents'); // Add multiple files formData.append('file', file1); formData.append('file', file2); formData.append('file', file3); const response = await fetch('https://api.easyrag.com/v1/files/upload', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}` }, body: formData });
Cost: 1 credit per file (3 credits for 3 files)
Control how documents are split into chunks:
javascriptconst formData = new FormData(); formData.append('datasetId', 'my-documents'); formData.append('file', file); formData.append('chunkSize', '500'); // Larger chunks formData.append('chunkOverlap', '50'); // More overlap await fetch('https://api.easyrag.com/v1/files/upload', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}` }, body: formData });
Use larger chunks (400-600) when:
Use smaller chunks (200-300) when:
Increase overlap (40-60) when:
Attach custom metadata to your files for filtering later:
javascriptconst formData = new FormData(); formData.append('datasetId', 'company-docs'); formData.append('file', policyFile); // Metadata as JSON string const metadata = { 'hr-policy.pdf': { department: 'HR', category: 'policy', year: 2024, confidential: false } }; formData.append('metadata', JSON.stringify(metadata)); await fetch('https://api.easyrag.com/v1/files/upload', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}` }, body: formData });
Metadata can be matched by:
metadata['hr-policy.pdf']metadata['f7a3b2c1-4d5e']metadata['0'] (first file in upload)javascriptconst metadata = { // Match by filename 'report.pdf': { type: 'financial' }, // Match by index (useful for multiple uploads) '0': { priority: 'high' }, '1': { priority: 'medium' } };
Later, you can filter by this metadata:
javascriptawait search('company-docs', 'vacation policy', { filters: [ { key: 'department', match: { value: 'HR' } }, { key: 'year', match: { value: 2024 } } ] });
When you upload audio or video files:
javascript// Upload a podcast episode const formData = new FormData(); formData.append('datasetId', 'podcast-episodes'); formData.append('file', audioFile); // .mp3 or .wav const response = await fetch('https://api.easyrag.com/v1/files/upload', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}` }, body: formData }); const result = await response.json(); // Access transcription const file = result.files[0]; console.log('Transcription:', file.transcriptionText); console.log('Subtitles:', file.transcriptionSrt); // Array of SRT entries
Note: Transcription adds processing time (typically 1-2 minutes per hour of audio).
json{ "error": "FILE_TOO_LARGE", "message": "File exceeds maximum size of 100MB" }
json{ "error": "Unsupported file format: .txt" }
json{ "error": "INSUFFICIENT_CREDITS", "message": "You are out of credits. Please top up to continue." }
javascriptasync function uploadWithErrorHandling(file) { // Check file size const maxSize = file.type.startsWith('video') ? 2 * 1024 * 1024 * 1024 : 100 * 1024 * 1024; if (file.size > maxSize) { alert('File too large!'); return; } // Check file type const allowed = ['.pdf', '.docx', '.xlsx', '.pptx', '.csv', '.mp3', '.wav', '.mp4']; const ext = '.' + file.name.split('.').pop().toLowerCase(); if (!allowed.includes(ext)) { alert('Unsupported file type!'); return; } const formData = new FormData(); formData.append('datasetId', 'my-dataset'); formData.append('file', file); try { const response = await fetch('https://api.easyrag.com/v1/files/upload', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}` }, body: formData }); if (!response.ok) { const error = await response.json(); if (error.error === 'INSUFFICIENT_CREDITS') { alert('Out of credits! Please top up in the dashboard.'); } else { alert(`Upload failed: ${error.message}`); } return; } const result = await response.json(); console.log('Success:', result); } catch (error) { console.error('Upload error:', error); alert('Network error. Please try again.'); } }
Check file size and type before uploading:
javascriptfunction validateFile(file) { const maxSize = 100 * 1024 * 1024; // 100MB const allowed = ['pdf', 'docx', 'xlsx', 'pptx', 'csv']; const ext = file.name.split('.').pop().toLowerCase(); if (file.size > maxSize) { return { valid: false, error: 'File too large' }; } if (!allowed.includes(ext)) { return { valid: false, error: 'Unsupported file type' }; } return { valid: true }; }
javascript// ✅ Good: Descriptive dataset names const datasetId = `user-${userId}-documents`; const datasetId = 'company-policies'; const datasetId = 'support-docs-2024'; // ❌ Bad: Generic names const datasetId = 'dataset1'; const datasetId = 'files';
javascript// ✅ Good: Metadata for filtering const metadata = { 'contract.pdf': { type: 'contract', client: 'Acme Corp', signedDate: '2024-01-15', value: 50000, department: 'sales' } }; // ❌ Bad: No metadata or useless metadata const metadata = { 'contract.pdf': { uploaded: true, format: 'pdf' // Already known from filename } };
javascript// Show loading state setUploading(true); try { await uploadFile(file); // Show success message showToast('File uploaded successfully!'); } catch (error) { // Show error message showToast('Upload failed. Please try again.'); } finally { setUploading(false); }
Now that you can upload files:
For complete API documentation: