Posted in

Build a Fully Offline AI App with Foundry Local and CAG

Guide to building a fully offline on-device AI app using Context-Augmented Generation (CAG) with Foundry Local. Explains CAG vs RAG trade-offs, JavaScript implementation, runtime model selection, local download and caching, and a minimal stack for privacy-preserving, field-ready inference.

Build a Fully Offline AI App with Foundry Local and Context-Augmented Generation (CAG) is now documented. This guide explains the on-device CAG pattern and Foundry Local runtime for fully offline AI apps.

Main feature/change and impact

The core change is adopting Context-Augmented Generation instead of RAG for small collections. CAG loads full documents into memory at startup and injects relevant content per query. This removes embeddings, vector stores, and retrieval pipelines. The impact is simplified architecture, deterministic grounding of responses, and true offline capability for curated datasets on local machines.

Practical implications

Developers gain a minimal dependency stack and predictable behavior for small knowledge bases. Foundry Local handles model selection, download, caching, and in-process inference. Apps can run without cloud, API keys, or external services once models are cached. Constraints include context window limits and restart-required document updates, so scale and ingestion frequency drive pattern choice.
“There is no retrieval pipeline, no vector database, and no embedding model.”
Closing paragraph: Choose CAG with Foundry Local when document counts are small and offline operation is required. For larger collections or dynamic updates, migrate to RAG or hybrid approaches and evaluate embedding and vector-store trade-offs.

Key points from the article:

  • CAG loads all documents into memory at startup for prompt grounding.
  • CAG is simpler and requires no embeddings or vector database.
  • RAG scales better for thousands of documents with semantic search.
  • Foundry Local auto-selects, downloads, caches, and loads models locally.
  • Sample stack: Node.js/Express, single HTML frontend, two npm dependencies.
  • Related Coverage:

    From the Microsoft Developer Community Blog articles