AI-COMPETE use case · system design

A Plant Assistant That Cites Its Sources or Says “I Don’t Know”

An agentic retrieval-augmented generation (RAG) system for an engine plant of the kind AI-COMPETE works with at Volvo Penta and Scania. Engineers and operators ask questions in Swedish or English about procedures, machines and energy rules. Every sentence of the answer points to a document and revision, a verifier checks each claim before it is shown, and a question the documents cannot answer is refused.

ContextUniversity of Skövde · AI-COMPETE (Vinnova) · 2026 · system design
Analytics stages
QualitativeDescriptiveDiagnosticPredictivePrescriptiveSoftware
Technology
PythonLangGraphQdrant (hybrid dense + BM25)Azure OpenAICross-encoder re-rankerFastAPI (SSE streaming)RedisDockerAzure Container AppsOpenTelemetry
ResultSystem design — architecture, indexing strategy and an evaluation harness with release gates. No production figures are claimed yet.
What this page is. A system design for a use case that comes out of the AI-COMPETE programme. It is not a report of a deployment at a partner site. Numbers marked target are release gates the system has to pass. They are not measured results.
Stakeholder engagement · problem formulation

A plausible wrong answer costs more than no answer

Thousands of pages under revision control, and nobody has time to read them at the line.

An engine plant runs on documents: work instructions, machine manuals, maintenance procedures, energy and carbon reporting rules, quality deviations. They come in two languages, and every one of them has revisions. Engineers search shared drives and ask whoever has been there longest. A general-purpose chatbot is worse, because it answers every question fluently whether or not the answer is in the documents.

The requirements came from the people who would be blamed for a wrong answer:

Architecture · agentic RAG

Retrieve, draft, verify, and loop back when a claim is unsupported

A LangGraph state machine rather than a single prompt, so each step can be tested and traced on its own.
One question, six testable steps, one verified answer Decomposesub-questions,filters from intent Hybrid retrieveQdrant dense + BM25RRF, metadata + ACL Re-rankcross-encoder,top 50 → top 8 Draftevery sentencecarries [doc·rev·§] Verify claimseach claim entailedby its cited chunk? Stream answerSSE, clickable citationsto the source page unsupported claim → rewrite the query and retrieve again (at most twice) still unsupported → refuse, name the nearest sources Question in Swedish or English · answer in the language of the question · the citation always points to the original text.
Each box is a node in the graph with its own inputs, outputs, trace span and test set.
  1. Decompose. A question like “what changed in the hardening furnace start-up procedure, and does it affect the energy log?” becomes two sub-questions. Named machines, lines and document types become metadata filters instead of search terms.
  2. Hybrid retrieve. Dense vectors find paraphrases. BM25 finds exact part numbers, fault codes and clause numbers, which embeddings handle badly. Reciprocal rank fusion merges the two lists inside Qdrant, and access-control filters are applied in the query itself, not after it.
  3. Re-rank. A cross-encoder rescores the 50 candidates and keeps 8, which is enough to answer and small enough to verify.
  4. Draft with a citation contract. The model may use only the chunks it has been given, and each sentence has to end with its source ID. A sentence with no source ID is removed.
  5. Verify. The draft is split into claims, and each claim is checked for entailment against the chunk it cites. An unsupported claim sends the graph back to retrieval with a rewritten query. After two failed tries it refuses.
  6. Stream. Server-sent events stream the verified answer as it is written. Each citation opens the source PDF at the cited page and highlights the passage.
Vector database · indexing strategy

Retrieval quality is decided at indexing time

Most RAG failures are chunking failures that only show up later.

Chunking that respects the document

  • Split on headings, never inside a numbered procedure. Step 4 without steps 1–3 is dangerous.
  • Tables are kept whole and also indexed as row-level text, so “torque for M12” hits the right row.
  • Parent–child chunks: small chunks are retrieved for precision, and the parent section is expanded into the context for completeness.
  • Scanned PDFs are OCR’d with layout detection. Pages with low OCR confidence are flagged for review instead of being indexed silently.

Metadata that does the filtering

  • Every chunk carries document type, line, machine ID, revision, effective date, language and an access-control group, all as indexed payload fields in Qdrant.
  • New revisions are ingested and the old ones are marked superseded, so an answer can never mix two revisions of one procedure.
  • Content hashes skip unchanged pages when re-indexing, so a nightly sync takes minutes.
  • Multilingual embeddings: a question in English retrieves a Swedish work instruction.
Context engineering

What reaches the model matters as much as which model

A token budget decides what goes in, in what order, and what is left out.
BudgetA fixed share of the window each for system rules, retrieved evidence, conversation and answer, so a long chat never pushes the evidence out.
OrderThe strongest evidence goes first and last, where models attend best. Near-duplicate chunks are merged before they take up space.
MemoryEarlier turns are compressed into a running summary. The facts the user has confirmed are kept word for word.
ContractThe system prompt is short, versioned and tested. It sets citation format, the refusal rule and the answer language, and it holds no domain knowledge.
Evaluation · RAG triad

Every change passes the same exam before it ships

A golden set written with process engineers, including questions that have no answer.

The golden set is planned at around 300 question–answer pairs, each tagged with the chunks that answer it, with about a fifth deliberately unanswerable from the corpus. The same suite runs in CI on every change to a prompt, the chunker, the embedding model or the re-ranker, and a change that drops any gate below target does not merge.

MetricHow it is measuredRelease gate (target)
Context relevanceShare of retrieved chunks that are relevant to the question (LLM judge, spot-checked by hand)≥ 0.85
GroundednessShare of answer claims entailed by their cited chunk≥ 0.95
Answer relevanceWhether the answer addresses the question that was asked≥ 0.90
Retrieval recall@8Gold chunk present among the 8 chunks passed to the model≥ 0.90
Correct refusalUnanswerable questions refused, not answered≥ 0.95
Retrieval latencyp95, hybrid query plus re-rank, warm cache excluded< 300 ms

Judges are cross-checked against a hand-labelled sample, because a judge nobody has validated is just a second model to trust.

Production stack

Built to be used by a shift, not only demonstrated

Containerised, observable and deployed inside the plant’s own cloud tenant.
ServingFastAPI with server-sent-event streaming and Entra ID sign-in. The user’s groups flow into the retrieval filter, so security trimming happens in the vector query.
CachingRedis caches embeddings by content hash and exact-match answers keyed to the index version, so a re-index invalidates cached answers automatically.
OperationsDocker images on Azure Container Apps with Qdrant alongside. OpenTelemetry traces every graph node, and a thumbs-down on an answer adds that question to the golden set.

Where it goes next: the same retrieval layer becomes the document tool that AI-COMPETE’s scheduling and carbon agents call when they need a rule, a machine limit or a reporting requirement. The agents then get the same citation guarantee the people do.