Raw Code

Applied AI

RAG, a classifier, or plain code? Picking the right tool for an AI automation

By the Raw Code team · · 3 min read

Short answer

Ask what the output looks like. If it's an answer that lives in your documents, use retrieval (RAG). If it's one label from a fixed list, use a classifier. If it's a number about the future, use a forecasting model. If a rule can produce it, write the rule and skip the AI.

Start from the output, not the model

"Can we use AI for this?" is the wrong first question, because the answer is nearly always yes and it doesn't tell you what to build. A better one is: what does a correct result look like? Across the projects our ML lead has shipped, the answer falls into a few shapes, and each shape points to a different tool.

The output is…UseExample
An answer that exists in your own documentsRetrieval-augmented generation (RAG)Darnytsia's document-grounded chatbots
One label from a fixed listA classifierSkanska's ticket routing
A number about the futureA forecasting modelJera's electricity forecasts
Something a clear rule can decidePlain code, no AISums, dates, lookups, matching IDs

When the answer is in your documents: RAG

A general chatbot answers from whatever its model absorbed in training, which knows nothing about your policies. Retrieval-augmented generation fixes that by searching your documents first and giving the model only what it found to answer from.

Darnytsia's chatbots work this way: a Python retrieval layer finds the relevant passages in the company's reference material, then the ChatGPT API writes the reply from them. The search step is the part that decides quality, which is why we treat it as its own piece of work, covered on our semantic search page.

RAG is usually a better first step than fine-tuning a model on your documents. Updating a document updates the answers the same day, and every answer can point back to its source.

When the output is a label: a classifier

Routing a ticket, tagging an email, or sorting an invoice by type doesn't need a model that writes. It needs one that picks from a list, and a dedicated classifier does that faster, cheaper, and more predictably than a chatbot asked to choose.

Skanska's service tickets were sorted by hand. NLP models now read each ticket and route it through the ServiceNow API, running on Azure Functions. The client reported that about 90% of human classification errors were eliminated and processing got 50% faster.

When the output is a number about the future: forecasting

Demand, consumption, and staffing questions are time series problems, and language models are the wrong tool for them. Jera's forecasts combine historical electricity use with weather and other outside factors, and Kubeflow pipelines retrain the models on a schedule so they don't go stale. The client reported a 20% increase in economic efficiency for electricity generation. More on that on our time series forecasting page.

When a rule will do: no AI

Adding up invoice lines, checking a date is in range, or matching an order number across two systems should be plain code. It's cheaper, it's exact, and it gives the same answer every time.

Most real automations mix the two. In a weekly report, code pulls the numbers and does the math, and the AI writes the plain-language summary. In reconciliation, code matches the clean records and the AI handles the messy free-text fields that rules can't. The AI automation page lists the workflows we see most often and how each one splits.

Before choosing any of them

  • Write down five real inputs and the correct output for each. If you can't, the task isn't defined well enough to automate yet.
  • Decide what a wrong answer costs. That sets where a person stays in the loop.
  • Try it on your real data before committing to a build. A prototype on a sample of actual emails, documents, or history shows the edge cases a demo hides.

Related

More from the blog

Have a problem like this?

Tell us about it on a free call and we'll say what we'd try first.

Book free consultation