Overview
The Prebuilt RAG API allows you to retrieve relevant document chunks from your ingested documents using semantic search. It returns the most relevant content for your query, making it ideal for building custom RAG (Retrieval-Augmented Generation) applications.Endpoint
Authentication
Include your API token in the Authorization header:Request
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer YOUR_API_TOKEN | Yes |
Content-Type | application/json | Yes |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | The search query to retrieve relevant chunks |
file_ids | string[] | No | Restrict retrieval to specific documents by file ID (preferred) |
file_names | string[] | No | Restrict retrieval to specific documents by file name (deprecated, use file_ids) |
Example Request
Example with Specific Documents (using file_ids)
Example with Specific Documents (using file_names - deprecated)
Response
Success Response (200 OK)
| Field | Type | Description |
|---|---|---|
query | string | The original search query |
chunks | array | List of retrieved document chunks |
total | integer | Total number of chunks retrieved |
Chunk Object
Each chunk in thechunks array contains:
| Field | Type | Description |
|---|---|---|
text | string | The text content of the chunk |
file_id | string | The unique identifier of the source file |
file_name | string | The source file name |
page_number | integer | The page number where the chunk was found |
score | float | The relevance score of the chunk (higher is more relevant) |
metadata | object | Additional metadata for the chunk |
Example Response
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid or missing API token |
| 404 | Not Found - Specified file not found |
| 500 | Internal Server Error |
Usage Examples
Python
Python with Custom LLM Integration
JavaScript
JavaScript with Custom LLM Integration
Use Cases
Custom RAG Applications
Use this API to build custom RAG pipelines with your preferred LLM:- Retrieve relevant chunks using semantic search
- Build context from the retrieved chunks
- Generate answers using any LLM (OpenAI, Anthropic, Google, etc.)
Document Search
Build document search interfaces that show relevant excerpts:- Query for relevant content
- Display chunks with file names and page numbers
- Allow users to navigate to source documents
Knowledge Base Q&A
Create custom Q&A systems with full control over:- Prompt engineering
- Response formatting
- Source citations
- Multi-step reasoning
Best Practices
- Be specific in queries — Clear, specific queries return more relevant chunks
- Use file_names for focused search — Restrict to specific documents when you know the source
- Check relevance scores — Higher scores indicate better matches; consider filtering low-score chunks
- Include source citations — Use file_name and page_number to cite sources in your responses
- Combine with LLM — Use retrieved chunks as context for LLM-generated answers
Comparison with Chat API
| Feature | Prebuilt RAG API | Chat API |
|---|---|---|
| Returns | Raw document chunks | Generated answer |
| LLM Integration | Bring your own | Built-in |
| Conversation Memory | No | Yes |
| Customization | Full control | Limited |
| Use Case | Custom RAG pipelines | Quick Q&A |
Related
Chat API
Get AI-generated answers with built-in LLM
Data Ingestion
Improve parsing quality for better retrieval results
Extraction API
Extract structured data from documents
RAG Quickstart
Build your first RAG pipeline with Graphor

