ИТ развој

Beyond the prompt: architecting databases that truly power AI

Надвор од поттикот: архитектура на бази на податоци што навистина ја напојуваат ВИ

Most AI projects do not fail because the prompt was weak. They fail because the system behind the prompt cannot reliably find, interpret, protect, or update the information the model needs.

A polished chat interface can hide a fragile backend for a while. Then real users arrive with ambiguous questions, stale records, missing permissions, and requests that span multiple systems. At that point, “add AI” stops being a feature request and becomes an architecture problem.

The durable approach is to treat an AI application as a data product with a language model at its edge. Prompts matter, but schemas, retrieval paths, API contracts, observability, and operational discipline matter more.

Start with the job, not the model

Before choosing a vector database or designing an agent workflow, define the decisions the application must support. “Answer questions about our documentation” is too broad. “Help a support engineer identify the current refund rule for a customer’s region” is specific enough to shape the system.

That distinction determines what data is authoritative, how fresh it must be, whether results require citations, and what happens when the system is uncertain. An AI system should not silently improvise around missing business data. It should be able to say that it cannot verify an answer and offer the next useful action.

For every high-value AI interaction, identify:

  • the source of truth for each required fact;
  • the acceptable age of that fact;
  • the user and tenant permissions that apply;
  • the consequence of a wrong answer or action;
  • the fallback when retrieval or downstream services fail.

This is ordinary backend design, which is precisely why it is effective. AI changes the interface to information; it does not remove the need for reliable information systems.

Keep operational data and semantic search connected

Relational databases remain excellent homes for transactional truth: users, orders, permissions, audit events, workflow state, and structured business rules. They offer constraints, transactions, joins, and familiar operational tooling. A semantic index solves a different problem: finding relevant text or other content when a question does not match exact keywords.

These systems should complement each other rather than compete. A common failure mode is copying documents into an embedding pipeline and treating the resulting index as the application database. That creates a second, less governable version of the truth.

A healthier model stores canonical content and metadata in the primary database, then derives searchable chunks and embeddings from it. Each indexed chunk should retain stable identifiers that point back to its source record, version, tenant, visibility rules, and update state.

CREATE TABLE knowledge_documents (
  id UUID PRIMARY KEY,
  tenant_id UUID NOT NULL,
  title TEXT NOT NULL,
  body TEXT NOT NULL,
  version INTEGER NOT NULL,
  visibility TEXT NOT NULL,
  updated_at TIMESTAMP NOT NULL
);

The vector index can store a document identifier and chunk identifier, but the application should still validate access and retrieve authoritative metadata before presenting an answer. That extra lookup is often worth the latency because it prevents an index from becoming a shortcut around permission checks.

Design chunks for change, not just relevance

Chunking is often described as a retrieval-quality problem. It is also a maintenance problem. A chunk should have enough context to stand alone, but not so much that one small edit forces broad reindexing or dilutes relevance.

Use stable chunk identities where possible, track the source version used to create each embedding, and make indexing idempotent. If a worker retries after a timeout, it should safely replace or confirm the expected index entry rather than create duplicates.

Make ingestion an explicit pipeline

Content reaches an AI system through updates, imports, events, and background jobs. Treat that path as a first-class pipeline, not an incidental side effect of a save operation.

For example, a PHP application can commit a document update and record an outbox event in the same database transaction. A worker later reads that event, extracts normalized text, creates chunks, updates the search index, and marks the event complete. This avoids the awkward state where a request updates the database but crashes before notifying the indexer.

$document = $documents->update($id, $payload);

$outbox->record('document.changed', [
    'document_id' => $document->id,
    'version' => $document->version,
]);

$database->commit();

The worker needs deliberate failure behavior. Retry transient network failures with bounded attempts and backoff. Send permanently malformed content to a reviewable failure queue. Record enough context to diagnose the issue without logging sensitive document bodies or credentials.

Eventual consistency is acceptable when it is visible. If newly published guidance may take a few minutes to become searchable, expose that state internally and avoid claiming instant availability to users.

Put retrieval behind a narrow backend contract

Do not let every controller assemble prompts, query indexes, and call model providers directly. Put AI orchestration behind a service boundary with a clear contract. In PHP, that might be an application service that accepts an authenticated user, a question, and a bounded scope.

That service can perform authorization, retrieve candidates, filter them by tenant and visibility, build a model request, validate the result, and return both an answer and its supporting references. Controllers remain thin, and tests can focus on deterministic steps without requiring a live model call.

A useful response contract separates generated language from factual support:

{
  "answer": "The policy allows...",
  "sources": [
    { "document_id": "…", "title": "Refund policy", "version": 4 }
  ],
  "status": "grounded"
}

If the system cannot find adequate support, return a distinct status such as insufficient_context. Do not disguise uncertainty with fluent prose. The model can be asked to summarize retrieved material, but it should not be the authority that decides whether a source is current or accessible.

Operate AI features like production services

Prompt text deserves version control, but it is only one versioned dependency. Retrieval logic, chunking rules, model configuration, response schemas, and evaluation examples should evolve together. A prompt change can appear successful while masking a regression in citation quality or permission filtering.

Measure the system at the boundaries where it can fail:

  • ingestion delay from source update to indexed availability;
  • retrieval results, filters applied, and source versions selected;
  • model latency, provider errors, retries, and timeout rates;
  • structured validation failures and fallback usage;
  • user feedback tied to an answer and its retrieved sources.

Be cautious with logging. Questions, retrieved passages, and prompts may contain confidential data. Apply retention rules, access controls, and redaction policies before sending observability data to shared systems.

Containerization helps make this architecture repeatable. A Docker-based local environment can run the PHP application, relational database, queue worker, and search service with explicit configuration. But containers do not solve consistency by themselves; health checks, migrations, backups, secrets management, and resource limits still require ownership.

The prompt is the last mile

A great prompt can improve tone, formatting, and instruction following. It cannot repair stale data, missing authorization, ambiguous ownership, or an unreliable event pipeline. Those are architecture concerns, and they deserve the same care given to payments, authentication, and other critical backend capabilities.

The most capable AI products will not be defined by the cleverest single prompt. They will be defined by systems that know what they know, can show where it came from, respect who may see it, and fail safely when the evidence is not there. That is how a database stops being storage and becomes the foundation of useful intelligence.

Портрет на автор на блогот

Mihajlo

Јас сум Михајло - развивач поттикнат од љубопитност, дисциплина и постојаната желба да создадам нешто значајно. Споделувам увиди, упатства и бесплатни услуги за да им помогнам на другите да ја поедностават својата работа и да растат во постојано развивачкиот свет на софтверот и вештачката интелигенција.