Knowledge Base API
Add documents, text content, and files to your AI's knowledge base. Content is automatically indexed and used by the Agent Chat API to provide accurate, grounded responses.
How It Works
Your Content → Embeddings → Vector Store → Chat Request → AI Uses Context
- Upload documents or text content via this API
- Content is automatically chunked and embedded
- When users ask questions via
/agent/chat, relevant content is retrieved - The AI uses this context to provide accurate answers
Note: You don't need to call any search API manually—the Agent Chat endpoint automatically retrieves relevant knowledge base content.
POST /api/sdk/knowledge/documents
Add a text document to the knowledge base.
Request Body
{
title: string; // Document title (required)
content: string; // Full text content (required)
contentType?: string; // Type identifier (default: 'document')
metadata?: Record<string, any>; // Custom metadata
tags?: string[]; // Tags for organization
}
Example
curl -X POST https://app.fig1.ai/api/sdk/knowledge/documents \
-H "Content-Type: application/json" \
-H "X-Fig1-API-Key: fig1_sdk_abc123" \
-d '{
"title": "Return Policy",
"content": "Our return policy allows customers to return items within 30 days of purchase. Items must be unused and in original packaging. Refunds are processed within 5-7 business days...",
"contentType": "policy",
"tags": ["returns", "customer-service"]
}'
Response
{
"success": true,
"data": {
"id": "doc_abc123",
"title": "Return Policy",
"content": "Our return policy allows...",
"contentType": "policy",
"metadata": {},
"tags": ["returns", "customer-service"],
"createdAt": "2024-01-15T10:00:00Z",
"updatedAt": "2024-01-15T10:00:00Z"
}
}
GET /api/sdk/knowledge/documents
List all documents in the knowledge base.
Query Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| limit | number | Max items (default: 20, max: 100) |
| offset | number | Pagination offset |
| contentType | string | Filter by content type |
| tag | string | Filter by tag |
curl -X GET "https://app.fig1.ai/api/sdk/knowledge/documents?contentType=policy&limit=10" \
-H "X-Fig1-API-Key: fig1_sdk_abc123"
Response
{
"success": true,
"data": {
"documents": [
{
"id": "doc_abc123",
"title": "Return Policy",
"content": "Our return policy allows...",
"contentType": "policy",
"tags": ["returns"],
"createdAt": "2024-01-15T10:00:00Z"
}
],
"total": 15,
"limit": 10,
"offset": 0,
"hasMore": true
}
}
GET /api/sdk/knowledge/documents/:id
Get a specific document.
curl -X GET "https://app.fig1.ai/api/sdk/knowledge/documents/doc_abc123" \
-H "X-Fig1-API-Key: fig1_sdk_abc123"
PUT /api/sdk/knowledge/documents/:id
Update a document. The document is re-indexed automatically.
curl -X PUT "https://app.fig1.ai/api/sdk/knowledge/documents/doc_abc123" \
-H "Content-Type: application/json" \
-H "X-Fig1-API-Key: fig1_sdk_abc123" \
-d '{
"content": "Updated return policy...",
"tags": ["returns", "customer-service", "policy-v2"]
}'
DELETE /api/sdk/knowledge/documents/:id
Remove a document from the knowledge base.
curl -X DELETE "https://app.fig1.ai/api/sdk/knowledge/documents/doc_abc123" \
-H "X-Fig1-API-Key: fig1_sdk_abc123"
File Processing
For PDF, Word, and other file uploads, use the file processing endpoint.
POST /api/sdk/knowledge/process
Upload and process a file. Supports PDF, DOCX, TXT, and Markdown files.
# First upload the file using the Assets API
curl -X POST https://app.fig1.ai/api/sdk/assets/upload \
-H "X-Fig1-API-Key: fig1_sdk_abc123" \
-F "file=@product-manual.pdf"
# Returns: { "success": true, "data": { "key": "uploads/abc123.pdf", "url": "..." } }
# Then process it into the knowledge base
curl -X POST https://app.fig1.ai/api/sdk/knowledge/process \
-H "Content-Type: application/json" \
-H "X-Fig1-API-Key: fig1_sdk_abc123" \
-d '{
"fileKey": "uploads/abc123.pdf",
"fileName": "product-manual.pdf",
"contentType": "manual",
"metadata": {
"product": "Widget Pro",
"version": "2.0"
}
}'
Response
{
"success": true,
"data": {
"jobId": "job_xyz789",
"status": "processing",
"fileName": "product-manual.pdf"
}
}
GET /api/sdk/knowledge/process/:jobId
Check processing status.
curl -X GET "https://app.fig1.ai/api/sdk/knowledge/process/job_xyz789" \
-H "X-Fig1-API-Key: fig1_sdk_abc123"
{
"success": true,
"data": {
"jobId": "job_xyz789",
"status": "completed",
"fileName": "product-manual.pdf",
"chunks": 45,
"documentId": "doc_def456"
}
}
Processing Status
| Status | Description |
|--------|-------------|
| queued | Waiting to be processed |
| processing | Extracting text and creating embeddings |
| completed | Successfully indexed |
| failed | Processing failed (check error field) |
Supported File Types
| Extension | Type | Notes |
|-----------|------|-------|
| .pdf | PDF | Text extraction + OCR for scanned pages |
| .docx | Word | Full text extraction |
| .doc | Word (legacy) | Basic support |
| .txt | Plain text | Direct indexing |
| .md | Markdown | Headers become section markers |
| .html | HTML | Tags stripped, text extracted |
Bulk Import
For large knowledge bases, you can batch upload documents:
const documents = [
{ title: "FAQ: Shipping", content: "..." },
{ title: "FAQ: Returns", content: "..." },
{ title: "FAQ: Payments", content: "..." }
];
for (const doc of documents) {
await fetch('https://app.fig1.ai/api/sdk/knowledge/documents', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Fig1-API-Key': 'fig1_sdk_abc123'
},
body: JSON.stringify({
...doc,
contentType: 'faq'
})
});
}
Direct Search (Advanced)
The knowledge base is automatically searched when using /agent/chat. For custom search UIs or advanced use cases, you can also search directly:
curl -X POST https://app.fig1.ai/api/sdk/rag/search \
-H "Content-Type: application/json" \
-H "X-Fig1-API-Key: fig1_sdk_abc123" \
-d '{
"query": "What is the return policy?",
"searchType": "hybrid",
"maxResults": 5
}'
This returns matching content without AI processing—useful for building custom search interfaces or previewing what the AI will see.
Content from Custom Types
Content created via the Content API is automatically added to the knowledge base when aiIndexed is true (the default). You don't need to separately add it to the knowledge base.
Video Processing
Index videos for AI-powered search and Q&A. Videos are analyzed, transcribed, and chunked for semantic search with timestamp context.
POST /api/sdk/knowledge/video
Start video processing for AI indexing.
Request Body
{
videoUrl: string; // URL of the video to process (required)
videoId?: string; // Optional MediaFile ID to link
fileName?: string; // Original file name
duration?: number; // Video duration in seconds
analysisConfig?: {
segmentDuration?: number; // Chunk size in seconds (default: 60)
detectTechniques?: boolean; // Domain-specific detection (default: true)
extractAudio?: boolean; // Enable transcription (default: true)
digestionInstructions?: string; // Custom AI analysis context
};
}
Example
curl -X POST https://app.fig1.ai/api/sdk/knowledge/video \
-H "Content-Type: application/json" \
-H "X-Fig1-API-Key: fig1_sdk_abc123" \
-d '{
"videoUrl": "https://cdn.fig1.ai/videos/tutorial.mp4",
"fileName": "tutorial.mp4",
"duration": 3600,
"analysisConfig": {
"segmentDuration": 60,
"detectTechniques": true,
"extractAudio": true
}
}'
Response
{
"success": true,
"data": {
"jobId": "vjob_abc123",
"status": "queued",
"stage": "Queued",
"message": "Video processing started"
}
}
GET /api/sdk/knowledge/video
List video processing jobs.
Query Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| status | string | Filter by status: queued, uploading, processing, completed, failed |
| limit | number | Max results (default: 20) |
curl -X GET "https://app.fig1.ai/api/sdk/knowledge/video?status=processing" \
-H "X-Fig1-API-Key: fig1_sdk_abc123"
Response
{
"success": true,
"data": [
{
"jobId": "vjob_abc123",
"fileName": "tutorial.mp4",
"status": "processing",
"progress": 45,
"stage": "Analyzing segments",
"createdAt": "2024-01-15T10:00:00Z"
},
{
"jobId": "vjob_def456",
"fileName": "demo.mp4",
"status": "completed",
"progress": 100,
"stage": "Complete",
"result": {
"totalSegments": 12,
"techniques": ["introduction", "demonstration", "summary"]
},
"createdAt": "2024-01-14T09:00:00Z",
"completedAt": "2024-01-14T09:15:00Z"
}
]
}
GET /api/sdk/knowledge/video/:jobId
Get status of a specific video processing job.
curl -X GET "https://app.fig1.ai/api/sdk/knowledge/video/vjob_abc123" \
-H "X-Fig1-API-Key: fig1_sdk_abc123"
Video Processing Status
| Status | Description |
|--------|-------------|
| queued | Waiting to start |
| uploading | Sent to processor |
| processing | Analyzing video content |
| completed | Successfully indexed |
| failed | Processing failed (check error) |
How Video RAG Works
- Upload - Video is sent to the processing pipeline
- Segmentation - Video is split into time-based chunks
- Analysis - AI analyzes each segment for content and context
- Transcription - Audio is transcribed to text
- Embedding - Segments are embedded for semantic search
- Indexing - Content becomes searchable via Agent Chat
Querying Video Content
Once processed, video content is automatically included in knowledge base searches:
curl -X POST https://app.fig1.ai/api/sdk/agent/chat \
-H "Content-Type: application/json" \
-H "X-Fig1-API-Key: fig1_sdk_abc123" \
-d '{
"message": "What techniques are shown in the tutorial video?",
"context": {
"currentVideo": {
"videoId": "vid_abc123",
"currentTime": 330
}
}
}'
The AI will search video segments and can reference specific timestamps in responses.
Best Practices
- Chunk large documents - Break very long content into logical sections
- Use descriptive titles - Helps with search relevance
- Add metadata - Include relevant context (product, version, date)
- Tag consistently - Create a tag taxonomy for filtering
- Keep content updated - Re-index when source content changes
- Use content types - Organize by type (faq, policy, guide, etc.)
- Index videos strategically - Process videos that have valuable searchable content
- Use digestion instructions - Provide context for domain-specific video content