Skip to content
Hamza Kara Bala
Hover or press Down Arrow for volume and settings.
Let’s talk

Admin

Build a Laravel RAG Assistant That Can Say “I Don’t Know”

7 min estimated read0 views0 completed reads
Build a Laravel RAG Assistant That Can Say “I Don’t Know”

A traveller asks what the Puente Nuevo bridge in Ronda crosses. That fact is stable enough to verify against the place page. A question about access on a particular date has a different requirement. The assistant needs evidence that covers the day the traveller has in mind.

This guide builds a Laravel retrieval-augmented generation (RAG) workflow around that distinction. It covers how to store evidence, retrieve it in two languages, verify it before answering, and test the cases where the assistant should ask a question or say it could not confirm the answer.

What happened when we asked Wwain AI about Ronda?

On November 7, 2026, I opened the Wwain listing for Puente Nuevo of Ronda in Spain and asked the public assistant where the bridge is, what it crosses, and which parts of the city it connects. I also asked for the Wwain place link.

What I checked

What I observed

Question in Arabic

The assistant said it could not find information about the bridge in its available Wwain results.

Fresh conversation with the English listing title

The assistant identified Ronda and El Tajo gorge and described the connection between the historic and newer quarters. It said it could not find the Wwain link.

Public place page

The listing confirms the city, the gorge and the connection between the two parts of Ronda.

The English answer matched the place page on all three facts. Its missing link is a separate result. The reader had no way to trace the facts to the listing from the reply itself. A single exchange in each language cannot tell us which sources the system retrieved or why the replies differed.

Turn this into an acceptance test with two independent checks. First, see whether the assistant answers the question correctly. Then see whether it returns the exact page that supports the answer. A second fixture can ask for date-specific access without an applicable source and check that the assistant communicates the gap.

Store facts with enough context to verify them

Put a source record behind every passage you index. Keep the original display text alongside the search text, along with its canonical URL, locale, source owner, section heading and stable entity ID. A venue’s Arabic name, English name and common transliterations can all point to the same entity. This helps the system resolve جسر بوينتي نويفو and Puente Nuevo of Ronda before asking a model to interpret the evidence.

Track when a source was checked separately from the dates when its contents apply. A notice verified this morning can still describe last month’s schedule. A holiday notice can supersede a current weekly timetable for one day. Store and compare the requested date in the destination’s time zone, and check coverage before ranking a passage as eligible for an hours answer.

Field

What it controls

entity_id and locale

Resolve names across languages and prefer passages the reader can use.

source_url and source_type

Show where a claim came from and prefer the operator for time-sensitive venue facts.

verified_at

Tell when your application last checked the source.

valid_from and valid_until

Determine whether the record covers the date in the question.

During ingestion, split documents by meaning. Keep a heading with the passage it introduces and preserve the relationship between special schedules and the venue they modify. Reindex on updates and remove or supersede old passages when an editor replaces a notice. Otherwise both versions can remain searchable after the source has changed.

Retrieve in stages and validate before generation

  1. Resolve the question. Extract the place and requested date. If a name maps to several cities and the context cannot resolve it, ask which one the visitor means.

  2. Filter what can be used. Check visibility, the relevant entity, source type and date coverage. When the question depends on current inventory, prices or similar changing data, prefer a live service that owns the value.

  3. Combine keyword and semantic retrieval. Use keyword matching for names and identifiers, and vector similarity for paraphrases. Preserve Arabic display text while maintaining normalized search aliases. Meilisearch hybrid search guide

  4. Rerank a limited set. Move passages that answer the question above broad topic matches. Keep the original document IDs with the candidates so the application can trace a result back to its source.

Laravel’s AI SDK exposes both embeddings and reranking. The snippet below illustrates reranking after your application has already filtered the candidates. It passes plain strings to the SDK and uses the returned original index to recover the record behind the top match. Run this stage only when you have candidates and choose a configured reranking provider. Laravel AI SDK documentation

use Laravel\Ai\Reranking;

// $eligible contains approved records with consecutive numeric keys.
$passages = array_column($eligible, 'passage');
$ranking = Reranking::of($passages)
    ->limit(4)
    ->rerank($question);

$first = $ranking->first();
$topSource = $first === null ? null : $eligible[$first->index];

The limit of four passages is a starting point to test with your own questions. Measure whether reranking improves the evidence enough to justify another request. If your data and permissions already live in PostgreSQL, pgvector offers vector similarity search in the same database. Measure retrieval with your real filters as well as without them, since filtering can affect how many results an approximate index returns. pgvector documentation

Make uncertainty an explicit response state

Ask the generation step for a structured result with status, answer and source_ids. Use three states such as answered, needs_clarification and unverified. When your server cannot find eligible evidence for a date-sensitive claim, it can return unverified directly. There is no need to call the model to guess around a missing record.

Map source IDs to URLs on the server. Reject IDs outside the retrieved set and verify that the cited passages support the specific claims. An allowed ID alone says nothing about whether it proves Friday’s hours. For opening times, keep the actual time values in an authoritative structured record when possible, so the application can validate them without asking another model to interpret prose.

Test retrieval and the answer separately

Test fixture

Expected behaviour

Arabic query and current English operator notice

Resolve the entity, verify date coverage, answer in Arabic and link to the notice.

Old guide and date-specific operator notice

Use the notice for the requested day and keep the older guide out of the supporting citations.

Two similarly named places

Ask which place or city the user means.

Popular venue with no applicable hours

State that the hours could not be verified and avoid guessing a time.

Unrelated or unknown source ID

Reject the citation and fall back to an answer supported by evidence or to an unverified result.

Record whether the expected source appeared in the first few retrieved results, whether each factual claim had support, and whether the assistant withheld an answer in the fixtures designed for uncertainty. Compare these results across languages and record latency for retrieval, reranking and generation separately. A correct passage missing from retrieval is a different problem from a correct passage that the model misread.

Start with one class of question, such as venue hours. It gives you a defined entity, a date, a source of truth and a clear result you can test before expanding into more open-ended travel recommendations.

0 likes
0 share actions

Updated Nov 7, 2026

Related articles

Discussion (0)

Be the first to join the conversation.

Leave a comment

Comments are reviewed before publication. Your name will be visible; your email stays private.

Completing the security check…