Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

Β 

History

53 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MemoryMesh

A shared, distributed memory layer for AI agents, backed by CockroachDB, deployable on AWS.

The idea in one paragraph

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.


🧠 MemoryMesh

Persistent AI memory powered by CockroachDB + Amazon S3

Demo

Watch MemoryMesh Demo

▢️ Click the image above to watch the full demo on YouTube.

🌐 Live Demo

▢️ Try MemoryMesh Live

The demo shows:

  • AI agent interaction
  • Persistent memory with CockroachDB
  • Amazon S3 integration
  • Memory storage and retrieval
  • FastAPI backend workflow

πŸ—οΈ Architecture

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:

  1. Distributed Vector Indexing β€” the memories table's embedding column + memories_embedding_idx, queried with the <-> operator.
  2. 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.


1. Set up CockroachDB Cloud (free tier works)

  1. Go to https://cockroachlabs.cloud/ and create a free Serverless cluster.
  2. In the console, click Connect, copy the connection string.
  3. Run the schema against it (easiest: paste the contents of db/schema.sql into the SQL Shell in the CockroachDB Cloud console).

2. Configure environment variables

cp .env.example .env

Edit .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.

3. Install dependencies

python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt

4. Run the demo

python demo.py

Agent 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.

5. Run the live API (for your "demo app URL")

 python -m uvicorn app.main:app --reload --port 8000

Visit http://localhost:8000/docs, or:

curl -X POST http://localhost:8000/demo/run
curl http://localhost:8000/stats

6. Enable real Bedrock embeddings (optional, recommended for submission)

  1. In AWS Console, enable model access for Titan Embeddings in Bedrock.
  2. In .env, set:
    USE_BEDROCK=true
    AWS_ACCESS_KEY_ID=...
    AWS_SECRET_ACCESS_KEY=...
    AWS_REGION=us-east-1
    
  3. Re-run python demo.py.

7. Deploy to AWS Lambda

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.

Using the CockroachDB MCP Server (dev-time tool)

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.


Troubleshooting

"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 utf8

Agent 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.


Project structure

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

Conclusion

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.

Future Scope

  • πŸ”Ή 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.

About

MemoryMesh gives every agent one shared memory

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages