Skip to content

AI

Low-Latency Go & pgvector RAG Assistant with Semantic Caching

A ~25MB stdlib Go + pgvector RAG service synced daily with Payload CMS, combining exact/semantic FAQ caches, anti-hallucination gates, and multi-provider SSE streaming.

Problem

Recruiters, engineering leaders, and developers visiting a technical portfolio often want direct answers to specific questions ("Has Sifat worked on HIPAA systems?", "How did the 50M-row Postgres migration work?") without hunting across ten pages. Naive wrapper chatbots solve this poorly: they hallucinate unverified claims, suffer multi-second Python cold starts, and waste LLM tokens on off-topic prompts.

Constraints

  • Zero hallucinated credentials: The assistant must answer strictly from published Payload CMS records and curated profile documents, falling back deterministically to showmic96@gmail.com when a fact is not in context.
  • Minimal recurring infrastructure cost: Must run comfortably inside a tiny container alongside existing Neon Serverless PostgreSQL (pgvector) without external vector DB bills.
  • Resilient streaming UX: Single LLM providers experience intermittent rate limits; failover must never emit duplicate partial streams to the browser.

Approach

1. Layered Cost & Latency Funnel in Go

Built apps/bot in Go using only the standard library net/http server and pgx connection pool. Every chat turn passes through a strict pipeline: alias normalization (showmic -> sifat) -> exact SQL match on common_questions / refused_questions -> zero-cost regex rule gate -> text-embedding-3-small vectorization -> negative semantic cache (cosine >= 0.93) -> grounded FAQ semantic cache (cosine >= 0.90) -> top-5 pgvector chunk retrieval (>= 0.38 relevance floor) -> grounded SSE generation.

2. Automated Payload CMS Sync & Self-Cleaning Cache

A daily and boot-time sync job pulls published projects, contents, experiences, and skills from Payload CMS, flattens Lexical AST nodes into clean text chunks, skips unchanged content hashes, and seeds 100 grounded FAQ pairs. Boot migrations automatically purge any refusal-polluted rows from common_questions.

3. Multi-Provider LLM Failover & Stream Hygiene

Implemented an ordered streamer (gemini-3.5-flash-lite direct -> OpenRouter google/gemini-3.5-flash-lite -> OpenRouter deepseek/deepseek-v4.1-flash) that only falls through if an upstream target errors before emitting its first token, paired with a live stream sanitizer that strips [S1] citation artifacts and normalizes punctuation.

Outcomes

  • Sub-50ms responses on exact and high-confidence FAQ cache hits with zero LLM generation cost.
  • ~25 MB idle RAM and sub-80ms container startup on Railway using stdlib Go + pgx.
  • Zero hallucinated portfolio claims enforced via 0.38 similarity gating, untrusted-context system prompts, and 0.45 minimum evidence thresholds before caching answers.

Stack:TypeScriptNext.jsPostgreSQLGo (net/httppgx)pgvectorGemini 3.5 Flash-LiteOpenRouterOpenAI EmbeddingsRailway

Production AI & RAG

Putting a grounded RAG assistant or LLM pipeline in production?

I build low-latency RAG backends in Go and FastAPI with hybrid retrieval, pgvector, and streaming SSE. Email me if you want grounded answers without runaway token costs.

Open to full-time and part-time roles (remote or onsite)

Discuss an AI systemGitHubLinkedIn

Also on Toptal. Email is the best way to start a conversation.