Built Document Memory For RAG Agent (Doesn't Reprocess Same Documents) 🔥
RAG system reprocessing 200 documents on every query. Wasting credits and time. Added document memory - checks hash, skips if already embedded. 85% cache hit rate, 70% cost reduction.
THE PROBLEM:
Every RAG query reprocessed all 200 documents - parsing, chunking, embedding, storing. Even documents processed yesterday. Massive waste.
Monthly cost: $180 in processing
Query latency: 12 seconds
THE SOLUTION:
Document memory layer. Hash-based deduplication. Process new documents only.
THE MEMORY SYSTEM:
DOCUMENT HASH TABLE:
Google Sheets: document_name, file_hash, processed_date, chunk_count, vector_ids
HASH CHECKER:
Before processing: Calculate file hash → Check if exists in hash table → Skip if match found → Process only if new or changed
SMART PROCESSING:
New document → Full processing → Add to hash table
Existing document (same hash) → Retrieve stored vector IDs → Skip processing
Changed document (different hash) → Delete old vectors → Reprocess → Update hash table
THE COMPLETE FLOW:
Document Upload → Calculate Hash → Check Memory → IF new: Process & Store → IF exists: Skip → RAG Query uses all vectors
MEMORY CHECK LOGIC:
Calculate SHA-256 hash of document
Query hash table for matching hash
IF match found AND processed_date < 30 days ago → Use cached vectors
IF no match OR old → Process fresh
THE NUMBERS:
200 documents in system:
- Truly new documents per week: 8 (4%)
- Updated documents per week: 22 (11%)
- Unchanged documents: 170 (85%)
Processing stats:
- Documents processed per query: 30 (was 200)
- Cache hit rate: 85%
- Processing cost: $54 monthly (was $180)
- Query latency: 3 seconds (was 12 seconds)
SAVINGS:
Monthly cost reduction: $126 (70%)
Time savings: 9 seconds per query
System responsiveness: 4X faster
CONFIGURATION:
Hash Calculator: Code node with SHA-256
Memory Table: Google Sheets with indexed column
Vector ID Tracking: Qdrant metadata includes document_hash
CACHE INVALIDATION:
Documents older than 30 days → Reprocess (ensures freshness)
Manual cache clear: Bulk delete vector IDs by document_hash
Selective refresh: Reprocess specific documents on demand
THE PATTERN:
RAG systems should track processed documents. Hash-based deduplication prevents unnecessary reprocessing. Memory layer saves cost and time.
BEFORE vs AFTER:
Before: Reprocess everything every time. Slow. Expensive. Wasteful.
After: Process once. Cache results. Reuse vectors. Fast. Efficient. Economical.
TEMPLATE:
RAG with document memory. Hash calculation, memory table, cache logic, invalidation patterns.
Templates: n8n | Zapier | Make
Are your RAG systems reprocessing documents unnecessarily?
9
4 comments
Duy Bui
7
Built Document Memory For RAG Agent (Doesn't Reprocess Same Documents) 🔥
AI Automation Society
skool.com/ai-automation-society
A community built to master no-code AI automations. Join to learn, discuss, and build the systems that will shape the future of work.
Leaderboard (30-day)
Powered by