Skip to main content
Ram.Franco LogoRam.Franco
Dual Stage RAG Assistant: Semantic Cache Over a Live Knowledge Base

Case Study

Dual Stage RAG Assistant: Semantic Cache Over a Live Knowledge Base

A RAG chat assistant that checks a semantic cache before ever calling an LLM, falling back to a Gemini agent with vector retrieval only on a cache miss.

Automation Architect (n8n) · Independent Practice
Live

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

Dual Stage RAG Assistant: Semantic Cache Over a Live Knowledge Base

Stack

n8nGoogle DriveOllamaPineconeGeminiRAGSemantic Caching

Project Links

Download Workflow (.json)

More case studies

Activate to toggle technology brand colors.

Limited Availability

Ready to Build Something Extraordinary?

Whether you have a fully defined project scope or just a high level vision, let's discuss how we can bring it to life with production grade engineering.

Available for new projects