UltraSafe

File Search API

Version: 2.0 Base URL: https://filesearchrag.usinc.ai

Quick Start

API Key

x-api-key: <YOUR_API_KEY>

Create Collection API

Endpoint: POST /v2/collections

Overview

The Create Collection API enables you to upload and process documents into organized, searchable collections for Retrieval-Augmented Generation (RAG). RAG is a technique that enhances AI model responses by retrieving relevant information from your documents before generating answers, resulting in more accurate and contextually relevant outputs.

Key Features

  • OCR-based extraction using USF Vision API for accurate text parsing from any document type
  • Parent-child chunking that preserves document context for better retrieval accuracy
  • Hierarchical organization with collections and sub-collections
  • S3 preview generation for file thumbnails in UI
  • User-scoped isolation ensuring private access to your collections
  • Concurrent processing of up to 3 files simultaneously
  • SSE Streaming for real-time progress updates

API Endpoint

MethodURL
POSThttps://filesearchrag.usinc.ai/v2/collections

Authentication

All API requests require authentication using an API key passed in the request header.

HeaderTypeRequiredDescription
x-api-keystringYesYour API authentication key

Example API Key:

x-api-key: <YOUR_API_KEY>

⚠️ Security Note: Keep your API key secure and never expose it in client-side code or public repositories.

Request Format

Files must be sent as multipart/form-data. This is the standard HTTP format for uploading binary data.

Request Parameters

ParameterTypeRequiredDefaultDescription
namestringYes-Display name for the collection
filesfile[]Yes-One or more files to upload (max 10 files, 100 MB each)
collection_idstringNoAuto-generatedExisting collection ID to append files to (creates new if omitted)
summarizebooleanNofalseGenerate summaries for each file
previewintegerNo0Enable S3 file preview (0=disabled, 1=enabled)
streambooleanNofalseEnable SSE streaming for real-time progress

Request Behavior

  • New Collection: Omit collection_id to create a brand new collection
  • Append to Existing: Provide collection_id to add files as a new sub-collection within an existing collection
  • Collection ID Format: Generated IDs use the format vs_* (e.g., vs_9b1fd5b2186f45bc9a35eab321c8318f)

Usage Examples

Python

Create New Collection (Single File):

import requests

url = "https://filesearchrag.usinc.ai/v2/collections"
headers = {"x-api-key": ""}

# Upload a single file to create a new collection
with open("document.pdf", "rb") as f:
    files = [("files", ("document.pdf", f, "application/pdf"))]
    data = {"name": "My Documents"}

    response = requests.post(url, headers=headers, files=files, data=data)
    result = response.json()

    print(f"Collection ID: {result['collection']['id']}")
    print(f"Sub-collections: {result['sub_collections']}")

Create New Collection (Batch Upload):

import requests

url = "https://filesearchrag.usinc.ai/v2/collections"
headers = {"x-api-key": ""}

# Upload multiple files to create a new collection
files = [
    ("files", ("report.pdf", open("report.pdf", "rb"), "application/pdf")),
    ("files", ("data.xlsx", open("data.xlsx", "rb"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")),
    ("files", ("notes.txt", open("notes.txt", "rb"), "text/plain"))
]
data = {"name": "Q4 Financial Reports"}

response = requests.post(url, headers=headers, files=files, data=data)
result = response.json()

print(f"Collection: {result['collection']['name']}")
print(f"Files processed: {result['summary']['successful']}/{result['summary']['total_files']}")
print(f"Total chunks: {result['summary']['total_chunks']}")

# Don't forget to close file handles
for _, (_, f, _) in files:
    f.close()

Append to Existing Collection:

import requests

url = "https://filesearchrag.usinc.ai/v2/collections"
headers = {"x-api-key": ""}

# Append files to an existing collection
existing_collection_id = "vs_9b1fd5b2186f45bc9a35eab321c8318f"

files = [
    ("files", ("new_report.pdf", open("new_report.pdf", "rb"), "application/pdf"))
]
data = {
    "name": "Q4 Reports",
    "collection_id": existing_collection_id
}

response = requests.post(url, headers=headers, files=files, data=data)
result = response.json()

print(f"Added to collection: {result['collection']['id']}")
print(f"New sub-collection: {result['latest_sub_collection_id']}")

JavaScript

Create New Collection (Single File):

const FormData = require('form-data');
const fs = require('fs');
const axios = require('axios');

async function createCollection() {
    const form = new FormData();
    form.append('files', fs.createReadStream('document.pdf'));
    form.append('name', 'My Documents');

    try {
        const response = await axios.post(
            'https://filesearchrag.usinc.ai/v2/collections',
            form,
            {
                headers: {
                    'x-api-key': '',
                    ...form.getHeaders()
                }
            }
        );

        console.log('Collection ID:', response.data.collection.id);
        console.log('Sub-collections:', response.data.sub_collections);
    } catch (error) {
        console.error(error.response?.data || error.message);
    }
}

createCollection();

Create New Collection (Batch Upload):

const FormData = require('form-data');
const fs = require('fs');
const axios = require('axios');

async function createBatchCollection() {
    const form = new FormData();

    // Append multiple files
    form.append('files', fs.createReadStream('report.pdf'));
    form.append('files', fs.createReadStream('data.xlsx'));
    form.append('files', fs.createReadStream('notes.txt'));
    form.append('name', 'Q4 Financial Reports');

    try {
        const response = await axios.post(
            'https://filesearchrag.usinc.ai/v2/collections',
            form,
            {
                headers: {
                    'x-api-key': '',
                    ...form.getHeaders()
                }
            }
        );

        const { data } = response;
        console.log('Collection:', data.collection.name);
        console.log('Processed:', data.summary.successful + '/' + data.summary.total_files);
        console.log('Total chunks:', data.summary.total_chunks);
    } catch (error) {
        console.error(error.response?.data || error.message);
    }
}

createBatchCollection();

cURL

Create New Collection (Single File):

curl -X POST "https://filesearchrag.usinc.ai/v2/collections" \
  -H "x-api-key: " \
  -F "files=@document.pdf" \
  -F "name=My Documents"

Create New Collection (Batch Upload):

curl -X POST "https://filesearchrag.usinc.ai/v2/collections" \
  -H "x-api-key: " \
  -F "files=@report.pdf" \
  -F "files=@data.xlsx" \
  -F "files=@notes.txt" \
  -F "name=Q4 Financial Reports"

Append to Existing Collection:

curl -X POST "https://filesearchrag.usinc.ai/v2/collections" \
  -H "x-api-key: " \
  -F "files=@new_report.pdf" \
  -F "name=Q4 Reports" \
  -F "collection_id=vs_9b1fd5b2186f45bc9a35eab321c8318f"

With S3 Preview and Summarization:

curl -X POST "https://filesearchrag.usinc.ai/v2/collections" \
  -H "x-api-key: " \
  -F "files=@document.pdf" \
  -F "name=My Documents" \
  -F "summarize=true" \
  -F "preview=1"

Response Format

The API returns a comprehensive JSON response with collection details, file information, and processing statistics.

HTTP Status Codes

StatusMeaning
200Complete success - all files processed
207Partial success - some files failed
400Validation error - invalid request
403Forbidden - collection belongs to another user
500Server error - all files failed

Success Response (HTTP 200)

{
    "status_code": 200,
    "status": "success",
    "api_version": "v2",
    "collection": {
        "id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
        "name": "Q4 Financial Reports",
        "created_at": "2026-02-09T10:30:00.000Z",
        "sub_collections_count": 3
    },
    "sub_collections": [
        "vs_a1b2c3d4e5f6g7h8i9j0",
        "vs_b2c3d4e5f6g7h8i9j0k1",
        "vs_c3d4e5f6g7h8i9j0k1l2"
    ],
    "latest_sub_collection_id": "vs_c3d4e5f6g7h8i9j0k1l2",
    "choices": [
        {
            "id": "file-doc_abc123def456",
            "bytes": 1048576,
            "size": "1.0 MB",
            "created_at": 1707480000,
            "filename": "report.pdf",
            "status": "processed",
            "status_details": "File processed with parent-child chunking",
            "sub_collection_id": "vs_a1b2c3d4e5f6g7h8i9j0",
            "metadata_document_id": "doc_abc123def456",
            "mongo_id": "65c1a2b3c4d5e6f7890abcde",
            "chunks_count": 45,
            "total_tokens": 12500,
            "parser_used": "vision_ocr",
            "chunking_mode": "parent_child",
            "parent_child_stats": {
                "parent_chunks": 15,
                "child_chunks": 45,
                "avg_parent_tokens": 1800,
                "avg_child_tokens": 280
            },
            "performance": {
                "extraction_time": 5.2,
                "chunking_time": 0.8,
                "embedding_time": 2.1,
                "indexing_time": 1.2,
                "total_time": 9.3
            },
            "preview_enabled": true,
            "s3_key": "collections/vs_9b1fd5b2186f45bc/files/report.pdf",
            "s3_url": "https://s3.amazonaws.com/bucket/collections/vs_9b1fd5b2186f45bc/files/report.pdf",
            "content_type": "application/pdf"
        }
    ],
    "processed_files": [
        {
            "filename": "report.pdf",
            "size": "1.0 MB",
            "file_id": "file-doc_abc123def456",
            "chunks": 45
        }
    ],
    "unprocessed_files": null,
    "summary": {
        "total_files": 1,
        "successful": 1,
        "failed": 0,
        "total_chunks": 45,
        "total_size": "1.0 MB",
        "total_size_bytes": 1048576,
        "summarization_enabled": false,
        "chunking_mode": "parent_child",
        "processing_time_seconds": 12.45,
        "avg_time_per_file": 12.45,
        "chunks_per_second": 3.61
    }
}

Partial Success Response (HTTP 207)

{
    "status_code": 207,
    "status": "partial",
    "api_version": "v2",
    "collection": {
        "id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
        "name": "Q4 Financial Reports",
        "created_at": "2026-02-09T10:30:00.000Z",
        "sub_collections_count": 1
    },
    "sub_collections": ["vs_a1b2c3d4e5f6g7h8i9j0"],
    "latest_sub_collection_id": "vs_a1b2c3d4e5f6g7h8i9j0",
    "choices": [
        {
            "id": "file-doc_abc123def456",
            "bytes": 1048576,
            "size": "1.0 MB",
            "created_at": 1707480000,
            "filename": "report.pdf",
            "status": "processed",
            "status_details": "File processed with parent-child chunking",
            "sub_collection_id": "vs_a1b2c3d4e5f6g7h8i9j0",
            "chunks_count": 45
        },
        {
            "id": null,
            "bytes": 2097152,
            "size": "2.0 MB",
            "created_at": 1707480000,
            "filename": "corrupted.pdf",
            "status": "error",
            "status_details": "Failed to extract text from file",
            "sub_collection_id": null
        }
    ],
    "processed_files": [
        {"filename": "report.pdf", "size": "1.0 MB", "file_id": "file-doc_abc123def456", "chunks": 45}
    ],
    "unprocessed_files": [
        {"filename": "corrupted.pdf", "size": "2.0 MB", "error": "Failed to extract text from file"}
    ],
    "summary": {
        "total_files": 2,
        "successful": 1,
        "failed": 1,
        "total_chunks": 45,
        "total_size": "3.0 MB",
        "total_size_bytes": 3145728,
        "summarization_enabled": false,
        "chunking_mode": "parent_child",
        "processing_time_seconds": 15.32,
        "avg_time_per_file": 7.66,
        "chunks_per_second": 2.94
    }
}

Response Fields Reference

Top-Level Fields

FieldTypeDescription
status_codeintegerHTTP status code: 200 (success), 207 (partial), 500 (error)
statusstringOverall status: "success", "partial", or "error"
api_versionstringAPI version identifier ("v2")
collectionobjectCollection metadata object
sub_collectionsarrayList of all sub-collection IDs (format: vs_*)
latest_sub_collection_idstringMost recently created sub-collection ID
choicesarrayDetailed information for each uploaded file
processed_filesarrayList of successfully processed files
unprocessed_filesarray | nullList of failed files, null if all succeeded
summaryobjectProcessing statistics

Collection Object

FieldTypeDescription
idstringCollection ID (format: vs_*)
namestringDisplay name of the collection
created_atstringISO 8601 timestamp
sub_collections_countintegerNumber of sub-collections

Choice Object (File Details)

FieldTypeDescription
idstring | nullUnique file identifier (format: file-{document_id}), null if failed
bytesintegerFile size in bytes
sizestringHuman-readable file size (e.g., "1.5 MB")
created_atintegerUnix timestamp when file was processed
filenamestringOriginal filename
statusstring"processed" or "error"
status_detailsstringDetailed status message
sub_collection_idstring | nullSub-collection ID where file is stored (null if failed)
metadata_document_idstringInternal document reference ID
mongo_idstringMongoDB document ID
chunks_countintegerNumber of text chunks created
total_tokensintegerTotal token count across all chunks
parser_usedstringParser type ("vision_ocr", "text_parser", etc.)
chunking_modestringChunking strategy used ("parent_child")
parent_child_statsobjectStatistics about parent/child chunks
performanceobjectDetailed timing breakdown
preview_enabledbooleanWhether S3 preview is available
s3_keystringS3 object key (when preview enabled)
s3_urlstringS3 URL for file preview (when preview enabled)
content_typestringMIME type of the file

Summary Object

FieldTypeDescription
total_filesintegerTotal number of files in request
successfulintegerNumber of successfully processed files
failedintegerNumber of files that failed
total_chunksintegerTotal chunks created across all files
total_sizestringHuman-readable total size
total_size_bytesintegerTotal size in bytes
summarization_enabledbooleanWhether summarization was enabled
chunking_modestringChunking strategy ("parent_child")
processing_time_secondsfloatTotal processing time
avg_time_per_filefloatAverage time per file
chunks_per_secondfloatProcessing throughput metric

SSE Streaming Mode

When stream=true, the API returns Server-Sent Events for real-time progress updates.

SSE Stages

StageDescription
startingProcessing initiated
extractionText extraction progress (0-100%)
chunkingDocument chunking progress (0-100%)
embeddingVector embedding progress (0-100%)
storingDatabase storage progress (0-100%)
completeProcessing finished successfully
errorProcessing failed

SSE Event Format

event: file_progress
data: {"filename": "report.pdf", "stage": "extraction", "progress": 45, "message": "Extracting text..."}

event: file_progress
data: {"filename": "report.pdf", "stage": "embedding", "progress": 80, "message": "Generating embeddings..."}

event: complete
data: {"status": "success", "collection_id": "vs_9b1fd5b2186f45bc", "total_chunks": 45}

Supported File Types

FormatExtensionMIME Type
PDF.pdfapplication/pdf
PNG Image.pngimage/png
JPEG Image.jpg, .jpegimage/jpeg

Error Handling

Error Response Format

{
    "error": {
        "message": "Error description",
        "type": "validation_error",
        "code": "ERROR_CODE",
        "status_code": 400,
        "correlation_id": "abc12345",
        "timestamp": "2026-02-09T10:30:00.000Z",
        "param": "field_name"
    }
}

Common Error Codes

Error CodeHTTP StatusDescription
no_files_provided400No files were provided in the request
too_many_files400More than 10 files in a single request
invalid_file_extension400File type not in supported formats list
file_too_large400Individual file exceeds 100 MB limit
batch_too_large400Total upload size exceeds 100 MB limit
collection_not_found404Specified collection_id does not exist
forbidden403Collection belongs to another user
internal_error500Server-side processing error

Best Practices

  1. Validate Files Before Upload: Check file size (up to 100 MB OR up to 5,000 pages) and extension before sending requests
  2. Handle Partial Success: When status_code is 207, check both processed_files and unprocessed_files
  3. Store Sub-Collection IDs: Save the returned latest_sub_collection_id for use in /v2/filesearch
  4. Use Meaningful Names: Set descriptive name values for easy identification
  5. Batch Related Documents: Upload related files together for logical groupings
  6. Implement Retry Logic: For 5xx errors, use exponential backoff with max 3 attempts
  7. Monitor Performance: Check summary.processing_time_seconds for throughput optimization
  8. Use Append for Updates: Use collection_id parameter to add files to existing collections

After uploading files, use the returned sub_collection_id or latest_sub_collection_id with the /v2/filesearch endpoint:

curl -X POST "https://filesearchrag.usinc.ai/v2/filesearch" \
  -H "x-api-key: " \
  -H "Content-Type: application/json" \
  -d '{
    "model": "usf1-mini",
    "messages": [{"role": "user", "content": "What are the key findings?"}],
    "collection_name": "vs_9b1fd5b2186f45bc9a35eab321c8318f"
  }'

Additional Endpoints

Get Collection Details

curl -X GET "https://filesearchrag.usinc.ai/v2/collections/vs_9b1fd5b2186f45bc9a35eab321c8318f" \
  -H "x-api-key: "

Delete Collection

Delete entire collection:

curl -X DELETE "https://filesearchrag.usinc.ai/v2/collections/vs_9b1fd5b2186f45bc9a35eab321c8318f?is_sub_collection=false" \
  -H "x-api-key: "

Delete sub-collection only:

curl -X DELETE "https://filesearchrag.usinc.ai/v2/collections/vs_a1b2c3d4e5f6g7h8?is_sub_collection=true" \
  -H "x-api-key: "

FileSearch API

Endpoint: POST /v2/filesearch

Overview

The FileSearch API enables RAG-powered (Retrieval-Augmented Generation) semantic search across your document collections. It combines advanced hybrid search (BM25 keyword + semantic vector search) with LLM-generated responses that include inline citations to source documents.

Key Features

FeatureDescription
Hybrid SearchBM25 keyword + semantic vector search with RRF fusion
Parent-Child ContextChild chunks for precise matching, parent chunks for full LLM context
Inline CitationsAutomatic [[N]] citation generation with source mapping
Conversation HistoryMulti-turn conversations via messages array or conversation_id
SSE StreamingReal-time response streaming with progress events
Web Search AugmentationOptional web search to supplement document context
File FilteringSearch within specific files or collections
Pagination SupportLimit/offset pagination with retrieval token caching
Search ModesHybrid, semantic-only, or keyword-only search
Redis CachingInstant responses for repeat queries (1-hour TTL)
User IsolationStrict access control - users only see their own collections

API Endpoint

MethodURL
POSThttps://filesearchrag.usinc.ai/v2/filesearch

Authentication

All API requests require authentication using an API key passed in the request header.

HeaderTypeRequiredDescription
x-api-keystringYesYour API authentication key

Example API Key:

x-api-key: <YOUR_API_KEY>

⚠️ Security Note: Keep your API key secure and never expose it in client-side code or public repositories.

Request Format

Requests must be sent as application/json with a JSON body.

Request Parameters

Core Parameters

ParameterTypeRequiredDefaultDescription
modelstringNo"usf1-mini"LLM model to use for response generation
messagesarrayYes-Conversation messages (min 1, max 100). Must contain at least one user message
temperaturefloatNo0.7Response creativity (0.0-2.0). Lower = more focused, higher = more creative
max_tokensintegerNo4000Maximum response tokens (1-16000)
streambooleanNofalseEnable SSE streaming for real-time responses

Collection & File Parameters

ParameterTypeRequiredDefaultDescription
collection_idstringNonullCollection ID to search (format: vs_*). Supports comma-separated IDs for multi-collection search
file_idstringNonullFilter search to specific file (format: file-{uuid} or {uuid})
conversation_idstringNoauto-generatedID for maintaining conversation history across requests

Search Parameters

ParameterTypeRequiredDefaultRangeDescription
search_typestringNo"hybrid"hybrid/semantic/keywordSearch mode for document retrieval
top_kintegerNo205-100Number of documents to retrieve from initial search
web_searchbooleanNofalse-Enable web search augmentation for additional context

Pagination Parameters

ParameterTypeRequiredDefaultRangeDescription
limitintegerNo101-50Number of documents for LLM context per page
offsetintegerNo0≥0Starting position in results for pagination
retrieval_tokenstringNonullmax 50 charsToken from previous response to reuse cached search results (skips re-search)

Message Object

FieldTypeRequiredDescription
rolestringYesMessage role: "system", "user", or "assistant"
contentstringYesMessage content

Request Body Schema

{
    "model": "usf1-mini",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "What are the key findings in the Q4 report?"
        }
    ],
    "temperature": 0.7,
    "max_tokens": 4000,
    "stream": false,
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "conversation_id": null,
    "web_search": false,
    "file_id": null,
    "search_type": "hybrid",
    "top_k": 20,
    "limit": 10,
    "offset": 0,
    "retrieval_token": null
}

Request Behavior

BehaviorDescription
Collection ResolutionParent collection IDs are automatically expanded to search all sub-collections
Multi-Collection SearchPass comma-separated IDs to search multiple collections: "vs_abc123,vs_def456"
File FilteringWhen file_id is provided, search is restricted to that specific file
Conversation HistoryProvide previous messages in the messages array OR use conversation_id to retrieve from database
Context OverflowIf retrieved context exceeds 15,000 tokens, returns suggested questions instead of direct answer
Pagination CachingWhen retrieval_token is provided, cached search results are used (no re-search)
Search Modeshybrid (default) combines BM25+semantic; semantic uses vector search only; keyword uses BM25 only

Search Modes

ModeDescriptionUse Case
hybridBM25 + Semantic with RRF fusionBest accuracy (default)
semanticVector search onlyMeaning-based queries, synonyms
keywordBM25 search onlyExact term matching, technical terms

Pagination System

How Pagination Works

  1. First Request: Fresh search runs, results cached with retrieval_token
  2. Subsequent Requests: Pass retrieval_token + different offset to paginate
  3. Token Expiry: Retrieval tokens expire after 5 minutes (300 seconds)

Pagination Flow Example

Request 1: Fresh Search

{
    "messages": [{"role": "user", "content": "List all contracts"}],
    "collection_id": "vs_abc123",
    "limit": 10,
    "offset": 0
}

Response 1:

{
    "pagination": {
        "offset": 0,
        "limit": 10,
        "total": 25,
        "has_more": true,
        "retrieval_token": "ret_abc123def456",
        "retrieval_token_expires_in": 300
    }
}

Request 2: Paginated (No Re-Search)

{
    "messages": [{"role": "user", "content": "List all contracts"}],
    "collection_id": "vs_abc123",
    "limit": 10,
    "offset": 10,
    "retrieval_token": "ret_abc123def456"
}

Response 2:

{
    "pagination": {
        "offset": 10,
        "limit": 10,
        "total": 25,
        "has_more": true,
        "retrieval_token": "ret_abc123def456",
        "retrieval_token_expires_in": 300
    }
}

Usage Examples

Python

Basic Search:

import requests

url = "https://filesearchrag.usinc.ai/v2/filesearch"
headers = {
    "x-api-key": "<YOUR_API_KEY>",
    "Content-Type": "application/json"
}

payload = {
    "model": "usf1-mini",
    "messages": [
        {"role": "user", "content": "What are the key findings in the Q4 report?"}
    ],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f"
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

print(f"Answer: {result['choices'][0]['message']['content']}")
print(f"Citations: {result['citations']}")
print(f"Docs used: {result['search_summary']['docs_used']}")

Multi-Turn Conversation:

import requests

url = "https://filesearchrag.usinc.ai/v2/filesearch"
headers = {
    "x-api-key": "<YOUR_API_KEY>",
    "Content-Type": "application/json"
}

# First message
payload = {
    "model": "usf1-mini",
    "messages": [
        {"role": "user", "content": "What was the total revenue in Q4?"}
    ],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f"
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()
conversation_id = result['conversation_id']

# Follow-up message with history
payload = {
    "model": "usf1-mini",
    "messages": [
        {"role": "user", "content": "What was the total revenue in Q4?"},
        {"role": "assistant", "content": result['choices'][0]['message']['content']},
        {"role": "user", "content": "How does that compare to Q3?"}
    ],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "conversation_id": conversation_id
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()
print(f"Answer: {result['choices'][0]['message']['content']}")

Search with File Filter:

import requests

url = "https://filesearchrag.usinc.ai/v2/filesearch"
headers = {
    "x-api-key": "<YOUR_API_KEY>",
    "Content-Type": "application/json"
}

payload = {
    "model": "usf1-mini",
    "messages": [
        {"role": "user", "content": "Summarize the main points"}
    ],
    "file_id": "file-abc123def456"  # Search only within this file
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

print(f"Answer: {result['choices'][0]['message']['content']}")
print(f"File: {result['file_filter']['filename']}")

Pagination:

import requests

url = "https://filesearchrag.usinc.ai/v2/filesearch"
headers = {
    "x-api-key": "<YOUR_API_KEY>",
    "Content-Type": "application/json"
}

# First request - get first page
payload = {
    "messages": [{"role": "user", "content": "List all contracts"}],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "limit": 5,
    "offset": 0
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()
print(f"Page 1: {result['search_summary']['docs_used']} of {result['pagination']['total']} docs")

# Get next page using retrieval_token (no re-search)
if result['pagination']['has_more']:
    payload = {
        "messages": [{"role": "user", "content": "List all contracts"}],
        "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
        "limit": 5,
        "offset": 5,
        "retrieval_token": result['pagination']['retrieval_token']
    }

    response = requests.post(url, headers=headers, json=payload)
    result = response.json()
    print(f"Page 2: {result['search_summary']['docs_used']} more docs")

Streaming Response:

import requests
import json

url = "https://filesearchrag.usinc.ai/v2/filesearch"
headers = {
    "x-api-key": "<YOUR_API_KEY>",
    "Content-Type": "application/json"
}

payload = {
    "model": "usf1-mini",
    "messages": [
        {"role": "user", "content": "What are the key findings?"}
    ],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "stream": True
}

response = requests.post(url, headers=headers, json=payload, stream=True)

for line in response.iter_lines():
    if line:
        line_str = line.decode('utf-8')
        if line_str.startswith('data: '):
            data_str = line_str[6:]
            if data_str.strip() == '[DONE]':
                break
            try:
                chunk = json.loads(data_str)
                if 'choices' in chunk and chunk['choices']:
                    delta = chunk['choices'][0].get('delta', {})
                    content = delta.get('content', '')
                    if content:
                        print(content, end='', flush=True)
            except json.JSONDecodeError:
                continue

With Web Search Augmentation:

import requests

url = "https://filesearchrag.usinc.ai/v2/filesearch"
headers = {
    "x-api-key": "<YOUR_API_KEY>",
    "Content-Type": "application/json"
}

payload = {
    "model": "usf1-mini",
    "messages": [
        {"role": "user", "content": "What are the latest industry trends?"}
    ],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "web_search": True  # Combine document search with web results
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

print(f"Answer: {result['choices'][0]['message']['content']}")
if 'executable_data' in result:
    print(f"Web sources: {len(result['executable_data'][0]['data'])} results")

Search with Specific Mode:

import requests

url = "https://filesearchrag.usinc.ai/v2/filesearch"
headers = {
    "x-api-key": "<YOUR_API_KEY>",
    "Content-Type": "application/json"
}

# Semantic-only search (meaning-based)
payload = {
    "model": "usf1-mini",
    "messages": [
        {"role": "user", "content": "What are the financial risks?"}
    ],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "search_type": "semantic",
    "top_k": 15
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

print(f"Search type: {result['search_summary']['search_type']}")
print(f"Answer: {result['choices'][0]['message']['content']}")

JavaScript

Basic Search:

const axios = require('axios');

async function searchDocuments() {
    try {
        const response = await axios.post(
            'https://filesearchrag.usinc.ai/v2/filesearch',
            {
                model: 'usf1-mini',
                messages: [
                    { role: 'user', content: 'What are the key findings in the Q4 report?' }
                ],
                collection_id: 'vs_9b1fd5b2186f45bc9a35eab321c8318f'
            },
            {
                headers: {
                    'x-api-key': '<YOUR_API_KEY>',
                    'Content-Type': 'application/json'
                }
            }
        );

        console.log('Answer:', response.data.choices[0].message.content);
        console.log('Citations:', response.data.citations);
        console.log('Sources:', response.data.sources.length);
    } catch (error) {
        console.error(error.response?.data || error.message);
    }
}

searchDocuments();

Streaming Response:

const axios = require('axios');

async function streamSearch() {
    const response = await axios.post(
        'https://filesearchrag.usinc.ai/v2/filesearch',
        {
            model: 'usf1-mini',
            messages: [
                { role: 'user', content: 'What are the key findings?' }
            ],
            collection_id: 'vs_9b1fd5b2186f45bc9a35eab321c8318f',
            stream: true
        },
        {
            headers: {
                'x-api-key': '<YOUR_API_KEY>',
                'Content-Type': 'application/json'
            },
            responseType: 'stream'
        }
    );

    response.data.on('data', (chunk) => {
        const lines = chunk.toString().split('\n');
        for (const line of lines) {
            if (line.startsWith('data: ')) {
                const dataStr = line.slice(6);
                if (dataStr.trim() === '[DONE]') return;
                try {
                    const data = JSON.parse(dataStr);
                    const content = data.choices?.[0]?.delta?.content;
                    if (content) process.stdout.write(content);
                } catch (e) {}
            }
        }
    });
}

streamSearch();

cURL

Basic Search:

curl -X POST "https://filesearchrag.usinc.ai/v2/filesearch" \
  -H "x-api-key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "usf1-mini",
    "messages": [{"role": "user", "content": "What are the key findings?"}],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f"
  }'

With Custom System Prompt:

curl -X POST "https://filesearchrag.usinc.ai/v2/filesearch" \
  -H "x-api-key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "usf1-mini",
    "messages": [
      {"role": "system", "content": "You are a financial analyst. Provide concise, data-driven answers."},
      {"role": "user", "content": "What was the revenue growth rate?"}
    ],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "temperature": 0.3
  }'

Streaming Response:

curl -X POST "https://filesearchrag.usinc.ai/v2/filesearch" \
  -H "x-api-key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "usf1-mini",
    "messages": [{"role": "user", "content": "What are the key findings?"}],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "stream": true
  }'

Search Multiple Collections:

curl -X POST "https://filesearchrag.usinc.ai/v2/filesearch" \
  -H "x-api-key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "usf1-mini",
    "messages": [{"role": "user", "content": "Compare the Q3 and Q4 results"}],
    "collection_id": "vs_abc123,vs_def456"
  }'

With Pagination:

curl -X POST "https://filesearchrag.usinc.ai/v2/filesearch" \
  -H "x-api-key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "usf1-mini",
    "messages": [{"role": "user", "content": "List all contracts"}],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "limit": 10,
    "offset": 0
  }'

With Search Type:

curl -X POST "https://filesearchrag.usinc.ai/v2/filesearch" \
  -H "x-api-key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "usf1-mini",
    "messages": [{"role": "user", "content": "Find exact term: indemnification clause"}],
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "search_type": "keyword",
    "top_k": 20
  }'

Response Format

Success Response (HTTP 200)

{
    "id": "chatcmpl-abc123def456",
    "object": "filesearch.completion",
    "created": 1707480000,
    "model": "usf1-mini",
    "api_version": "v2",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Based on the Q4 report, total revenue increased by 25% to $331.7M [[1]], driven primarily by market expansion in the APAC region [[2]]. Customer acquisition costs decreased by 12% [[1]], while the net promoter score improved to 27 [[3]]."
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 2500,
        "completion_tokens": 150,
        "total_tokens": 2650
    },
    "conversation_id": "abc123def456",
    "history_source": "messages",
    "citations": [
        {
            "index": 1,
            "filename": "Q4_Report.pdf",
            "page": 5,
            "snippet": "Total revenue for Q4 2025 reached $331.7M, representing a 25% increase...",
            "confidence": 0.95
        },
        {
            "index": 2,
            "filename": "Q4_Report.pdf",
            "page": 12,
            "snippet": "APAC region contributed 45% of new customer acquisitions...",
            "confidence": 0.89
        },
        {
            "index": 3,
            "filename": "Q4_Report.pdf",
            "page": 8,
            "snippet": "Net Promoter Score improved from 21 to 27...",
            "confidence": 0.92
        }
    ],
    "sources": [
        {
            "document": "Full parent chunk text with complete context...",
            "filename": "Q4_Report.pdf",
            "score": 0.95,
            "chunk_type": "parent",
            "page": 5,
            "collection_name": "vs_9b1fd5b2186f45bc9a35eab321c8318f"
        }
    ],
    "search_summary": {
        "search_type": "hybrid",
        "context_tokens": 4500,
        "response_path": "direct",
        "docs_used": 3,
        "docs_found": 8,
        "bm25_count": 5,
        "bm25_matches": [
            {
                "rank": 1,
                "score": 0.92,
                "page": 5,
                "filename": "Q4_Report.pdf",
                "snippet": "Total revenue for Q4 2025..."
            }
        ],
        "semantic_count": 6,
        "semantic_matches": [
            {
                "rank": 1,
                "score": 0.89,
                "page": 12,
                "filename": "Q4_Report.pdf",
                "snippet": "APAC region contributed..."
            }
        ],
        "merged_results": 8,
        "rrf_k": 60,
        "top_sources": [
            {
                "document_id": "file-abc123",
                "filename": "Q4_Report.pdf",
                "page": 5,
                "relevance_score": 0.95,
                "match_type": "both",
                "bm25_rank": 1,
                "semantic_rank": 2,
                "collection_name": "vs_9b1fd5b2186f45bc9a35eab321c8318f"
            }
        ],
        "all_retrieved_files": ["Q4_Report.pdf", "Q3_Report.pdf", "Annual_Summary.pdf"],
        "all_retrieved_count": 3
    },
    "pagination": {
        "offset": 0,
        "limit": 10,
        "total": 8,
        "has_more": false,
        "retrieval_token": "ret_abc123def456",
        "retrieval_token_expires_in": 300
    },
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "context_overflow": false,
    "search_notice": null,
    "suggested_questions": null,
    "history": [],
    "file_filter": null
}

Context Overflow Response

When retrieved context exceeds 15,000 tokens, the API returns suggested questions instead of attempting to process all content:

{
    "id": "chatcmpl-abc123def456",
    "object": "filesearch.completion",
    "created": 1707480000,
    "model": "usf1-mini",
    "api_version": "v2",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "I found 25 relevant sections across your documents about 'financial performance'. To provide the most accurate answer, please narrow your search by selecting one of the suggested questions below."
            },
            "finish_reason": "context_overflow"
        }
    ],
    "usage": {
        "prompt_tokens": 0,
        "completion_tokens": 0,
        "total_tokens": 0
    },
    "conversation_id": "abc123def456",
    "context_overflow": true,
    "found_results": 25,
    "suggested_questions": [
        {
            "text": "What are the details in Table 15.1.3?",
            "reason": "Found 8 matches on pages 12, 13, 14",
            "match_count": 8,
            "pages": [12, 13, 14]
        },
        {
            "text": "Tell me about Revenue Analysis",
            "reason": "Found 6 matches on pages 5, 6, 7",
            "match_count": 6,
            "pages": [5, 6, 7]
        }
    ],
    "available_topics": [
        {
            "topic": "Revenue Analysis",
            "matches": 6,
            "pages": [5, 6, 7]
        },
        {
            "topic": "Cost Structure",
            "matches": 4,
            "pages": [15, 16]
        }
    ],
    "search_summary": {
        "search_type": "hybrid",
        "context_tokens": 18500,
        "response_path": "suggested_questions",
        "bm25_count": 12,
        "semantic_count": 15,
        "merged_results": 25,
        "top_sources": [...]
    },
    "pagination": {
        "offset": 0,
        "limit": 10,
        "total": 25,
        "has_more": true,
        "retrieval_token": "ret_abc123def456",
        "retrieval_token_expires_in": 300
    }
}

Response Fields Reference

Top-Level Fields

FieldTypeDescription
idstringUnique completion ID (format: chatcmpl-{conversation_id})
objectstringResponse type: "filesearch.completion"
createdintegerUnix timestamp of response creation
modelstringLLM model used for generation
api_versionstringAPI version ("v2")
choicesarrayArray containing the response message
usageobjectToken usage statistics
conversation_idstringID for conversation continuity
history_sourcestringSource of conversation history: "none", "messages", or "database"
citationsarrayInline citation references with source details
sourcesarraySource documents used for context
search_summaryobjectDetailed search metadata and statistics
paginationobjectPagination metadata for limit/offset support
collection_idstringCollection ID(s) that were searched
context_overflowbooleanWhether context exceeded 15K token threshold
search_noticestring | nullNotice about pagination (when has_more is true)
suggested_questionsarray | nullSuggested follow-up questions (context overflow only)
historyarrayPrevious conversation messages
file_filterobject | nullFile filter info when file_id is used

Choice Object

FieldTypeDescription
indexintegerChoice index (always 0)
messageobjectAssistant's response message
finish_reasonstring"stop" for normal completion, "context_overflow" for overflow

Message Object

FieldTypeDescription
rolestringAlways "assistant"
contentstringGenerated answer with [[N]] inline citations
reasoningstring(Optional) Chain-of-thought reasoning when web_search enabled

Citation Object

FieldTypeDescription
indexintegerCitation number matching [[N]] in response
filenamestringSource document filename
pageinteger | nullPage number in source document
snippetstringText excerpt from source (child chunk)
confidencefloatRelevance confidence score (0.0-1.0)

Source Object

FieldTypeDescription
documentstringFull parent chunk text (complete context)
filenamestringSource document filename
scorefloatRelevance score (rounded to 2 decimals)
chunk_typestring"parent" or "child"
pageintegerPage number
collection_namestringCollection ID containing this document

Search Summary Object

FieldTypeDescription
search_typestringSearch mode used: "hybrid", "semantic", or "keyword"
context_tokensintegerTotal tokens in retrieved context
response_pathstring"direct" or "suggested_questions"
docs_usedintegerDocuments in current page (after limit/offset)
docs_foundintegerTotal documents found (before pagination)
bm25_countintegerDocuments matched by BM25 keyword search
bm25_matchesarrayTop BM25 matches with rank, score, snippet
semantic_countintegerDocuments matched by semantic search
semantic_matchesarrayTop semantic matches with rank, score, snippet
merged_resultsintegerTotal unique documents after RRF fusion
rrf_kintegerRRF constant used (default: 60)
top_sourcesarrayDetailed info about top matched documents
all_retrieved_filesarrayAll unique filenames retrieved (before truncation)
all_retrieved_countintegerCount of all unique files retrieved

BM25/Semantic Match Object

FieldTypeDescription
rankintegerPosition in search results
scorefloatSearch score (rounded to 2 decimals)
pageintegerPage number
filenamestringSource document filename
snippetstringText excerpt (truncated to 200 chars)

Top Source Object

FieldTypeDescription
document_idstringUnique document/file ID
filenamestringSource document filename
pageintegerPage number
relevance_scorefloatRelevance score (rounded to 2 decimals)
match_typestring"both", "keyword", or "semantic"
bm25_rankinteger | nullRank in BM25 results (null if not matched)
semantic_rankinteger | nullRank in semantic results (null if not matched)
collection_namestringCollection ID

Pagination Object

FieldTypeDescription
offsetintegerCurrent offset position
limitintegerCurrent page size
totalintegerTotal documents found by search
has_morebooleanWhether more results exist beyond current page
retrieval_tokenstringToken to use for subsequent pagination requests
retrieval_token_expires_inintegerSeconds until token expires (300)

Usage Object

FieldTypeDescription
prompt_tokensintegerTokens in the prompt (context + messages)
completion_tokensintegerTokens in the generated response
total_tokensintegerTotal tokens used

File Filter Object

FieldTypeDescription
file_idstringThe file ID that was used to filter
filenamestringResolved filename for the file
collection_idstringCollection containing the file

SSE Streaming Format

When stream: true, the API returns Server-Sent Events (SSE) with real-time progress updates.

Progress Events

data: {"event": "progress", "data": {"status": "searching", "detail": "Running hybrid search (BM25 + Semantic)"}}

data: {"event": "progress", "data": {"status": "reranked", "detail": "Found 8 relevant documents"}}

data: {"event": "progress", "data": {"status": "generating", "detail": "Starting LLM response generation"}}

Content Chunks

data: {"id": "chatcmpl-abc123", "object": "chat.completion.chunk", "created": 1707480000, "model": "usf1-mini", "api_version": "v2", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Based on the Q4 report, "}, "finish_reason": null}]}

data: {"id": "chatcmpl-abc123", "object": "chat.completion.chunk", "created": 1707480000, "model": "usf1-mini", "api_version": "v2", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "total revenue increased by 25% [[1]]. "}, "finish_reason": null}]}

Final Chunk

data: {"id": "chatcmpl-abc123", "object": "filesearch.completion", "created": 1707480000, "model": "usf1-mini", "api_version": "v2", "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 2500, "completion_tokens": 150, "total_tokens": 2650}, "citations": [...], "sources": [...]}

data: {"event": "progress", "data": {"status": "complete", "detail": "Response generation finished"}}

data: [DONE]

Progress Status Values

StatusDescription
searchingRunning hybrid search (BM25 + semantic)
cachedUsing cached retrieval results
rerankedDocuments reranked by relevance
generatingLLM response generation started
completeResponse generation finished

Error Handling

Error Response Format

{
    "error": {
        "message": "Error description",
        "type": "validation_error",
        "code": "ERROR_CODE",
        "status_code": 400,
        "correlation_id": "abc12345",
        "timestamp": "2026-02-09T10:30:00.000Z",
        "param": "field_name"
    }
}

Common Error Codes

Error CodeHTTP StatusDescription
missing_user_message400No user message found in messages array
too_many_messages400More than 100 messages in request
context_length_exceeded400Prompt exceeds 100,000 token limit
collection_not_found404Specified collection_id does not exist
file_not_found404Specified file_id does not exist
forbidden403Collection or file belongs to another user
llm_service_error502LLM API returned an error
service_unavailable503LLM service not configured or unavailable
service_timeout504LLM service timed out after retries
parse_error500Failed to parse LLM response
internal_error500Server-side processing error

Retry Logic

The API implements automatic retry for transient failures:

AttemptDelayTotal Wait
10s0s
21s1s
32s3s

Retryable Status Codes: 502, 503, 504, Timeout

Best Practices

PracticeDescription
Use Specific QueriesMore specific questions yield better citations and focused answers
Filter by Collection/FileUse collection_id or file_id to narrow search scope for faster, more relevant results
Choose Search ModeUse hybrid (default) for best accuracy; keyword for exact terms; semantic for meaning-based
Use PaginationSet appropriate limit and use retrieval_token for paginating through large result sets
Handle Context OverflowWhen receiving context_overflow: true, use the suggested_questions to refine your query
Use Streaming for UXEnable stream: true for better user experience with real-time response display
Maintain ConversationUse conversation_id or pass previous messages for multi-turn conversations
Check CitationsVerify important claims using the citations array with page numbers and snippets
Monitor UsageTrack usage.total_tokens for cost estimation and optimization
Handle RetriesImplement retry logic for 5xx errors with exponential backoff
Leverage CachingThe API caches repeat queries for 1 hour; retrieval tokens cache for 5 minutes

Technical Configuration

Configuration Constants

ConstantValueDescription
CONTEXT_THRESHOLD_DIRECT15,000Token threshold for direct vs overflow path
LLM_FINAL_TIMEOUT45.0sTimeout for LLM calls
LLM_STREAM_TIMEOUT60.0sTimeout for streaming LLM calls
LLM_MAX_RETRIES2Max retry attempts for LLM calls
RERANK_TIMEOUT15.0sTimeout for reranker API
RETRIEVAL_CACHE_TTL300sRetrieval token cache expiry
DEFAULT_CACHE_TTL3600sResponse cache expiry
DEFAULT_RRF_K60RRF fusion constant
ENTITY_MATCH_BOOST1.5xBM25 boost for explicitly named files

List Collections API

Endpoint: GET /v2/collections

Overview

Retrieves all collections belonging to the authenticated user with file details, sub-collections, and processing status.

API Endpoint

MethodURL
GEThttps://filesearchrag.usinc.ai/v2/collections

Authentication

HeaderTypeRequiredDescription
x-api-keystringYesYour API authentication key

Usage Examples

Python

import requests

url = "https://filesearchrag.usinc.ai/v2/collections"
headers = {"x-api-key": ""}

response = requests.get(url, headers=headers)
result = response.json()

print(f"Total collections: {result['total']}")
for collection in result['data']:
    print(f"Collection: {collection['collection']['name']} - {collection['summary']['total_files']} files")

JavaScript

const axios = require('axios');

const response = await axios.get(
    'https://filesearchrag.usinc.ai/v2/collections',
    { headers: { 'x-api-key': '' } }
);

console.log('Total:', response.data.total);

cURL

curl -X GET "https://filesearchrag.usinc.ai/v2/collections" \
  -H "x-api-key: "

Response Format

{
    "status_code": 200,
    "status": "success",
    "api_version": "v2",
    "data": [
        {
            "collection": {
                "id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
                "name": "Q4 Financial Reports",
                "created_at": "2026-02-09T10:30:00.000Z",
                "sub_collections_count": 3,
                "processing_status": {
                    "status": "completed",
                    "progress_percent": 100,
                    "total_files": 5,
                    "processed_files": 5,
                    "failed_files": 0
                }
            },
            "sub_collections": ["vs_a1b2c3d4e5f6g7h8i9j0"],
            "latest_sub_collection_id": "vs_a1b2c3d4e5f6g7h8i9j0",
            "choices": [
                {
                    "id": "file-doc_abc123def456",
                    "filename": "report.pdf",
                    "size": "1.0 MB",
                    "chunks_count": 45,
                    "status": "processed",
                    "sub_collection_id": "vs_a1b2c3d4e5f6g7h8i9j0"
                }
            ],
            "summary": {
                "total_files": 1,
                "successful": 1,
                "failed": 0,
                "total_chunks": 45,
                "total_size": "1.0 MB"
            }
        }
    ],
    "total": 1
}

Response Fields

FieldTypeDescription
dataarrayArray of collection objects
totalintegerTotal number of collections
data[].collection.idstringCollection ID (format: vs_*)
data[].collection.namestringCollection display name
data[].collection.processing_statusobjectCurrent processing status
data[].sub_collectionsarrayList of sub-collection IDs
data[].latest_sub_collection_idstringMost recent sub-collection ID
data[].choicesarrayFile details array
data[].summaryobjectAggregated statistics

Error Handling

{
    "error": {
        "message": "Error description",
        "type": "internal_error",
        "code": "internal_error",
        "status_code": 500
    }
}

Delete Collection API

Endpoint: DELETE /v2/collections/{col_id}

Overview

Delete a collection or sub-collection by ID. Supports two deletion modes:

  • Full Delete: Remove entire collection with all sub-collections and files
  • Sub-Collection Delete: Remove only a specific sub-collection

Deletion pipeline:

  1. Find collection/sub-collection in MongoDB
  2. Delete vectors from Qdrant
  3. Delete file metadata from MongoDB DocData
  4. Delete/update collection record

API Endpoint

MethodURL
DELETEhttps://filesearchrag.usinc.ai/v2/collections/{col_id}

Authentication

HeaderTypeRequiredDescription
x-api-keystringYesYour API authentication key

Path Parameters

ParameterTypeRequiredDescription
col_idstringYesCollection ID or Sub-Collection ID to delete (format: vs_*)

Query Parameters

ParameterTypeRequiredDefaultDescription
is_sub_collectionbooleanNofalseDeletion mode: false = delete entire collection, true = delete only the specified sub-collection

Usage Examples

Python

Delete Entire Collection (default behavior):

import requests

# Use collection_id (parent collection ID)
collection_id = "vs_9b1fd5b2186f45bc9a35eab321c8318f"
url = f"https://filesearchrag.usinc.ai/v2/collections/{collection_id}"
headers = {"x-api-key": ""}

# No params needed - defaults to deleting entire collection
response = requests.delete(url, headers=headers)
result = response.json()

print(f"Deleted: {result['collection_name']}")
print(f"Sub-collections removed: {result['summary']['sub_collections_removed']}")
print(f"Documents removed: {result['summary']['total_docs_removed']}")

Delete Sub-Collection Only:

import requests

# Use sub_collection_id (child sub-collection ID from collection's sub_collections array)
sub_collection_id = "vs_4f14ee1a-46c7-4b49-a683-6a44e18b4d56"
url = f"https://filesearchrag.usinc.ai/v2/collections/{sub_collection_id}"
headers = {"x-api-key": ""}

# is_sub_collection=true - deletes only this sub-collection
response = requests.delete(url, headers=headers, params={"is_sub_collection": True})
result = response.json()

print(f"Deleted sub-collection: {result['sub_collection_id']}")
print(f"Parent collection: {result['parent_collection_id']}")
print(f"Documents removed: {result['docs_deleted']}")

JavaScript

Delete Entire Collection (default behavior):

const axios = require('axios');

// Use collection_id (parent collection ID)
const collectionId = 'vs_9b1fd5b2186f45bc9a35eab321c8318f';

const response = await axios.delete(
    `https://filesearchrag.usinc.ai/v2/collections/${collectionId}`,
    { headers: { 'x-api-key': '' } }
);

console.log('Deleted:', response.data.collection_name);
console.log('Sub-collections removed:', response.data.summary.sub_collections_removed);

Delete Sub-Collection Only:

const axios = require('axios');

// Use sub_collection_id (child sub-collection ID)
const subCollectionId = 'vs_4f14ee1a-46c7-4b49-a683-6a44e18b4d28';

const response = await axios.delete(
    `https://filesearchrag.usinc.ai/v2/collections/${subCollectionId}`,
    {
        headers: { 'x-api-key': '' },
        params: { is_sub_collection: true }
    }
);

console.log('Deleted sub-collection:', response.data.sub_collection_id);

cURL

Delete Entire Collection (pass collection_id):

# collection_id = parent collection ID
curl -X DELETE "https://filesearchrag.usinc.ai/v2/collections/vs_9b1fd5b2186f45bc9a35eab321c8318f" \
  -H "x-api-key: "

Delete Sub-Collection Only (pass sub_collection_id):

# sub_collection_id = child sub-collection ID from sub_collections array
curl -X DELETE "https://filesearchrag.usinc.ai/v2/collections/vs_4f14ee1a-46c7-4b49-a683-6a44e18b4d28?is_sub_collection=true" \
  -H "x-api-key: "

Response Format

Delete Entire Collection (is_sub_collection=false)

{
    "status_code": 200,
    "status": "success",
    "api_version": "v2",
    "message": "Collection 'Q4 Financial Reports' and all sub-collections deleted successfully",
    "collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "collection_name": "Q4 Financial Reports",
    "deleted_at": 1707480000,
    "sub_collections_deleted": [
        "vs_a1b2c3d4e5f6g7h8i9j0",
        "vs_b2c3d4e5f6g7h8i9j0k1"
    ],
    "docs_deleted": 15,
    "summary": {
        "sub_collections_removed": 2,
        "total_docs_removed": 15,
        "processing_time_seconds": 1.25
    }
}

Delete Sub-Collection Only (is_sub_collection=true)

{
    "status_code": 200,
    "status": "success",
    "api_version": "v2",
    "message": "Sub-collection 'Upload 2026-02-09' deleted successfully",
    "sub_collection_id": "vs_a1b2c3d4e5f6g7h8i9j0",
    "sub_collection_name": "Upload 2026-02-09",
    "parent_collection_id": "vs_9b1fd5b2186f45bc9a35eab321c8318f",
    "deleted_at": 1707480000,
    "qdrant_deleted": true,
    "docs_deleted": 5,
    "parent_updated": true,
    "summary": {
        "processing_time_seconds": 0.85
    }
}

Response Fields

Full Collection Delete Response

FieldTypeDescription
collection_idstringDeleted collection ID
collection_namestringDeleted collection name
deleted_atintegerUnix timestamp of deletion
sub_collections_deletedarrayList of deleted sub-collection IDs
docs_deletedintegerTotal documents removed
summary.sub_collections_removedintegerCount of sub-collections removed
summary.total_docs_removedintegerTotal documents removed
summary.processing_time_secondsfloatProcessing time

Sub-Collection Delete Response

FieldTypeDescription
sub_collection_idstringDeleted sub-collection ID
sub_collection_namestringDeleted sub-collection name
parent_collection_idstringParent collection ID
deleted_atintegerUnix timestamp of deletion
qdrant_deletedbooleanWhether Qdrant vectors were deleted
docs_deletedintegerDocuments removed
parent_updatedbooleanWhether parent collection was updated
summary.processing_time_secondsfloatProcessing time

Error Handling

Error Response Format

{
    "error": {
        "message": "Collection 'vs_xyz' not found",
        "type": "not_found",
        "code": "collection_not_found",
        "status_code": 404,
        "param": "col_id"
    }
}

Common Error Codes

Error CodeHTTP StatusDescription
collection_not_found404Collection or sub-collection not found
forbidden403Collection belongs to another user
internal_error500Server-side processing error

FileSearchRAG API • Version 2.0 Base URL: https://filesearchrag.usinc.ai