惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
博客园 - 【当耐特】
B
Blog
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园 - 司徒正美
博客园 - 叶小钗
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I built persistent AI memory for Claude on Cloudflare's f...
Rahil Pirani · 2026-05-20 · via DEV Community
Cover image for I built persistent AI memory for Claude on Cloudflare's free tier

Rahil Pirani

Every Claude session starts fresh. You copy context, explain your setup, reintroduce your project, and then do it all over again the next day. I got tired of this and created a solution.

second-brain-cloudflare is a self-hosted MCP server that provides Claude, ChatGPT, Cursor, and any MCP-compatible client with persistent memory across sessions. It operates entirely on Cloudflare's free tier. Here’s how it works.

The stack

  • Cloudflare Workers: MCP server, REST API, and web UI, all from one wrangler deploy
  • D1 (SQLite): stores entry content, tags, source, timestamps, and vector chunk IDs
  • Vectorize: the vector index (bge-small-en-v1.5, 384 dimensions)
  • Workers AI: bge-small-en-v1.5 for embeddings, @cf/meta/llama-4-scout-17b-16e-instruct for web UI synthesis

One deployment. No external databases. No API keys needed beyond your Cloudflare account token.

Tag-based time-decay reranking

Pure vector similarity has a drawback. A memory from three months ago can outrank something you saved yesterday if it’s semantically closer. The solution is to fetch three times more candidates than needed (topK=5 pulls 15), then score each using a tag-aware half-life:

  • Tasks: 7-day half-life
  • Work: 3-month half-life
  • Context: 6-month half-life
  • Default: 30-day half-life

adjusted_score = cosine_similarity × e^(-age_in_days / half_life)

Duplicate detection

Before storing anything, embed the incoming content and query Vectorize for its nearest neighbor:

  • Score ≥ 95%: block
  • Score 85–94%: store with duplicate-candidate tag
  • Score < 85%: store normally

Without this step, Claude creates 20–30 nearly identical entries for the same decision.

Smart chunking

Long notes split at sentence ends, with a 200-character overlap. Each chunk receives its own vector. Chunk IDs are stored in D1, so forget() reliably removes all related vectors.

Temporal recall (v1.2.0)

Queries now support time limits:

  • recall("API decisions", after="7 days ago")
  • recall("standup notes", after="2026-05-12") Supports: "today", "yesterday", "last week", "this month", ISO dates, and epoch timestamps.

AI synthesis in the web UI

Queries flow through @cf/meta/llama-4-scout-17b-16e-instruct before being rendered. Answers stream in real time, with source memories that can be collapsed underneath. You’ll find Append and Forget buttons. This runs on your own Cloudflare account.

Why the free tier works

  • D1: 5GB storage, 5 million row reads per day
  • Vectorize: 5 million vectors, 30 million queried dimensions per month (adequate for team scale but fine for personal use)
  • Workers AI: 10,000 Neurons per day

Try it

Deploy: https://thesecondbrain.dev
GitHub: https://github.com/rahilp/second-brain-cloudflare

If this was helpful, please give it a star.