A shared, distributed memory layer for AI agents, backed by CockroachDB, deployable on AWS.
AI agents normally forget everything between runs, and agents built for different purposes never share what they learn. MemoryMesh gives every agent one shared memory: when Agent A solves a problem, it writes what it learned into CockroachDB. When Agent B later hits something similar β even worded completely differently β it searches that shared memory (via CockroachDB's vector index) and gets the answer instantly instead of reasoning from scratch.
Persistent AI memory powered by CockroachDB + Amazon S3
The demo shows:
- AI agent interaction
- Persistent memory with CockroachDB
- Amazon S3 integration
- Memory storage and retrieval
- FastAPI backend workflow
MemoryMesh is designed as a persistent AI memory layer that connects an AI agent with CockroachDB for structured memory and Amazon S3 for cloud-based object storage.
ββββββββββββββββββββββββ
β User / Client β
β Web App / API Call β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β MemoryMesh Agent β
β β
β β’ Understand context β
β β’ Retrieve memory β
β β’ Update memory β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β FastAPI Backend β
β β
β β’ API endpoints β
β β’ Agent orchestrationβ
β β’ Memory operations β
ββββββββββββ¬ββββββββββββ
β
ββββββββββββββ΄βββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββββββ
β CockroachDB β β Amazon S3 β
β β β β
β β’ Persistent β β β’ Object storage β
β memory β β β’ Large artifactsβ
β β’ Metadata β β β’ Cloud files β
β β’ Memory records β β β
ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ
β β
ββββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Persistent Agent β
β Memory β
β β
β Context + Metadata + β
β Cloud Artifacts β
ββββββββββββββββββββββββ
CockroachDB tools used:
- Distributed Vector Indexing β the
memoriestable'sembeddingcolumn +memories_embedding_idx, queried with the<->operator. - CockroachDB Cloud Managed MCP Server β point Claude Code / Cursor at your cluster via MCP during development to inspect memory tables live.
AWS service used: AWS Lambda (serverless execution via
lambda/lambda_handler.py), optionally Amazon Bedrock for real embeddings.
- Go to https://cockroachlabs.cloud/ and create a free Serverless cluster.
- In the console, click Connect, copy the connection string.
- Run the schema against it (easiest: paste the contents of
db/schema.sqlinto the SQL Shell in the CockroachDB Cloud console).
cp .env.example .envEdit .env and paste your real DATABASE_URL (with your actual password).
Use sslmode=require unless you've specifically set up certificate
verification β require still fully encrypts the connection, it just
skips the extra identity-check step, which is fine for development.
Leave USE_BEDROCK=false for now β the app uses a local embedding fallback
so everything works without AWS credentials yet.
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtpython demo.pyAgent A works through an incident and writes a memory, then Agent B finds that memory and solves a differently-worded problem instantly, followed by a time-saved comparison and shared-memory stats. This is the exact script to screen-record for your submission video.
python -m uvicorn app.main:app --reload --port 8000Visit http://localhost:8000/docs, or:
curl -X POST http://localhost:8000/demo/run
curl http://localhost:8000/stats- In AWS Console, enable model access for Titan Embeddings in Bedrock.
- In
.env, set:USE_BEDROCK=true AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... AWS_REGION=us-east-1 - Re-run
python demo.py.
pip install mangum
mkdir -p package
pip install -r requirements.txt -t package/
pip install mangum -t package/
cp -r app package/
cp lambda/lambda_handler.py package/
cd package && zip -r ../memorymesh_lambda.zip . && cd ..In AWS Console: create a Lambda function (Python 3.12), upload the zip,
set handler to lambda_handler.handler, add your env vars, and enable a
Function URL for a public HTTPS endpoint.
CockroachDB Cloud Console β your cluster β Connect β MCP Server tab
gives you a config snippet for Claude Code / Cursor. This lets you inspect
the memories table and audit recalls directly from your coding assistant
β mention this as your second CockroachDB tool in your submission.
"root certificate file does not exist" / SSL errors on Windows:
The simplest fix is using sslmode=require instead of sslmode=verify-full
in your DATABASE_URL β this still encrypts everything, it just skips
certificate identity verification. Fine for hackathon/dev use.
Editing .env and changes don't seem to take effect:
On Windows, Notepad can silently fail to save in some setups. Rewrite the
file directly from PowerShell instead:
@"
DATABASE_URL=postgresql://user:password@host:26257/defaultdb?sslmode=require
AWS_REGION=us-east-1
USE_BEDROCK=false
"@ | Set-Content -Path .env -Encoding utf8Agent B doesn't find Agent A's memory (recall returns nothing):
This was a real bug in earlier versions of this code β memory_store.py
was converting CockroachDB's <-> operator (raw Euclidean/L2 distance)
into a similarity score with the wrong formula (1 - distance), which
badly underestimates similarity. Since embeddings here are unit-normalized,
the correct conversion is similarity = 1 - (distance ** 2) / 2. This is
already fixed in app/memory_store.py β if you see this issue again,
check that formula first.
memorymesh/
βββ app/
β βββ config.py
β βββ embeddings.py # Bedrock + local embedding fallback
β βββ memory_store.py # core remember()/recall() logic
β βββ agent_a_devops.py # Agent A: hits an incident, stores memory
β βββ agent_b_onboarding.py # Agent B: recalls Agent A's memory
β βββ main.py # FastAPI app (live demo API)
βββ db/
β βββ schema.sql
βββ lambda/
β βββ lambda_handler.py
βββ demo.py # end-to-end demo script (record this!)
βββ requirements.txt
βββ .env.example
βββ README.md
MemoryMesh demonstrates how persistent memory can make AI agents more useful, reliable, and context-aware across multiple interactions.
By combining CockroachDB for structured and persistent memory with Amazon S3 for cloud-based artifact storage, MemoryMesh provides a scalable foundation for storing, retrieving, and managing agent context.
The project was built to explore how AI agents can move beyond short-lived conversations and maintain useful long-term context while keeping memory organized and accessible.
- πΉ Smarter memory retrieval and ranking
- πΉ Automatic memory summarization
- πΉ Semantic/vector-based memory search
- πΉ Memory expiration and lifecycle management
- πΉ Multi-agent shared memory
- πΉ Improved observability and memory analytics
MemoryMesh is a step toward building AI agents that can remember, learn from context, and deliver more personalized interactions over time.
