RAG & Document Retrieval
Enable your assistants to search and reference uploaded documents.
RAG & Document Retrieval
Retrieval Augmented Generation (RAG) allows your assistants to search through uploaded documents and include relevant context in their responses.
RAG requires the Pro tier or higher. File search is not available on the Hobby tier.
How It Works
- Upload - You upload documents (PDFs, Word docs, etc.) in the dashboard
- Process - Documents are automatically chunked and embedded
- Retrieve - When users ask questions, relevant chunks are retrieved
- Generate - The assistant uses the context to generate accurate responses
Setting Up RAG
Upload Documents
Upload your knowledge base documents via the dashboard.
- Go to Documents in the sidebar
- Click Upload Document
- Select your file (PDF, DOCX, TXT, or MD)
- Add an optional description
- Wait for processing to complete
Documents are processed asynchronously. Large documents may take a few minutes to be ready for retrieval.
Create an Assistant with RAG
Enable file search when creating or editing an assistant.
- Go to Assistants in the sidebar
- Click New Assistant or edit an existing one
- In the Tools section, enable File Search (RAG)
- Select which documents to include:
- All documents in workspace
- Specific documents only
- Save the assistant
Use the Assistant
The assistant will automatically search documents when relevant.
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.assistantrouter.com/v1',
apiKey: process.env.ASSISTANTROUTER_API_KEY,
});
const response = await client.chat.completions.create({
// @ts-ignore
assistant_id: 'your-assistant-uuid',
messages: [
{ role: 'user', content: 'How do I reset my password?' }
],
});
console.log(response.choices[0].message.content);The response will include information from your uploaded documents.
Managing Documents
Supported File Types
| Type | Extensions | Max Size |
|---|---|---|
.pdf | 50 MB | |
| Word | .docx | 50 MB |
| Text | .txt, .md | 50 MB |
| CSV | .csv | 50 MB |
| Excel | .xlsx | 50 MB |
Note: Only .docx format is supported for Word documents. Legacy .doc files must be converted first.
Document Status
| Status | Description |
|---|---|
uploading | File is being uploaded |
processing | Document is being chunked and embedded |
ready | Document is ready for retrieval |
failed | Processing failed (check error message) |
Organizing Documents
Documents can be associated with specific assistants:
- Go to the assistant's Settings
- Under File Search, select which documents to include
- You can add all workspace documents or select specific ones
Best Practices
- Chunk wisely - Keep related content together in documents
- Use descriptive names - Helps identify documents in the dashboard
- Update regularly - Keep your knowledge base current
- Test retrieval - Verify the right content is being found
- Split large documents - Better retrieval with smaller, focused documents
Tip: Smaller, focused documents work better than large monolithic files. Consider splitting a 100-page manual into separate documents by chapter or topic.
Understanding Retrieval
When you send a message to an assistant with RAG enabled:
- Your query is converted to an embedding
- Similar document chunks are retrieved (typically top 5-10)
- Retrieved context is injected into the prompt
- The model generates a response using the context
Response Metadata
The API response includes information about tools used:
{
"choices": [...],
"x_assistantrouter": {
"cost_cents": 0.15,
"tools_used": ["file_search"],
"was_fallback": false
}
}Troubleshooting
Documents Not Being Retrieved
- Ensure the document status is
readyin the dashboard - Check that file search is enabled on the assistant
- Verify the query is relevant to the document content
- Try rephrasing the question
Poor Quality Responses
- Improve document formatting (clear headings, sections)
- Add metadata/descriptions when uploading
- Consider splitting large documents into smaller pieces
- Ensure documents contain the relevant information
Processing Failures
- Check file size is within limits
- Verify file is not corrupted
- Try re-uploading the document
- Check for unsupported file formats