Video summary
How To Build A Production Ready RAG AI - My Full AI Coding Workflow
Main summary
Key takeaways
Overview
This video is a complete, production-focused build walkthrough for a production-ready RAG (Retrieval-Augmented Generation) search system. The system ingests the creator’s own content and lets users search it, returning the most relevant topics with a link to the exact location in the source articles/videos.
What the System Does (Product Behavior)
Ingests
- Blog articles from an RSS feed
- YouTube videos using the YouTube Data API plus subtitles/captions
Indexing Strategy for Retrieval
- Content is chunked:
- Blog content is chunked based on its HTML structure
- YouTube content is chunked using caption timing/segments
- Each chunk is embedded and stored in a vector database for similarity search
User Search Flow
- Users log in (GitHub auth).
- The search query is embedded.
- The system performs a vector similarity query.
- It returns high-relevance matches only using a threshold.
- Instead of returning raw chunks, it returns content pages:
- Articles: highlights matched text
- Videos: generates a URL with a start time parameter to jump to the relevant moment
Production Pipeline
- Uses dev/prod separation via environment variables.
- Runs database migrations during deploy to keep the DB schema consistent with the app code.
Tools and Infrastructure Used
- Neon: Postgres database with branching support
- Used for dev/prod DB URLs and vector storage
- Vercel Workflows: Durable long-running/queued ingestion tasks
- Includes retries, batching, and long waits
- CodeRabbit: Code reviews for security and correctness
- Includes automatic suggestions/fixes
- Next.js: App UI + server actions/routes
- Better Auth: Authentication system
- GitHub OAuth via Better Auth
- Drizzle ORM (including Drizzle 1.0 RC)
- Typed schema + migrations
- pgvector extension (
vectortype)- Required to store embeddings and run vector similarity queries
- Embedding models:
- Local development: LM Studio + local embedding model (e.g., Quen / 1024 dims)
- Production: OpenAI embeddings (1536 dims)
- Requires a separate migration/schema change for dimensions
Production Safety / Engineering Practices Emphasized
- Start from an existing repo and scaffold normally (don’t ask AI to generate the entire project immediately).
- Deploy incrementally to catch issues early.
- Enforce branch protection:
- Block direct pushes to
main - Require PRs for merging
- Block direct pushes to
- Use AI for code generation, but always manually review:
- CodeRabbit is used heavily, but AI-generated code is still reviewed cautiously
- Secure long-running workflow endpoints:
- Added a cron secret check (must match an env var; rejects unauthorized callers)
Ingestion Workflows (Core RAG Indexing)
1) Blog Ingestion Workflow (RSS-based)
- Fetch RSS feed, parse items, and compute which articles are not already ingested
- Filter based on existing URLs in the DB
- Process each new article in batches of 10:
- Fetch HTML
- Extract:
- thumbnail image (OG image)
- text content from the main article section
- Chunking strategy:
- Initially described as chunking by H2 headings (hierarchical context chunks)
- Later simplified/refactored with extensive testing
- Store chunk records and related content records
Testing
- Added chunking unit tests using Vitest (via vest)
- Added “real world” HTML test cases
2) YouTube Ingestion Workflow (API + Captions)
- Uses YouTube Data API v3:
- Gets the channel’s uploads playlist
- Retrieves playlist items with pagination
- Filters for public videos
- Fetches captions/subtitles:
- Uses OAuth scopes for captions (with redirect/refresh token setup)
- Parses subtitles into timed segments
- Chunking strategy for videos:
- Uses caption text segments with overlap
- Stores chunk start position to build accurate timestamps later
- Batching and quotas:
- Processes in batches of 10
- Includes a very long delay (9 hours) between batches to avoid quota limits
Search Implementation (Query-time Retrieval)
- The search page uses a server action that:
- Embeds the user query
- Queries vector similarity from pgvector
- Joins chunks → content (returns content results)
- Applies a relevance threshold (e.g.,
> 0.5) - Returns up to 20 results (after ranking, not before)
- Retrieval quality improvements:
- Corrected cosine similarity expression usage
- Added missing vector search index support
- Cleaned ordering/dedup logic:
distincton content ID- then sort by similarity
Rate Limiting (Production Cost Control)
- Added a rate limit system to the search action:
- Limits number of searches per user per time window
- Stores search history (user id, query, createdAt, results/content ids)
- Frontend behavior:
- UI displays a “rate limit exceeded” message when triggered
- Code adjustments:
- Fixed error handling so rate limit errors propagate properly and don’t crash UI logic
Code Quality & Review Outcomes (What CodeRabbit Caught)
Security/Privacy
- Pass secrets explicitly instead of relying on env fallback names
- Enforce minimum secret length (Better Auth requirements)
Correctness
- Fix schema/adapter compatibility (Better Auth + Drizzle v1 RC)
- Enforce authentication at the server action layer (not only by hiding UI)
Query Correctness
- Fix similarity ranking and result limiting order
Main Speakers/Sources
- Kyle — “WebDev Simplified” (primary narrator/instructor)
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.