Skip to main content
ANNOUNCEMENTMeet MariaDB Enterprise Platform 2027. Read more.

Menu

WEBINAR

Built for the Agentic Era: Introducing MariaDB Enterprise Platform 2027

Watch now

Product

From Exception Report to AI Agent: How MariaDB Combines SQL and Vector Search

By Michael Aglietti

21 min read
Share

Key takeaways

  • Reviewers stop hunting for files. An AI agent can pull the numbers behind a flagged exception, find the reason in contracts or filings, and cite both. Reviewers then check citations instead of searching documents by hand.
  • One database holds both your numbers and your documents. MariaDB Cloud stores the structured financial data and the document knowledge base in the same service, so there’s no second vector database and no sync job between them.
  • People keep the decisions that matter. The agent handles lookups and drafts the explanation, but a person still decides what to do with every exception.
  • You can start small, at no cost. MariaDB AI Retrieval’s Public Preview includes 100 MCUs per organization each month. Loading 11 annual reports used about 61.
# The system prompt and the question start the conversation
llm.ask(question)

# One model call per step, up to 8 steps
for step in range(MAX_STEPS):

# The model replies with tool calls, or with its answer
reply = llm.step()

# A reply without tool calls is the answer
if not reply["calls"]:
return reply["text"]

# Run each tool, and send the results back to the model
results = []
for call in reply["calls"]:
result = tools.run(call["name"], call["args"])
results.append((call, result))
llm.add_results(results)

An exception report is a recurring query that lists records that broke a business rule, such as invoices more than 90 days overdue or borrowers over a loan limit. Each row is an exception. The query shows which records broke the rule, but the reason is usually in a document, such as a contract or filing, that a reviewer has to find.

A RAG workflow runs the same fixed steps for every question: it builds a search from a template, retrieves passages, and has a model draft an answer. An AI agent gets tools instead of a fixed path. The model decides what to look up, reads the result, and chooses its next step, much as an experienced reviewer would.

Yes. MariaDB Server has had a built-in VECTOR data type and vector index since version 11.7, so you can store embeddings and run similarity searches with SQL. MariaDB Cloud also offers AI Retrieval, a managed service that handles document parsing, chunking, embedding, and search for you.

MariaDB AI Retrieval is a MariaDB Cloud service that turns your documents into a searchable knowledge base. It parses documents, splits them into chunks, embeds each chunk, and searches them using hybrid search and reranking. It stores the knowledge base alongside your relational data in the same MariaDB Cloud service.

Structured data shows what changed, and documents explain why. In this example, SQL showed that interest expense outgrew operating income, causing net losses, but only the annual reports explained the new loan behind it. Neither source could answer the question alone.

 Hybrid search combines keyword search with vector search to find the 25 most relevant chunks quickly. A reranker, usually a cross-encoder, then reads the question and each candidate chunk together and scores how well it answers the question. This two-stage approach is more accurate than vector search alone and still fast enough for large knowledge bases.

 Check citations in code before a person sees the answer. In this example, a check of about 100 lines of Python confirms that every cited reference came from a tool call in the same run, and that every dollar amount appears in the source it cites. Failed answers go back to the model once, and a second failure is flagged for the reviewer.

 Enforce limits in the database session, not just in the prompt. Here, the SQL tool accepts only one SELECT statement, runs it in a read-only transaction, sets a 15-second limit with MariaDB’s max_statement_time variable, and returns at most 50 rows. These limits apply even if the model ignores its instructions.

Agents work well when a question needs about two steps, such as one query and one search. When the agent needs to see a number before it can choose the right search, move that step into the workflow as code. Otherwise, the agent may guess its search terms before seeing the data and miss part of the answer.

AI Retrieval is in Public Preview in MariaDB Cloud, with no separate sign-up. You need a MariaDB Cloud account with a role above Viewer. Find it under AI & Automation in the portal, and use the quickstart to create a knowledge base, upload a file, and run a first query. The preview includes 100 MCUs per organization each month.