Chunk local text, create embeddings, and export a portable RAG index without a vector database.
Use this when a small docs or knowledge-base prototype needs its text turned into embeddings held in React state and saved as a portable index.
Similar patterns, and when each one is the better fit.

Local RAG ChatUse this when you already have an exported embedding index of text chunks and want users to chat over it with cited, streamed answers.
Local Image IngestUse this when teaching or prototyping caption-then-embed for images and you want a downloadable index file as the result.
Local Image SearchUse this when you already have an exported image index and need to search it by meaning in the browser using caption embeddings.
Chunk strategy compareUse this when you are tuning chunking as a retrieval setting and want to compare three strategies side by side with cosine similarity scores.Requirements, wiring steps, and what this pattern adds to your project.
Pick how you want to pull this pattern in. Then wire env vars and routes the same way.
Download → Next.js app
Use Download → Next.js app in the preview toolbar. You get a zip scaffold (Pro downloads rewrite preview `/view/.../api/*` paths to `/api/*` automatically).
Extract the zip and install dependencies
Unzip the archive, then run `pnpm install` (or npm / yarn) in the project folder.
Fill .env.local
The download includes .env.local placeholders when needed. Add real values for: AI_GATEWAY_API_KEY.
Customize the agent and tool files
Adapt prompts, tools, and stop conditions in the generated project for your product.
Run the app and open the pattern route
Run `pnpm dev`, open the setup/checklist page if present, then navigate to the generated pattern route and verify responses.
AI_GATEWAY_API_KEYGet keyAI SDK APIs
embedManyExternal services
app/page.tsxapp/layout.tsxapp/api/embed/route.tscomponents/local-rag-ingest.tsxcomponents/source-input.tsxcomponents/index-summary.tsxhooks/use-local-rag-ingest.tslib/chunk-text.tslib/embedding-config.tslib/ingest-state.tslib/local-rag-index.tslib/rate-limit.tslib/request-utils.tsREADME.mdnpm packages
6
Registry components
lib/local-rag-index.tsV1 portable embedding-index contract (schema, Zod validation, invariants, export constructor). Future Local RAG Chat must reuse this module as the compatibility seam—reject incompatible schema/version/model/dimensions/chunking before cosineSimilarity.
lib/chunk-text.tsBrowser-side UTF-8 decode, unicode-nfc-lf normalization, SHA-256 hashing, and paragraph-window-v1 deterministic chunking. Keep pure and unit-tested; do not move chunking to the server.
embed/route.tsStateless embedMany boundary via AI SDK Core from 'ai' with Gateway model string openai/text-embedding-3-small, providerOptions.openai.dimensions=512, abort/timeout, disabled telemetry, and no document/vector persistence. Never add @ai-sdk/openai solely for embeddings.
Chunk local text, create embeddings, and export a portable RAG index without a vector database.
Use this when a small docs or knowledge-base prototype needs its text turned into embeddings held in React state and saved as a portable index.
Similar patterns, and when each one is the better fit.

Local RAG ChatUse this when you already have an exported embedding index of text chunks and want users to chat over it with cited, streamed answers.
Local Image IngestUse this when teaching or prototyping caption-then-embed for images and you want a downloadable index file as the result.
Local Image SearchUse this when you already have an exported image index and need to search it by meaning in the browser using caption embeddings.
Chunk strategy compareUse this when you are tuning chunking as a retrieval setting and want to compare three strategies side by side with cosine similarity scores.Requirements, wiring steps, and what this pattern adds to your project.
Pick how you want to pull this pattern in. Then wire env vars and routes the same way.
Download → Next.js app
Use Download → Next.js app in the preview toolbar. You get a zip scaffold (Pro downloads rewrite preview `/view/.../api/*` paths to `/api/*` automatically).
Extract the zip and install dependencies
Unzip the archive, then run `pnpm install` (or npm / yarn) in the project folder.
Fill .env.local
The download includes .env.local placeholders when needed. Add real values for: AI_GATEWAY_API_KEY.
Customize the agent and tool files
Adapt prompts, tools, and stop conditions in the generated project for your product.
Run the app and open the pattern route
Run `pnpm dev`, open the setup/checklist page if present, then navigate to the generated pattern route and verify responses.
AI_GATEWAY_API_KEYGet keyAI SDK APIs
embedManyExternal services
app/page.tsxapp/layout.tsxapp/api/embed/route.tscomponents/local-rag-ingest.tsxcomponents/source-input.tsxcomponents/index-summary.tsxhooks/use-local-rag-ingest.tslib/chunk-text.tslib/embedding-config.tslib/ingest-state.tslib/local-rag-index.tslib/rate-limit.tslib/request-utils.tsREADME.mdnpm packages
6
Registry components
lib/local-rag-index.tsV1 portable embedding-index contract (schema, Zod validation, invariants, export constructor). Future Local RAG Chat must reuse this module as the compatibility seam—reject incompatible schema/version/model/dimensions/chunking before cosineSimilarity.
lib/chunk-text.tsBrowser-side UTF-8 decode, unicode-nfc-lf normalization, SHA-256 hashing, and paragraph-window-v1 deterministic chunking. Keep pure and unit-tested; do not move chunking to the server.
embed/route.tsStateless embedMany boundary via AI SDK Core from 'ai' with Gateway model string openai/text-embedding-3-small, providerOptions.openai.dimensions=512, abort/timeout, disabled telemetry, and no document/vector persistence. Never add @ai-sdk/openai solely for embeddings.
Loading preview…
Early-bird pricing — limited time


Open on desktop for the interactive preview.
Chunk local text, create embeddings, and export a portable RAG index without a vector database.
Loading preview…
Early-bird pricing — limited time


Open on desktop for the interactive preview.
Chunk local text, create embeddings, and export a portable RAG index without a vector database.