Skip to main content

RAG QA

Perform retrieval-augmented generation QA based on uploaded knowledge base documents. The endpoint retrieves relevant document chunks, constructs context, and then calls the specified large language model to generate answers.

Try It

POST/search/chat_messagehttps://api-platform.ope.ai

Authentication

Uses Bearer Token authentication.

  • Header: Authorization: Bearer <token>
  • Example: Authorization: Bearer sk-xxxxxx

Request Body (application/json)

FieldTypeRequiredDescriptionDefault / Range
questionstringYesUser question, used for document retrieval and answer generation-
llm_model_namestringYesLarge language model name used to generate answers-
embedding_model_namestringYesEmbedding model name used for text vectorization and retrieval-
session_idstringYesSession ID, used to associate conversation history-
top_kintegerNoNumber of similar documents returned by retrievalDefault 5
streambooleanNoWhether to use SSE streaming responseDefault true
return_sourcesbooleanNoWhether to return relevant source documentsDefault true
return_historybooleanNoWhether to return conversation history recordsDefault false
extra_promptstringNoAdditional prompt to supplement answer constraintsDefault None
example_promptstringNoExample prompt to constrain response styleDefault example
fallback_contextstringNoBackup context when no relevant content is found in the knowledge baseDefault empty string
cosine_radiusnumberNoCosine similarity threshold radiusDefault 0.55

Request Examples

curl -X POST "https://api-platform.ope.ai/search/chat_message" \
-H "Authorization: Bearer $OPEAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"question": "What is RAG?",
"llm_model_name": "deepseek-v4-flash",
"embedding_model_name": "bge-m3",
"top_k": 5,
"session_id": "session_1",
"stream": false,
"return_sources": true
}'

Response Example

{
"message": "RAG is Retrieval-Augmented Generation, which retrieves relevant content from the knowledge base and generates answers combined with the model.",
"sources": [
{
"doc_id": "doc_1",
"chunk_id": "chunk_1",
"content": "RAG combines retrieval with generation."
}
],
"info": {
"top_k": 5
},
"history": []
}

Error Responses

Status CodeScenarioDescription
400Parameter validation errorMissing or incorrect format for required fields like question, model, or session
401Authentication failedAPI Key is missing, invalid, or has insufficient permissions
422Validation failedParameter structure validation failed
500Processing failedDatabase, retrieval, model call, or other server errors