Skip to content

timurgaleev/memex

Repository files navigation

memex

Long-term memory for your AI agent — that never leaves your cloud.

Self-hosted on your own AWS. memex indexes your notes and code and lets any MCP agent (Claude Code, Cursor, Codex) search it and cite the source. No SaaS, no telemetry — your second brain stays yours.

License: MIT MCP-native Self-hosted Built with Bun

memex turns your notes and code into a searchable brain that your AI agent reaches over MCP

What is memex?

You write a lot — notes, decisions, docs, code. Six months later you can't find any of it, and your AI assistant has no idea it exists.

memex is a personal knowledge brain you run in your own cloud. It reads your markdown notes and your code, turns them into a searchable index, and hands that search to your AI agent over the Model Context Protocol (MCP). Now your agent answers "what did I decide about X?" with your own words, cited back to the exact note — instead of guessing.

It's a second brain for you, and long-term memory for your AI.

See it work

Your agent asks 'what did I decide about the auth approach', memex.search returns 3 cited chunks from your own notes (decisions/auth-approach.md:12, notes/mcp-security.md:31), and the agent answers: you chose a bearer token over MCP, not OAuth.

memex returns the evidence, cited to the exact file. Your agent writes the answer. (The brain retrieves — it doesn't chat.)

Why it exists

  • Your knowledge is private. Most "AI memory" tools upload everything to someone else's servers. memex runs entirely inside one AWS account you control — your notes never leave your cloud, and there's zero telemetry.
  • One brain, every agent. It exposes a single MCP endpoint. Any MCP-compatible tool connects to it; you don't re-index your life per app.
  • Search that actually finds things. It blends meaning (vector embeddings), exact words (keyword search), and relationships (an entity graph) — so the thing you only half-remember still surfaces.
  • Understands your code too. It indexes your source (TypeScript, Python) and can answer "who calls this function / what does it call" from a real call graph — not just your prose.
  • Surfaces notes before you ask. Hand it a conversation and it volunteers the pages most likely relevant — deterministic, no AI guessing.
  • Small and boring on purpose. No orchestrator, no SaaS to depend on. It fits on one small EC2 box, and you can read the whole thing in an afternoon. Multi-source tenant isolation is built in (each source scoped, opt-in fail-closed) so one box can serve more than one person — see docs/tenancy.md.

How it's different

memex Hosted "AI memory" A plain RAG script
Your data stays in your cloud
Any MCP agent, one shared index sometimes
Vector + keyword + entity-graph varies vector-only
Understands code (real call graph), not just notes
Zero telemetry, no SaaS dependency

Who it's for: developers who live in Claude Code / Cursor / Codex, note-takers with a markdown vault, and anyone who refuses to put their second brain on someone else's servers.


How it works

memex indexes your content once, then answers searches on demand. When your agent asks a question, here's the round trip — note that memex hands back evidence, and the agent composes the answer:

sequenceDiagram
    autonumber
    actor You
    participant Agent as Your AI agent
    participant memex as memex (MCP)
    participant DB as Postgres + pgvector
    You->>Agent: "What did I decide about X?"
    Agent->>memex: tools/call search { q }
    memex->>DB: vector + keyword + graph query
    DB-->>memex: top chunks, ranked (RRF)
    memex-->>Agent: cited chunks (evidence, not an answer)
    Agent-->>You: answer, grounded in your own notes
Loading

Under the hood: a small Bun + TypeScript service, Postgres 16 with pgvector, AWS Bedrock for embeddings, and a Cloudflare Tunnel for HTTPS — so no EC2 port is ever exposed. The entire public surface is two routes: GET /health and POST /mcp. That's the whole attack surface.

Full topology, every container, and the security model: ARCHITECTURE.md.


Quickstart

You'll need an AWS account, Terraform 1.6+, docker compose v2, and a domain you control (for the Cloudflare Tunnel).

git clone https://github.com/<your-org>/memex.git
cd memex

make init     # interactive bootstrap: AWS account, domain, buckets -> .env + tfvars
make audit    # PII / secrets gate (must pass on a clean clone)
make plan     # preview the AWS resources
make apply    # create them

make apply boots one EC2 host, pulls the repo, fetches secrets from AWS Secrets Manager, and starts the two containers (memex + cloudflared). Your brain is then live at https://brain.<your-domain>/mcp.

Connecting Claude Code (or any MCP client): deploy/memex/docs/CLAUDE-CODE.md.


What's in the box

Piece What it does
memex The brain: hybrid search, entity + code call graph, code/markdown indexers, MCP server, a built-in advisor that ranks what to fix, push-context that volunteers relevant pages, an opt-in (off-by-default) step that distils notes into concepts/opinions in a separate store (your original notes are never touched) with a take-review lifecycle (list_takes / takes_search / set_take_status), and a self-maintaining background cycle. 63 MCP tools.
cloudflared Public HTTPS ingress via Cloudflare Tunnel — no open EC2 ports.
Terraform All AWS infra (VPC, EC2, RDS, EFS, Secrets Manager) as one module.
AWS Bedrock Titan v2 embeddings + Claude Haiku for query intent and the optional, off-by-default note synthesis (Claude Sonnet for the paid opt-in deep-reasoning slices). Your agent still writes the answers.

Learn more: How it works · ARCHITECTURE.md · Deployment · Configuration · Tenancy · API / MCP tools · Operations · Privacy · Changelog


Like the idea?

If a private, self-hosted brain for your AI agent is something you want to exist, give it a ⭐ — it's the signal that keeps this maintained. Bugs and ideas welcome in issues.

Contributing

memex is intentionally small — one box, multi-source tenant isolation, no SaaS — so open an issue before anything that adds infrastructure or changes the deploy story. Please read CLAUDE.md (the repo's working rules) first.

Security

Found a vulnerability? Please don't open a public issue — see SECURITY.md for the private disclosure channel.

License

MIT. Fork it, redeploy it, modify it, ship it. Solo-maintained, no SLA — if you need guarantees, fork and pin.

About

Self-hosted personal AI knowledge brain -- hybrid (vector + keyword + entity-graph) search over your notes and code, served to any MCP agent (Claude Code, Cursor, Codex). One AWS account, zero telemetry, MIT.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors