Retrieval and Search
MariaDB AI RAG retrieval and search endpoints provide semantic vector, full-text, and hybrid Reciprocal Rank Fusion search, plus synchronous, async, and streaming LLM generation.
Retrieval and Search Endpoints
Semantic Retrieval
POST /retrievePurpose: Performs semantic search to retrieve relevant document chunks based on a query using vector similarity.
Request body:
{
"query": "What is MariaDB AI RAG?",
"top_k": 20,
"document_ids": [42, 43]
}Request Parameters:
query(required): The search querytop_k(optional): Number of results to return (default: 20)document_ids(optional): Filter results to specific document IDs (default: all documents)
Response: Array of retrieval results
[
{
"id": "uuid-chunk-id",
"document_id": 42,
"content": "MariaDB AI RAG is an enterprise-grade RAG solution...",
"metadata": {},
"distance": 0.15
},
{
"id": "uuid-chunk-id-2",
"document_id": 43,
"content": "Key features include document processing and semantic search...",
"metadata": {},
"distance": 0.23
}
]Response Fields:
id: Unique chunk identifierdocument_id: ID of the source documentcontent: The chunk text contentmetadata: Additional metadata about the chunkdistance: Vector distance (lower = more similar)
Usage Example: Use this endpoint to find semantically relevant information. The system converts your query into a vector embedding and finds the most similar chunks.
Full-Text Search
Purpose: Performs full-text search using MariaDB's FULLTEXT index to find relevant document chunks.
Request body:
Request Parameters:
query(required): The search querytop_k(optional): Number of results to return (default: 10)document_ids(optional): Filter results to specific document IDs
Response: Array of search results
Response Fields:
id: Unique chunk identifierdocument_id: ID of the source documentsource: File path of the source documentcontent: The chunk text contentscore: Relevance score (higher = more relevant)
Usage Example: Use this endpoint for keyword-based search when you need exact term matching.
Hybrid Search
Purpose: Combines semantic search (vector similarity) and full-text search using Reciprocal Rank Fusion (RRF) for optimal results.
Request body:
Request Parameters:
query(required): The search querytop_k(optional): Number of results to return (default: 20)k(optional): RRF parameter for rank fusion (default: 60)provider(optional): Embedding provider for semantic searchmodel(optional): Embedding model for semantic searchdocument_ids(optional): Filter results to specific document IDs
Response: Array of hybrid search results
Response Fields:
id: Unique chunk identifierdocument_id: ID of the source documentsource: File path of the source documentcontent: The chunk text contentmetadata: Additional metadata about the chunkdistance: Vector distance from semantic search (lower = more similar)score: Full-text relevance score (higher = more relevant)
Usage Example: Use this endpoint for the best of both worlds - combining semantic understanding with keyword matching.
Generate Text
Purpose: Generates a response to a query using a language model and the provided context chunks.
Request body:
Request Parameters:
query(required): The user's question or promptchunks(required): Array of context chunks to use for generationllm_provider(optional): LLM provider -openai,anthropic,gemini,cohere,ollama,azure,bedrockllm_model(optional): Specific model to use (e.g.,gpt-4,claude-3-opus)temperature(optional): Controls randomness (0.0-2.0, default: 0.7)top_p(optional): Nucleus sampling parameter (0.0-1.0, default: 0.9)max_tokens(optional): Maximum tokens to generate (1-8192, default: 500)
Response:
Usage Example: Use this endpoint after retrieving relevant chunks to generate a coherent response based on the information in those chunks.
Asynchronous Generation
Purpose: Generates a response asynchronously, useful for long-running generation tasks.
Request body: Same as /generate
Response: Same as /generate
Usage Example: Use this endpoint for generation tasks that may take longer to complete.
Streaming Generation
Purpose: Generates a response with streaming output (Server-Sent Events), allowing for real-time display of results as tokens are generated.
Request body: Same as /generate
Response: Server-Sent Events (SSE) stream with the following event types:
Usage Example: Use this endpoint for a better user experience when generating longer responses, as it allows displaying partial results as they become available.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

