Building a Local-First AI Memory Layer with Rust, SQLite FTS5, MCP, and Amazon Bedrock

2026-11-30来源 dev.toEnglish

Why AI Coding Sessions Need a Local-First Memory Layer

Modern AI engineering workflows span multiple tools—IDE assistants, CLI coding agents, and cloud-hosted LLM workbenches. Over the past year, my daily architecture and mobile engineering work accumulated more than 500 multi-turn AI sessions across different environments. Every time a new session started, valuable architectural reasoning, debugging traces, and design trade-offs vanished behind fragmented local logs.

Uploading raw personal and engineering chat logs wholesale into a third-party cloud vector store creates two immediate problems: latency/cost bloat and privacy boundaries. A cleaner pattern is a hybrid local-first architecture: keep full-text indexing and privacy-boundary filtering local on disk, and send only compact, redacted context snippets to cloud foundation models on Amazon Bedrock when deep synthesis is required.

Architecture Overview

  1. Local Ingestion & Normalization (Rust)
    • Parses heterogeneous JSONL / SQLite session transcripts into a normalized relational schema (conversations, messages, artifacts).
    • Built in Rust (chat-memory-mcp, open-sourced at https://github.com/leotyndale/chat-memory-mcp and installable via brew install leotyndale/tap/chat-memory-mcp) for millisecond startup time and zero runtime dependencies.
  2. Sub-10ms Hybrid Retrieval (SQLite FTS5)
    • Uses SQLite FTS5 with BM25 ranking so developers can query tens of thousands of historical engineering turns locally with zero token spend and zero network round trips.
  3. IDE & Agent Integration (Model Context Protocol + JetBrains Plugin)
    • Exposes structured tools (search_sessions, get_session_summary, retrieve_decision_trace) over stdio MCP so any MCP-compatible coding agent or IDE plugin (chat-memory-jetbrains, JetBrains Marketplace ID 36557) can query historical decisions on demand.
  4. Cloud Synthesis Layer (Amazon Bedrock + Guardrails)
    • Only after local FTS5 narrows 15,000+ steps down to the top 5–8 relevant, PII-scrubbed excerpts does the workflow invoke Amazon Bedrock (e.g., Claude / Nova models via AWS SDK for Rust aws-sdk-bedrockruntime) with Amazon Bedrock Guardrails enabled to enforce sensitive-information redaction and structured JSON output.

Key Engineering Trade-Offs

  • Zero-Token Pre-Filtering: Filtering 99% of irrelevant history locally with SQLite FTS5 reduces downstream cloud prompt tokens by an order of magnitude and keeps prompt-cache hit rates high.
  • Deterministic Privacy Gates: A pre-flight regex and allowlist filter strips credentials, local filesystem usernames, and internal identifiers before any payload leaves the developer workstation for Bedrock.
  • Cross-IDE Portability: Decoupling the core engine as a standalone Rust MCP binary lets the same local index serve JetBrains IDEs, VS Code, and CLI agents simultaneously.

Try It Yourself

brew install leotyndale/tap/chat-memory-mcp 

Source code and architecture docs are open-sourced at https://github.com/leotyndale/chat-memory-mcp. Feedback, benchmarks, and AWS Bedrock integration PRs are warmly welcome!

原文:https://www.a8q9.cn/en/article/building-a-local-first-ai-memory-layer-with-rust-sqlite-fts5-mcp-and-amazon-bedr-b71591.html

相关文章