Web Technologies

Chapter 14
AI-Enabled Web Applications and Emerging Trends

Bachelors Program in AI & ML
Web Technologies   •   Bachelor

AI-Enabled Web Applications and Emerging Trends

Introduction and Context

The web has evolved from a document-delivery system into a platform for intelligent, interactive and distributed applications. Modern web applications can call machine-learning (ML) services, generate text or images, search semantic knowledge bases, process live streams, and adapt interfaces to user needs. At the same time, these capabilities introduce risks involving privacy, discrimination, security, misinformation, accessibility and accountability.

An AI-enabled web application is therefore more than a webpage connected to an AI API. It is a socio-technical system that combines user experience, software architecture, data pipelines, models, security controls, operational monitoring and governance. Successful development requires both technical competence and critical evaluation of what the system should do, what evidence supports its outputs and who is responsible when it fails.

This chapter examines practical integration patterns for ML and generative AI, streaming and vector retrieval, model-centred user experience, safety and governance. It then considers progressive web applications (PWAs), WebAssembly, edge computing, WebXR, decentralized technologies and emerging web standards.

Learning Objectives

By the end of this chapter, students should be able to:

1. Explain the architecture of an AI-enabled web application.

2. Integrate external ML and generative-AI services through secure APIs.

3. Distinguish request-response, streaming and retrieval-augmented architectures.

4. Design basic vector-search and retrieval-augmented generation workflows.

5. Evaluate model UX, reliability, safety, bias, privacy and governance.

6. Compare PWAs, WebAssembly, edge computing, WebXR and decentralized approaches.

7. Select suitable technologies for a stated application context.

8. Identify limitations, operational risks and future directions of intelligent web systems.

1. Architecture of an AI-Enabled Web Application

A conventional web application usually contains a client, an application server, databases and external services. An AI-enabled system adds model inference, feature or document pipelines, prompt and policy management, evaluation, and often a vector index.

A representative architecture contains the following layers:

  • Experience layer: browser interface, accessibility features, conversation history, loading states and explanations.
  • Application layer: authentication, authorization, business rules, orchestration and rate limiting.
  • AI service layer: classification, recommendation, speech, vision, language-model or embedding APIs.
  • Knowledge layer: transactional databases, object storage, document repositories and vector indexes.
  • Trust layer: validation, content filtering, audit logs, privacy controls, monitoring and human review.
  • Operations layer: deployment, observability, cost management, model/version control and incident response.

A browser should normally not contain a secret API key. The browser calls an application server, which authenticates the user, validates input, applies policy and calls the model provider. This pattern also permits provider replacement, usage accounting and centralized protection against abuse.

Inference modes

In synchronous inference, the client sends a request and waits for a complete response. It is simple and appropriate for short classifications or recommendations. In asynchronous inference, a job is submitted and the client later receives status and results; this suits long document analysis or media generation. In streaming inference, partial results are delivered as they become available, improving perceived responsiveness for conversational systems. Streaming does not necessarily reduce total computation time; it changes when users see output.

Common transport choices include ordinary HTTP requests, Server-Sent Events (SSE) for one-way server-to-client streams, and WebSockets for bidirectional real-time communication. A production stream should define reconnection behavior, event identifiers, cancellation, timeouts and a final completion or error event.

API integration principles

A robust integration should:

1. validate and constrain user input;

2. authenticate requests and authorize access to data;

3. use timeouts, retries and bounded exponential backoff for transient failures;

4. avoid retrying non-recoverable validation or authorization errors;

5. record model, prompt-template and policy versions;

6. protect personal and confidential data;

7. set usage and cost limits;

8. return understandable error states rather than fabricated answers.

For example, a tutoring application may send a student question to an orchestration service. The service retrieves approved course material, constructs a constrained prompt, invokes a language model, checks the response, and returns both an answer and citations. The client displays the answer as provisional until the response is complete.

2. Embeddings, Vector Retrieval and Retrieval-Augmented Generation

An embedding is a numerical representation of an item such as a sentence, image or product. Items with related meanings tend to occupy nearby positions in an embedding space. The embedding model, however, does not create truth; it creates a representation useful for similarity-based operations.

A vector database stores embeddings and metadata such as document identifier, author, access permissions and timestamp. At query time, the system embeds the user query and retrieves nearby records. A common similarity measure is cosine similarity:

\[

\operatorname{cos}(x,y)=\frac{x\cdot y}{\|x\|\|y\|}

\]

Here, x and y are non-zero vectors, x·y is their dot product, and ||x|| and ||y|| are their Euclidean lengths. Cosine similarity is dimensionless and is especially useful when direction is more important than magnitude. It is not meaningful for a zero vector. Some systems instead use Euclidean distance or an inner product, depending on the embedding model and index configuration.

Retrieval-augmented generation (RAG)

RAG separates knowledge retrieval from language generation:

1. collect and authorize source documents;

2. clean and divide documents into meaningful chunks;

3. generate an embedding for each chunk;

4. store vectors and metadata;

5. embed the user query;

6. retrieve candidate chunks;

7. optionally rerank them using a more precise model;

8. place selected evidence in the model context;

9. generate an answer constrained to the evidence;

10. cite sources and evaluate the result.

Chunk size is a design trade-off. Very small chunks lose context; very large chunks reduce retrieval precision and consume context capacity. Chunk boundaries should respect headings, paragraphs, tables and code blocks rather than blindly splitting characters.

Access control must be applied during retrieval, not merely at display time. Otherwise, a model may receive confidential text even if the final answer hides it. Metadata filters can restrict results by tenant, course, role or document status.

Worked example: cosine similarity

Suppose a query vector is x=(1,2) and a document vector is y=(2,1). The dot product is 1×2+2×1=4. The lengths are √5 and √5. Therefore:

cos(x,y)=4/(√5×√5)=4/5=0.8.

The result indicates a positive directional similarity under this representation. It does not mean that the document is factually correct or that 80 percent of the answer is reliable. Similarity is a retrieval signal, not a truth score.

RAG limitations

RAG can retrieve irrelevant, outdated or contradictory sources. It can also fail when a question requires multi-step reasoning across many documents. A model may cite a relevant passage but draw an unsupported conclusion. Evaluation should therefore measure retrieval quality and answer quality separately, using representative test questions, citation checks, human review and adversarial tests.

3. Model-Centred User Experience

AI changes the design problem from displaying deterministic results to communicating uncertain, probabilistic outputs. A responsible interface should make the system’s capabilities and limits visible without overwhelming the user.

Important patterns include:

  • Expectation setting: explain what the system can and cannot do.
  • Progressive disclosure: show concise results first, with evidence, reasoning summaries or details available when needed.
  • Uncertainty communication: use calibrated labels such as “needs review” rather than arbitrary confidence percentages.
  • Source grounding: provide links, document titles, dates and quoted evidence where appropriate.
  • Correction and feedback: allow users to edit, reject or report outputs.
  • Human control: provide cancel, undo, approval and escalation mechanisms.
  • Safe defaults: do not automatically send, publish, purchase or delete based solely on generated output.
  • Accessibility: support keyboard operation, screen readers, captions, readable contrast and alternatives to voice or visual interaction.

A generated answer should be treated as a suggestion until validated according to the consequences of the task. A low-risk brainstorming assistant can tolerate more uncertainty than a medical triage or financial decision system. This is a form of risk-proportionate design.

4. Safety, Bias, Privacy and Governance

Safety engineering

Safety controls should exist at several stages:

  • input validation and abuse detection;
  • authentication, authorization and tenant isolation;
  • prompt and tool restrictions;
  • output filtering and schema validation;
  • sandboxing of code or tool execution;
  • human approval for high-impact actions;
  • logging, monitoring and incident response.

Prompt injection is an attack in which untrusted content attempts to override system instructions. It is particularly important in RAG and agentic systems because retrieved documents, web pages or emails may contain adversarial instructions. A robust design treats retrieved text as data, limits tool permissions, validates tool arguments and separates instructions from content.

Sensitive information can leak through prompts, logs, vector stores or generated responses. Data minimization, encryption, retention limits, access control and redaction reduce exposure. Developers must check whether a provider stores submitted data, uses it for training, or transfers it across jurisdictions.

Bias and fairness

Bias may arise from historical data, under-representation, labels, measurement choices, model design or unequal deployment conditions. A model can have different error rates across groups even when its overall accuracy appears high. Evaluation should examine relevant subgroups, but subgroup analysis must protect privacy and avoid inappropriate classification.

Fairness is not one universal mathematical condition. For example, equal false-positive rates and equal positive predictive values cannot generally both be achieved when groups have different base rates, except in special circumstances. Consequently, fairness criteria must be selected with domain experts, affected communities and legal requirements in mind. Technical metrics support judgment; they do not replace it.

Governance

Governance assigns responsibility across the system lifecycle. A useful governance record includes purpose, owner, data sources, model and prompt versions, known limitations, evaluation evidence, permitted uses, prohibited uses, monitoring indicators and incident procedures. Impact assessments are appropriate when systems affect education, employment, credit, healthcare, public services or other rights.

Relevant principles include legality, transparency, accountability, privacy, security, accessibility, human oversight and proportionality. Exact obligations differ by jurisdiction and sector, so legal review is necessary. Standards and regulatory frameworks continue to develop; organizations should track applicable data-protection, consumer-protection, accessibility and AI-specific rules rather than relying on informal assurances.

5. Progressive Web Applications and WebAssembly

A PWA uses web technologies while offering some app-like capabilities. A web app manifest describes installation metadata, and a service worker can intercept requests, cache resources and support offline experiences. HTTPS is required for service-worker security except in controlled local-development contexts.

Offline design is not simply “cache everything.” Developers must classify data as immutable, refreshable, private or transaction-sensitive. A news reader can cache articles, whereas an offline banking interface must avoid implying that a transaction succeeded before server confirmation. Synchronization conflicts require explicit policies.

WebAssembly (Wasm) is a portable binary instruction format that runs in browser and server runtimes. It is useful for computationally intensive, performance-sensitive or cross-language modules such as image processing, simulation, cryptography and on-device inference. Wasm does not automatically make code secure or faster: memory safety depends on the source language and interfaces, and calls across the JavaScript–Wasm boundary have costs. Large model files also create download, memory and battery constraints.

6. Edge Computing and On-Device Intelligence

Cloud inference centralizes computation and simplifies model management. Edge inference moves computation closer to users, for example to a regional point of presence, while on-device inference runs on the user’s hardware. These approaches can reduce latency, bandwidth and exposure of raw data, but they introduce constraints in memory, energy, hardware diversity, model updating and observability.

A hybrid architecture is often appropriate: perform speech wake-word detection or basic personalization on-device, use an edge service for low-latency filtering, and use a central service for complex analysis. Designers should measure end-to-end latency, not merely model execution time. A fast model can still produce a slow experience if network negotiation, serialization or queueing dominates.

7. WebXR and Decentralized Technologies

WebXR enables browser experiences involving virtual-reality and augmented-reality devices. Applications must handle device capability negotiation, tracking loss, changing frames of reference, motion comfort, spatial audio, input diversity and accessibility. Avoiding excessive acceleration, providing stable reference points and allowing user control can reduce discomfort. Camera, microphone and spatial data are sensitive and require clear permission and minimization.

Decentralized technologies distribute trust or data across networks rather than relying entirely on a single provider. Distributed ledgers can support verifiable records, digital assets or programmable transactions. Decentralized identifiers and verifiable credentials can allow users to present claims without exposing unnecessary information. However, decentralization does not guarantee privacy, correctness or usability. Public records may be permanent, transaction fees and throughput may be problematic, keys can be lost, and governance may remain concentrated in practice.

A sound design asks why decentralization is needed. If a conventional database with strong access controls meets the requirement, it may be more efficient and easier to govern. If verifiability across organizations is central, a decentralized or federated architecture may have a stronger justification.

8. Emerging Web Standards and Directions

The modern web platform is developing toward richer capabilities while preserving security and interoperability. Important directions include improved WebGPU access for parallel graphics and potentially local ML workloads; WebRTC for real-time audio, video and data; WebAuthn and passkeys for phishing-resistant authentication; Web Components for reusable interface elements; and privacy-oriented browser APIs that limit covert tracking.

Future systems are likely to combine multimodal models, local inference, retrieval, real-time collaboration and tool use. Standards will need to address permission boundaries, model provenance, content authenticity, portability, accessibility and energy use. Developers should prefer open protocols and progressive enhancement: an application should remain usable when a powerful model, advanced sensor or particular browser feature is unavailable.

9. Illustrative Case: A University Research Assistant

Background. A university wants a web assistant that helps students locate policies, laboratory procedures and course guidance. The assistant must not invent rules or expose documents restricted to staff.

Problem. Students ask natural-language questions across thousands of documents. A keyword search produces either too many results or misses paraphrased queries. A general language model can produce fluent but unsupported answers.

Analysis. The system has three risk classes. Low-risk requests ask for navigation. Medium-risk requests summarize academic procedures. High-risk requests concern safety, assessment appeals or personal records and require escalation. Documents also have ownership, version and audience metadata.

Approach. The university builds an authenticated server-side application. An ingestion pipeline extracts text, preserves headings, records document versions and creates embeddings. At query time, authorization filters are applied before vector retrieval. A reranker selects a small evidence set. The language model receives only authorized passages and is instructed to answer with citations, state when evidence is insufficient and route high-risk questions to staff. The interface displays source dates, a feedback control and an escalation option. Logs exclude unnecessary personal content and retain model, retrieval and policy versions.

Evaluation uses a test set prepared by librarians, faculty and students. Measures include retrieval of the authoritative document, citation correctness, answer completeness, refusal appropriateness, subgroup usability and response latency. Red-team tests include prompt injection inside documents, attempts to retrieve staff-only policies and misleading outdated documents.

Outcome. In this illustrative scenario, the system improves discovery and reduces repetitive inquiries, but it does not replace official policy publication or human decision-making. When documents conflict, the assistant reports the conflict and directs the student to the responsible office.

Learning points. Retrieval quality, permissions and document currency are as important as model choice. A visible citation is useful only when it actually supports the answer. Risk classification enables proportionate human oversight, and governance must be designed before deployment rather than added after an incident.

10. Professional Design and Evaluation Practices

A development team should begin with a problem statement and a measurable success criterion, not with a fashionable model. It should establish a data inventory, threat model, accessibility requirements, failure-handling plan and ownership structure. Prototypes should use synthetic or minimized data until privacy and security controls are validated.

Evaluation should include functional tests, adversarial tests, accessibility testing, load testing, cost analysis and monitoring in real use. Useful indicators may include task completion, grounded-answer rate, unsafe-output rate, escalation appropriateness, latency, availability, energy consumption and user correction rate. Metrics require definitions and sampling methods; a single aggregate score can conceal serious failures.

Model and prompt changes should be versioned and tested against a fixed evaluation set plus newly observed failure cases. Monitoring should detect drift in user questions, data distributions, retrieval results, latency and cost. An incident process should support disabling a feature, reverting a model, notifying affected users and preserving evidence for investigation.

Challenges and Limitations

AI-enabled web applications remain limited by imperfect data, changing model behavior, hallucination, distribution shift, vendor dependence and computational cost. Streaming can create a false impression of confidence because fluent partial text appears before verification. Vector retrieval may amplify biased or stale source collections. On-device models may be less capable, while cloud models create privacy and availability dependencies. PWAs and emerging APIs vary across browsers and devices. Decentralized systems can make correction difficult, and WebXR can exclude users who lack specialized hardware.

These limitations imply that technical novelty is not a sufficient design criterion. A system should be understandable, maintainable, secure, accessible and appropriate to its social context. Sometimes the best solution is conventional search, a rules engine or a human workflow rather than generative AI.

Chapter Summary

AI-enabled web applications combine browser experiences, application services, ML APIs, retrieval systems, data stores and governance controls. Secure server-side orchestration protects credentials and enables validation, rate limiting and auditing. Request-response, asynchronous and streaming architectures serve different latency and interaction needs.

Embeddings support semantic retrieval, while RAG supplies selected evidence to a generative model. Vector similarity is a retrieval signal, not a measure of truth. Effective systems enforce authorization before retrieval, cite sources, evaluate retrieval and generation separately, and expose correction and escalation paths.

Responsible design addresses prompt injection, privacy, bias, accessibility, human oversight and lifecycle accountability. PWAs support installation and offline operation; WebAssembly enables portable high-performance modules; edge and on-device inference can improve latency and privacy. WebXR introduces spatial interaction and new safety requirements, while decentralized technologies can provide verifiability but also create permanence, key-management and governance challenges.

The central professional lesson is that AI capability must be matched with evidence, controls, usability and responsibility. Emerging standards should be adopted through progressive enhancement, interoperability and risk-proportionate evaluation.

Key Terms

Embedding: A numerical representation of an item used for similarity or downstream ML tasks.

Vector database: A system that stores vectors and supports similarity search with metadata filtering.

Cosine similarity: A measure of the angle-based similarity between two non-zero vectors.

Retrieval-augmented generation: Generation that uses retrieved external evidence as model context.

Reranking: Reordering retrieved candidates with a more precise scoring model.

Streaming inference: Delivery of partial model output while processing continues.

Server-Sent Events: A browser-compatible mechanism for one-way server-to-client event streams.

Prompt injection: An attempt to manipulate model instructions through user or retrieved content.

Model UX: Interface design that communicates AI capabilities, uncertainty, evidence and control.

Calibration: The relationship between a system’s confidence indications and actual correctness.

Bias: Systematic distortion that can produce unequal or inaccurate outcomes.

Governance: Policies, roles, controls and processes that manage a system throughout its lifecycle.

Progressive web application: A web application enhanced with installation, offline and app-like capabilities.

Service worker: A browser worker that can intercept network requests and support caching or background tasks.

WebAssembly: A portable binary instruction format for execution in web and other runtimes.

Edge computing: Processing performed near users or data sources rather than only in a central cloud.

WebXR: Web APIs for virtual- and augmented-reality experiences.

Verifiable credential: A digitally signed claim that can be checked for integrity and issuer provenance.

Progressive enhancement: Designing a baseline experience that gains capabilities when supported.

Human-in-the-loop: A design in which people review, approve, correct or override system outputs.

Review Questions

Short Answer Questions

1. Why should production browser code generally not contain an AI provider’s secret API key?

2. What is the purpose of metadata filtering in vector retrieval?

3. How does streaming inference affect user experience?

4. State two risks associated with decentralized technologies.

5. Why is similarity in embedding space not equivalent to factual correctness?

Long Answer Questions

1. Explain the architecture and lifecycle of a retrieval-augmented web application, including ingestion, retrieval, generation and evaluation.

2. Compare synchronous, asynchronous and streaming inference, and recommend a suitable mode for three different web applications.

3. Discuss how model UX can communicate uncertainty while preserving usability and accessibility.

4. Explain how privacy, bias, prompt injection and governance should influence the design of an AI-enabled application.

5. Compare PWAs, WebAssembly and edge computing in terms of capability, performance, constraints and appropriate use cases.

Analytical / Application Questions

1. Design a secure architecture for a university assistant that answers questions from documents with different access levels. Identify the data flow, controls and evaluation measures.

2. A company wants to run a large generative model entirely in the browser to protect privacy. Analyze the benefits, technical constraints and circumstances in which a hybrid design would be preferable.

3. An AI assistant produces fluent answers supported by outdated documents. Diagnose the likely retrieval and governance failures and propose a corrective plan.

Multiple Choice Questions with Answers

Question 1

Which architecture best protects a third-party AI API key in a browser application?

A. Place the key in client-side JavaScript and obfuscate it

B. Store the key in browser local storage

C. Route requests through an authenticated server-side service

D. Encode the key in the HTML manifest

Correct Answer: C. Route requests through an authenticated server-side service

Question 2

What does cosine similarity primarily compare?

A. The monetary cost of two model calls

B. The directional similarity of two non-zero vectors

C. The number of tokens in two documents

D. The network latency between two servers

Correct Answer: B. The directional similarity of two non-zero vectors

Question 3

Which statement about retrieval-augmented generation is correct?

A. Retrieval guarantees that generated answers are true

B. Authorization should be applied after generation

C. Retrieved evidence can ground generation but must still be evaluated

D. RAG eliminates the need for source documents

Correct Answer: C. Retrieved evidence can ground generation but must still be evaluated

Question 4

Which technology is designed for one-way server-to-browser event streaming?

A. Server-Sent Events

B. DNS

C. Web Storage

D. CSS Grid

Correct Answer: A. Server-Sent Events

Question 5

Why is prompt injection especially relevant to RAG systems?

A. Retrieved content may contain instructions that attempt to override intended behavior

B. Embeddings always expose encryption keys

C. Vector indexes cannot store metadata

D. Streaming prevents server authentication

Correct Answer: A. Retrieved content may contain instructions that attempt to override intended behavior

Question 6

Which practice is most appropriate for a high-impact AI decision?

A. Automatically execute every model recommendation

B. Remove all user correction mechanisms

C. Use human oversight, documentation and impact evaluation

D. Hide the model’s limitations from users

Correct Answer: C. Use human oversight, documentation and impact evaluation

Question 7

What is a service worker commonly used for in a PWA?

A. Compiling database queries on a remote server

B. Intercepting requests and supporting caching

C. Replacing all authentication mechanisms

D. Guaranteeing that offline transactions succeeded

Correct Answer: B. Intercepting requests and supporting caching

Question 8

Which is a realistic benefit of edge or on-device inference?

A. It always provides greater model accuracy

B. It can reduce latency or exposure of raw data

C. It removes the need for model updates

D. It guarantees compatibility with every device

Correct Answer: B. It can reduce latency or exposure of raw data

Question 9

What is a key limitation of WebAssembly?

A. It cannot execute any computational code

B. It automatically makes unsafe source code memory-safe

C. Large modules can impose download, memory and battery costs

D. It is limited to server-side HTML rendering

Correct Answer: C. Large modules can impose download, memory and battery costs

Question 10

Which design principle is an example of progressive enhancement?

A. Make the application unusable without the newest browser API

B. Provide a functional baseline and add advanced capabilities when supported

C. Require a specialized headset for all users

D. Disable accessibility features to reduce latency

Correct Answer: B. Provide a functional baseline and add advanced capabilities when supported

Web Technologies
Chapter 14 of 14