RAG Search API
Search your knowledge base using semantic similarity. The RAG (Retrieval Augmented Generation) API finds relevant content that can be used to ground AI responses.
POST /api/sdk/rag/search
Search for relevant content using natural language queries.
Request Body
{
query: string; // Search query
// Optional
searchType?: 'hybrid' | 'standard' | 'expanded';
maxResults?: number; // Default: 10, max: 50
threshold?: number; // Minimum relevance score (0-1)
useReranking?: boolean; // Re-rank results for relevance
contentTypes?: string[]; // Filter by content type
context?: Record<string, any>; // Additional context for search
}
Search Types
| Type | Description | Best For |
|------|-------------|----------|
| standard | Basic semantic search | Simple queries |
| hybrid | Combines semantic + keyword | Most use cases |
| expanded | Query expansion + hybrid | Complex queries |
Example Request
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": "How do I reset my password?",
"searchType": "hybrid",
"maxResults": 5,
"contentTypes": ["faq", "article"]
}'
Response
{
"success": true,
"data": {
"results": [
{
"id": "chunk_abc123",
"content": "To reset your password, go to the login page and click 'Forgot Password'. Enter your email address and we'll send you a reset link...",
"score": 0.92,
"rank": 1,
"source": "faq",
"metadata": {
"fileName": "password-reset.md",
"contentType": "faq",
"title": "Password Reset Guide"
}
},
{
"id": "chunk_def456",
"content": "If you're having trouble with your account credentials, our password reset feature can help...",
"score": 0.85,
"rank": 2,
"source": "article",
"metadata": {
"fileName": "account-troubleshooting.md",
"contentType": "article",
"title": "Account Troubleshooting"
}
}
],
"totalResults": 2,
"query": "How do I reset my password?",
"searchType": "hybrid",
"latencyMs": 145
}
}
Using RAG with Chat
The agent automatically uses RAG when configured. You can also provide search results as context:
// 1. Search for relevant content
const searchResponse = await fetch('https://app.fig1.ai/api/sdk/rag/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Fig1-API-Key': 'fig1_sdk_abc123'
},
body: JSON.stringify({
query: 'password reset',
maxResults: 3
})
});
const { data: searchData } = await searchResponse.json();
// 2. Use results as context in chat
const chatResponse = await fetch('https://app.fig1.ai/api/sdk/agent/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Fig1-API-Key': 'fig1_sdk_abc123'
},
body: JSON.stringify({
message: 'How do I reset my password?',
context: {
relevantContent: searchData.results.map(r => r.content)
}
})
});
Knowledge Base Management
GET /api/sdk/rag/documents
List documents in your knowledge base.
curl -X GET "https://app.fig1.ai/api/sdk/rag/documents" \
-H "X-Fig1-API-Key: fig1_sdk_abc123"
Response:
{
"success": true,
"data": [
{
"_id": "doc_abc123",
"fileName": "product-guide.pdf",
"fileType": "pdf",
"status": "completed",
"chunks": 45,
"createdAt": "2024-01-15T10:00:00Z",
"processedAt": "2024-01-15T10:02:30Z"
}
]
}
Document Status
| Status | Description |
|--------|-------------|
| queued | Waiting to be processed |
| processing | Currently being analyzed and indexed |
| completed | Successfully indexed and searchable |
| failed | Processing failed (check error message) |
Indexing Content
Documents are automatically chunked and indexed when uploaded. The system:
- Extracts text from documents (PDF, DOCX, etc.)
- Splits content into semantic chunks
- Generates embeddings using Voyage AI
- Stores in vector database for fast retrieval
Supported File Types
| Type | Extensions | Notes |
|------|------------|-------|
| PDF | .pdf | Text extraction + OCR |
| Word | .docx, .doc | Full formatting preserved |
| Markdown | .md | Headers become sections |
| Text | .txt | Plain text |
| HTML | .html | Tags stripped |
Best Practices
- Use hybrid search - Best balance of semantic and keyword matching
- Set appropriate thresholds - Filter out low-relevance results
- Enable re-ranking - Improves result quality for important queries
- Structure your content - Clear headings and sections improve chunking
- Keep content updated - Re-index when source content changes