Search and RAG
Perform semantic search over indexed documents and prepare retrieval-augmented message arrays.
Two endpoints power retrieval in Mojar: a direct semantic search and a higher-level pipeline that assembles a ready-to-send message array with retrieved context injected.
GET /documents/search
Returns ranked chunks from an agent's knowledge base whose embeddings are within the similarity threshold of the query.
Authentication: Bearer API key required (see Authentication).
Request body
Although this is a GET request, the query parameters are sent in the request body as JSON.
Prop
Type
Example
curl -X GET https://api.mojar.ai/documents/search \
-H "Authorization: Bearer nest-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agentId": 42,
"query": "product pricing tiers",
"matchCount": 5,
"minSimilarity": 0.7
}'const response = await fetch("https://api.mojar.ai/documents/search", {
method: "GET",
headers: {
Authorization: "Bearer nest-YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
agentId: 42,
query: "product pricing tiers",
matchCount: 5,
minSimilarity: 0.7,
}),
});
const chunks = await response.json();Response — 200 OK
Returns an array of RawChunkSearchResult objects, ordered by descending similarity.
[
{
"document_id": 1001,
"source_text_id": null,
"document_title": "Q2 Product Roadmap",
"document_file_name": "roadmap-q2.pdf",
"document_total_chunks": 38,
"document_summary": "Outlines the planned features and pricing changes for Q2 2026.",
"document_metadata": {},
"chunk_id": 8821,
"chunk_sequence": 12,
"chunk_text": "The Starter tier is priced at $49/month...",
"similarity": 0.912,
"chunk_metadata": {
"token_count": 94,
"contains_paragraph_break": false,
"sentence_count": 3
}
}
]Prop
Type
POST /rag/prepare-messages
Runs the full RAG pipeline: retrieves relevant chunks for the conversation, optionally re-ranks them, optionally expands them with sibling chunks, and returns a new messages array with the retrieved context injected — ready to pass directly to an LLM.
Authentication: Bearer API key required.
Request headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer API key. |
dev-pipeline-options | No | JSON string to override pipeline flags (development use). See below. |
dev-pipeline-options header
Pass a JSON string to override pipeline defaults during development:
{ "useReranking": true, "useKnowledgeGraph": false }| Option | Type | Description |
|---|---|---|
useReranking | boolean | Enable or disable re-ranking of retrieved chunks. |
useKnowledgeGraph | boolean | Enable or disable knowledge graph augmentation. |
Request body
Prop
Type
Example
curl -X POST https://api.mojar.ai/rag/prepare-messages \
-H "Authorization: Bearer nest-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agentId": 42,
"messages": [
{ "role": "user", "content": "What are the pricing tiers?" }
]
}'const response = await fetch("https://api.mojar.ai/rag/prepare-messages", {
method: "POST",
headers: {
Authorization: "Bearer nest-YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
agentId: 42,
messages: [
{ role: "user", content: "What are the pricing tiers?" },
],
}),
});
const { messages, metadata } = await response.json();
// Pass `messages` directly to your LLM callResponse — 200 OK
{
"message": "Messages prepared successfully",
"messages": [
{
"role": "system",
"content": "Use the following context to answer the user's question:\n\n---\nThe Starter tier is priced at $49/month...\n---"
},
{
"role": "user",
"content": "What are the pricing tiers?"
}
],
"metadata": {
"knowledgeGraphUsed": false,
"rerankingUsed": true,
"retrievalMetrics": {
"retrievedK": 10,
"rerankedK": 5,
"siblingEnhancedK": 7,
"mergedK": 6,
"durationMs": 142,
"chunks": [
{
"chunkId": 8821,
"similarityScore": 0.912,
"searchType": "similarity"
}
]
}
}
}Prop
Type