For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 /retrieve

Purpose: 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 query

  • top_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 identifier

  • document_id: ID of the source document

  • content: The chunk text content

  • metadata: Additional metadata about the chunk

  • distance: 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.

Purpose: Performs full-text search using MariaDB's FULLTEXT index to find relevant document chunks.

Request body:

Request Parameters:

  • query (required): The search query

  • top_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 identifier

  • document_id: ID of the source document

  • source: File path of the source document

  • content: The chunk text content

  • score: Relevance score (higher = more relevant)

Usage Example: Use this endpoint for keyword-based search when you need exact term matching.

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 query

  • top_k (optional): Number of results to return (default: 20)

  • k (optional): RRF parameter for rank fusion (default: 60)

  • provider (optional): Embedding provider for semantic search

  • model (optional): Embedding model for semantic search

  • document_ids (optional): Filter results to specific document IDs

Response: Array of hybrid search results

Response Fields:

  • id: Unique chunk identifier

  • document_id: ID of the source document

  • source: File path of the source document

  • content: The chunk text content

  • metadata: Additional metadata about the chunk

  • distance: 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 prompt

  • chunks (required): Array of context chunks to use for generation

  • llm_provider (optional): LLM provider - openai, anthropic, gemini, cohere, ollama, azure, bedrock

  • llm_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.

Last updated

Was this helpful?