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
| Method | URL |
|---|---|
| POST | https://filesearchrag.usinc.ai/v2/collections |
Authentication
All API requests require authentication using an API key passed in the request header.
| Header | Type | Required | Description |
|---|---|---|---|
x-api-key | string | Yes | Your 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | - | Display name for the collection |
files | file[] | Yes | - | One or more files to upload (max 10 files, 100 MB each) |
collection_id | string | No | Auto-generated | Existing collection ID to append files to (creates new if omitted) |
summarize | boolean | No | false | Generate summaries for each file |
preview | integer | No | 0 | Enable S3 file preview (0=disabled, 1=enabled) |
stream | boolean | No | false | Enable SSE streaming for real-time progress |
Request Behavior
- New Collection: Omit
collection_idto create a brand new collection - Append to Existing: Provide
collection_idto 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
| Status | Meaning |
|---|---|
| 200 | Complete success - all files processed |
| 207 | Partial success - some files failed |
| 400 | Validation error - invalid request |
| 403 | Forbidden - collection belongs to another user |
| 500 | Server 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
| Field | Type | Description |
|---|---|---|
status_code | integer | HTTP status code: 200 (success), 207 (partial), 500 (error) |
status | string | Overall status: "success", "partial", or "error" |
api_version | string | API version identifier ("v2") |
collection | object | Collection metadata object |
sub_collections | array | List of all sub-collection IDs (format: vs_*) |
latest_sub_collection_id | string | Most recently created sub-collection ID |
choices | array | Detailed information for each uploaded file |
processed_files | array | List of successfully processed files |
unprocessed_files | array | null | List of failed files, null if all succeeded |
summary | object | Processing statistics |
Collection Object
| Field | Type | Description |
|---|---|---|
id | string | Collection ID (format: vs_*) |
name | string | Display name of the collection |
created_at | string | ISO 8601 timestamp |
sub_collections_count | integer | Number of sub-collections |
Choice Object (File Details)
| Field | Type | Description |
|---|---|---|
id | string | null | Unique file identifier (format: file-{document_id}), null if failed |
bytes | integer | File size in bytes |
size | string | Human-readable file size (e.g., "1.5 MB") |
created_at | integer | Unix timestamp when file was processed |
filename | string | Original filename |
status | string | "processed" or "error" |
status_details | string | Detailed status message |
sub_collection_id | string | null | Sub-collection ID where file is stored (null if failed) |
metadata_document_id | string | Internal document reference ID |
mongo_id | string | MongoDB document ID |
chunks_count | integer | Number of text chunks created |
total_tokens | integer | Total token count across all chunks |
parser_used | string | Parser type ("vision_ocr", "text_parser", etc.) |
chunking_mode | string | Chunking strategy used ("parent_child") |
parent_child_stats | object | Statistics about parent/child chunks |
performance | object | Detailed timing breakdown |
preview_enabled | boolean | Whether S3 preview is available |
s3_key | string | S3 object key (when preview enabled) |
s3_url | string | S3 URL for file preview (when preview enabled) |
content_type | string | MIME type of the file |
Summary Object
| Field | Type | Description |
|---|---|---|
total_files | integer | Total number of files in request |
successful | integer | Number of successfully processed files |
failed | integer | Number of files that failed |
total_chunks | integer | Total chunks created across all files |
total_size | string | Human-readable total size |
total_size_bytes | integer | Total size in bytes |
summarization_enabled | boolean | Whether summarization was enabled |
chunking_mode | string | Chunking strategy ("parent_child") |
processing_time_seconds | float | Total processing time |
avg_time_per_file | float | Average time per file |
chunks_per_second | float | Processing throughput metric |
SSE Streaming Mode
When stream=true, the API returns Server-Sent Events for real-time progress updates.
SSE Stages
| Stage | Description |
|---|---|
starting | Processing initiated |
extraction | Text extraction progress (0-100%) |
chunking | Document chunking progress (0-100%) |
embedding | Vector embedding progress (0-100%) |
storing | Database storage progress (0-100%) |
complete | Processing finished successfully |
error | Processing 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
| Format | Extension | MIME Type |
|---|---|---|
.pdf | application/pdf | |
| PNG Image | .png | image/png |
| JPEG Image | .jpg, .jpeg | image/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 Code | HTTP Status | Description |
|---|---|---|
no_files_provided | 400 | No files were provided in the request |
too_many_files | 400 | More than 10 files in a single request |
invalid_file_extension | 400 | File type not in supported formats list |
file_too_large | 400 | Individual file exceeds 100 MB limit |
batch_too_large | 400 | Total upload size exceeds 100 MB limit |
collection_not_found | 404 | Specified collection_id does not exist |
forbidden | 403 | Collection belongs to another user |
internal_error | 500 | Server-side processing error |
Best Practices
- Validate Files Before Upload: Check file size (up to 100 MB OR up to 5,000 pages) and extension before sending requests
- Handle Partial Success: When
status_codeis 207, check bothprocessed_filesandunprocessed_files - Store Sub-Collection IDs: Save the returned
latest_sub_collection_idfor use in/v2/filesearch - Use Meaningful Names: Set descriptive
namevalues for easy identification - Batch Related Documents: Upload related files together for logical groupings
- Implement Retry Logic: For 5xx errors, use exponential backoff with max 3 attempts
- Monitor Performance: Check
summary.processing_time_secondsfor throughput optimization - Use Append for Updates: Use
collection_idparameter to add files to existing collections
Using Sub-Collection IDs for Search
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
| Feature | Description |
|---|---|
| Hybrid Search | BM25 keyword + semantic vector search with RRF fusion |
| Parent-Child Context | Child chunks for precise matching, parent chunks for full LLM context |
| Inline Citations | Automatic [[N]] citation generation with source mapping |
| Conversation History | Multi-turn conversations via messages array or conversation_id |
| SSE Streaming | Real-time response streaming with progress events |
| Web Search Augmentation | Optional web search to supplement document context |
| File Filtering | Search within specific files or collections |
| Pagination Support | Limit/offset pagination with retrieval token caching |
| Search Modes | Hybrid, semantic-only, or keyword-only search |
| Redis Caching | Instant responses for repeat queries (1-hour TTL) |
| User Isolation | Strict access control - users only see their own collections |
API Endpoint
| Method | URL |
|---|---|
| POST | https://filesearchrag.usinc.ai/v2/filesearch |
Authentication
All API requests require authentication using an API key passed in the request header.
| Header | Type | Required | Description |
|---|---|---|---|
x-api-key | string | Yes | Your 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | No | "usf1-mini" | LLM model to use for response generation |
messages | array | Yes | - | Conversation messages (min 1, max 100). Must contain at least one user message |
temperature | float | No | 0.7 | Response creativity (0.0-2.0). Lower = more focused, higher = more creative |
max_tokens | integer | No | 4000 | Maximum response tokens (1-16000) |
stream | boolean | No | false | Enable SSE streaming for real-time responses |
Collection & File Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
collection_id | string | No | null | Collection ID to search (format: vs_*). Supports comma-separated IDs for multi-collection search |
file_id | string | No | null | Filter search to specific file (format: file-{uuid} or {uuid}) |
conversation_id | string | No | auto-generated | ID for maintaining conversation history across requests |
Search Parameters
| Parameter | Type | Required | Default | Range | Description |
|---|---|---|---|---|---|
search_type | string | No | "hybrid" | hybrid/semantic/keyword | Search mode for document retrieval |
top_k | integer | No | 20 | 5-100 | Number of documents to retrieve from initial search |
web_search | boolean | No | false | - | Enable web search augmentation for additional context |
Pagination Parameters
| Parameter | Type | Required | Default | Range | Description |
|---|---|---|---|---|---|
limit | integer | No | 10 | 1-50 | Number of documents for LLM context per page |
offset | integer | No | 0 | ≥0 | Starting position in results for pagination |
retrieval_token | string | No | null | max 50 chars | Token from previous response to reuse cached search results (skips re-search) |
Message Object
| Field | Type | Required | Description |
|---|---|---|---|
role | string | Yes | Message role: "system", "user", or "assistant" |
content | string | Yes | Message 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
| Behavior | Description |
|---|---|
| Collection Resolution | Parent collection IDs are automatically expanded to search all sub-collections |
| Multi-Collection Search | Pass comma-separated IDs to search multiple collections: "vs_abc123,vs_def456" |
| File Filtering | When file_id is provided, search is restricted to that specific file |
| Conversation History | Provide previous messages in the messages array OR use conversation_id to retrieve from database |
| Context Overflow | If retrieved context exceeds 15,000 tokens, returns suggested questions instead of direct answer |
| Pagination Caching | When retrieval_token is provided, cached search results are used (no re-search) |
| Search Modes | hybrid (default) combines BM25+semantic; semantic uses vector search only; keyword uses BM25 only |
Search Modes
| Mode | Description | Use Case |
|---|---|---|
hybrid | BM25 + Semantic with RRF fusion | Best accuracy (default) |
semantic | Vector search only | Meaning-based queries, synonyms |
keyword | BM25 search only | Exact term matching, technical terms |
Pagination System
How Pagination Works
- First Request: Fresh search runs, results cached with
retrieval_token - Subsequent Requests: Pass
retrieval_token+ differentoffsetto paginate - 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
| Field | Type | Description |
|---|---|---|
id | string | Unique completion ID (format: chatcmpl-{conversation_id}) |
object | string | Response type: "filesearch.completion" |
created | integer | Unix timestamp of response creation |
model | string | LLM model used for generation |
api_version | string | API version ("v2") |
choices | array | Array containing the response message |
usage | object | Token usage statistics |
conversation_id | string | ID for conversation continuity |
history_source | string | Source of conversation history: "none", "messages", or "database" |
citations | array | Inline citation references with source details |
sources | array | Source documents used for context |
search_summary | object | Detailed search metadata and statistics |
pagination | object | Pagination metadata for limit/offset support |
collection_id | string | Collection ID(s) that were searched |
context_overflow | boolean | Whether context exceeded 15K token threshold |
search_notice | string | null | Notice about pagination (when has_more is true) |
suggested_questions | array | null | Suggested follow-up questions (context overflow only) |
history | array | Previous conversation messages |
file_filter | object | null | File filter info when file_id is used |
Choice Object
| Field | Type | Description |
|---|---|---|
index | integer | Choice index (always 0) |
message | object | Assistant's response message |
finish_reason | string | "stop" for normal completion, "context_overflow" for overflow |
Message Object
| Field | Type | Description |
|---|---|---|
role | string | Always "assistant" |
content | string | Generated answer with [[N]] inline citations |
reasoning | string | (Optional) Chain-of-thought reasoning when web_search enabled |
Citation Object
| Field | Type | Description |
|---|---|---|
index | integer | Citation number matching [[N]] in response |
filename | string | Source document filename |
page | integer | null | Page number in source document |
snippet | string | Text excerpt from source (child chunk) |
confidence | float | Relevance confidence score (0.0-1.0) |
Source Object
| Field | Type | Description |
|---|---|---|
document | string | Full parent chunk text (complete context) |
filename | string | Source document filename |
score | float | Relevance score (rounded to 2 decimals) |
chunk_type | string | "parent" or "child" |
page | integer | Page number |
collection_name | string | Collection ID containing this document |
Search Summary Object
| Field | Type | Description |
|---|---|---|
search_type | string | Search mode used: "hybrid", "semantic", or "keyword" |
context_tokens | integer | Total tokens in retrieved context |
response_path | string | "direct" or "suggested_questions" |
docs_used | integer | Documents in current page (after limit/offset) |
docs_found | integer | Total documents found (before pagination) |
bm25_count | integer | Documents matched by BM25 keyword search |
bm25_matches | array | Top BM25 matches with rank, score, snippet |
semantic_count | integer | Documents matched by semantic search |
semantic_matches | array | Top semantic matches with rank, score, snippet |
merged_results | integer | Total unique documents after RRF fusion |
rrf_k | integer | RRF constant used (default: 60) |
top_sources | array | Detailed info about top matched documents |
all_retrieved_files | array | All unique filenames retrieved (before truncation) |
all_retrieved_count | integer | Count of all unique files retrieved |
BM25/Semantic Match Object
| Field | Type | Description |
|---|---|---|
rank | integer | Position in search results |
score | float | Search score (rounded to 2 decimals) |
page | integer | Page number |
filename | string | Source document filename |
snippet | string | Text excerpt (truncated to 200 chars) |
Top Source Object
| Field | Type | Description |
|---|---|---|
document_id | string | Unique document/file ID |
filename | string | Source document filename |
page | integer | Page number |
relevance_score | float | Relevance score (rounded to 2 decimals) |
match_type | string | "both", "keyword", or "semantic" |
bm25_rank | integer | null | Rank in BM25 results (null if not matched) |
semantic_rank | integer | null | Rank in semantic results (null if not matched) |
collection_name | string | Collection ID |
Pagination Object
| Field | Type | Description |
|---|---|---|
offset | integer | Current offset position |
limit | integer | Current page size |
total | integer | Total documents found by search |
has_more | boolean | Whether more results exist beyond current page |
retrieval_token | string | Token to use for subsequent pagination requests |
retrieval_token_expires_in | integer | Seconds until token expires (300) |
Usage Object
| Field | Type | Description |
|---|---|---|
prompt_tokens | integer | Tokens in the prompt (context + messages) |
completion_tokens | integer | Tokens in the generated response |
total_tokens | integer | Total tokens used |
File Filter Object
| Field | Type | Description |
|---|---|---|
file_id | string | The file ID that was used to filter |
filename | string | Resolved filename for the file |
collection_id | string | Collection 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
| Status | Description |
|---|---|
searching | Running hybrid search (BM25 + semantic) |
cached | Using cached retrieval results |
reranked | Documents reranked by relevance |
generating | LLM response generation started |
complete | Response 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 Code | HTTP Status | Description |
|---|---|---|
missing_user_message | 400 | No user message found in messages array |
too_many_messages | 400 | More than 100 messages in request |
context_length_exceeded | 400 | Prompt exceeds 100,000 token limit |
collection_not_found | 404 | Specified collection_id does not exist |
file_not_found | 404 | Specified file_id does not exist |
forbidden | 403 | Collection or file belongs to another user |
llm_service_error | 502 | LLM API returned an error |
service_unavailable | 503 | LLM service not configured or unavailable |
service_timeout | 504 | LLM service timed out after retries |
parse_error | 500 | Failed to parse LLM response |
internal_error | 500 | Server-side processing error |
Retry Logic
The API implements automatic retry for transient failures:
| Attempt | Delay | Total Wait |
|---|---|---|
| 1 | 0s | 0s |
| 2 | 1s | 1s |
| 3 | 2s | 3s |
Retryable Status Codes: 502, 503, 504, Timeout
Best Practices
| Practice | Description |
|---|---|
| Use Specific Queries | More specific questions yield better citations and focused answers |
| Filter by Collection/File | Use collection_id or file_id to narrow search scope for faster, more relevant results |
| Choose Search Mode | Use hybrid (default) for best accuracy; keyword for exact terms; semantic for meaning-based |
| Use Pagination | Set appropriate limit and use retrieval_token for paginating through large result sets |
| Handle Context Overflow | When receiving context_overflow: true, use the suggested_questions to refine your query |
| Use Streaming for UX | Enable stream: true for better user experience with real-time response display |
| Maintain Conversation | Use conversation_id or pass previous messages for multi-turn conversations |
| Check Citations | Verify important claims using the citations array with page numbers and snippets |
| Monitor Usage | Track usage.total_tokens for cost estimation and optimization |
| Handle Retries | Implement retry logic for 5xx errors with exponential backoff |
| Leverage Caching | The API caches repeat queries for 1 hour; retrieval tokens cache for 5 minutes |
Technical Configuration
Configuration Constants
| Constant | Value | Description |
|---|---|---|
CONTEXT_THRESHOLD_DIRECT | 15,000 | Token threshold for direct vs overflow path |
LLM_FINAL_TIMEOUT | 45.0s | Timeout for LLM calls |
LLM_STREAM_TIMEOUT | 60.0s | Timeout for streaming LLM calls |
LLM_MAX_RETRIES | 2 | Max retry attempts for LLM calls |
RERANK_TIMEOUT | 15.0s | Timeout for reranker API |
RETRIEVAL_CACHE_TTL | 300s | Retrieval token cache expiry |
DEFAULT_CACHE_TTL | 3600s | Response cache expiry |
DEFAULT_RRF_K | 60 | RRF fusion constant |
ENTITY_MATCH_BOOST | 1.5x | BM25 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
| Method | URL |
|---|---|
| GET | https://filesearchrag.usinc.ai/v2/collections |
Authentication
| Header | Type | Required | Description |
|---|---|---|---|
x-api-key | string | Yes | Your 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
| Field | Type | Description |
|---|---|---|
data | array | Array of collection objects |
total | integer | Total number of collections |
data[].collection.id | string | Collection ID (format: vs_*) |
data[].collection.name | string | Collection display name |
data[].collection.processing_status | object | Current processing status |
data[].sub_collections | array | List of sub-collection IDs |
data[].latest_sub_collection_id | string | Most recent sub-collection ID |
data[].choices | array | File details array |
data[].summary | object | Aggregated 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:
- Find collection/sub-collection in MongoDB
- Delete vectors from Qdrant
- Delete file metadata from MongoDB DocData
- Delete/update collection record
API Endpoint
| Method | URL |
|---|---|
| DELETE | https://filesearchrag.usinc.ai/v2/collections/{col_id} |
Authentication
| Header | Type | Required | Description |
|---|---|---|---|
x-api-key | string | Yes | Your API authentication key |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
col_id | string | Yes | Collection ID or Sub-Collection ID to delete (format: vs_*) |
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
is_sub_collection | boolean | No | false | Deletion 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
| Field | Type | Description |
|---|---|---|
collection_id | string | Deleted collection ID |
collection_name | string | Deleted collection name |
deleted_at | integer | Unix timestamp of deletion |
sub_collections_deleted | array | List of deleted sub-collection IDs |
docs_deleted | integer | Total documents removed |
summary.sub_collections_removed | integer | Count of sub-collections removed |
summary.total_docs_removed | integer | Total documents removed |
summary.processing_time_seconds | float | Processing time |
Sub-Collection Delete Response
| Field | Type | Description |
|---|---|---|
sub_collection_id | string | Deleted sub-collection ID |
sub_collection_name | string | Deleted sub-collection name |
parent_collection_id | string | Parent collection ID |
deleted_at | integer | Unix timestamp of deletion |
qdrant_deleted | boolean | Whether Qdrant vectors were deleted |
docs_deleted | integer | Documents removed |
parent_updated | boolean | Whether parent collection was updated |
summary.processing_time_seconds | float | Processing 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 Code | HTTP Status | Description |
|---|---|---|
collection_not_found | 404 | Collection or sub-collection not found |
forbidden | 403 | Collection belongs to another user |
internal_error | 500 | Server-side processing error |
FileSearchRAG API • Version 2.0
Base URL: https://filesearchrag.usinc.ai
