The Problem
A single stage RAG chatbot reruns embedding + retrieval + generation on every question, even ones it's effectively already answered. That's slower and more expensive than it needs to be for the long tail of repeated or near duplicate questions any internal knowledge assistant actually gets.
Architecture
Ingestion: Google Drive Trigger/Manual → PDF/Text Extraction → Chunking → Ollama Embeddings → Pinecone Knowledge Base Index
Query: Chat Trigger → Ollama Query Embedding → Pinecone Semantic Cache Lookup → [score ≥ 0.88: return cached answer] / [cache miss: Gemini Agent + Pinecone Retrieval Tool + Memory → answer → write back to cache]
What It Does
Two independent Pinecone indexes, one job each: a knowledge base index (768 dim, cosine, nomic-embed-text) holds the source documents; a separate semantic cache index holds prior query/answer pairs, so cache lookups don't compete with retrieval quality.
Cache first response path: every query is embedded and checked against the semantic cache before any LLM call happens; a similarity score of 0.88+ short circuits straight to a cached answer.
Self reinforcing cache: every cache miss answer generated by the Gemini agent gets written back into the semantic cache index, so the same or similar question resolves faster next time without redeploying anything.
Local embeddings via Ollama: both ingestion and query time embeddings run through a local Ollama model rather than a paid embeddings API, which matters at the volume a semantic cache implies.
Engineering Focus
The part worth understanding here isn't the AI agent: it's the cache invalidation free design. There's no explicit expiry or invalidation on cached answers, which is fine for stable reference docs and a real liability the moment the underlying knowledge base changes and a cached answer goes stale silently.
What I'd Harden
Before production I'd add: a cache invalidation hook tied to the ingestion pipeline (a new document upload should at minimum flag related cache entries), a lower similarity floor with human review for scores near the 0.88 boundary, and metrics on cache hit rate so "it's fast" is measured, not assumed.
Gallery



