Skip to main content

Universal long-term memory for any LLM application

Project description

MemoryWeave

Universal long-term memory for any LLM application.

CI Python License: MIT Version


LLMs are stateless. Every conversation starts from zero. MemoryWeave fixes that.

Plug into any LLM app with 3 lines of code. It automatically extracts entities and facts from conversations, builds a personal knowledge graph, and surfaces the most relevant context on every prompt — across sessions, users, and models.

import memoryweave

memory = memoryweave.MemoryWeave()
memory.add("My name is Ravi and I prefer Python over JavaScript.")
ctx = memory.get("What language does the user prefer?")
# inject ctx.summary into your LLM system prompt
print(ctx.summary)
# → Relevant memories:
# → - My name is Ravi and I prefer Python over JavaScript. (relevance: 0.94)

Features

  • Model-agnostic — works with OpenAI, Anthropic, Gemini, Ollama, and any LLM
  • Dual retrieval — combines semantic vector search with a structured knowledge graph
  • Zero config — works out of the box with in-memory storage; swap to ChromaDB in one line
  • Multi-session — isolated per-user memory with session_id
  • REST API — FastAPI server so any language can use it
  • TypeScript SDK — native JS/TS client for the REST API
  • Fully offline — no API keys needed; runs on CPU with local models

Installation

pip install memoryweave

Optional extras:

pip install memoryweave[server]    # FastAPI REST server

Download the NLP model on first use:

python -m spacy download en_core_web_sm

Quick start

Python

from memoryweave import MemoryWeave, MemoryConfig

# in-memory store (default) — great for development
memory = MemoryWeave()

# add memories
memory.add("My name is Ravi Kashyap.")
memory.add("I work at a startup building AI tools in India.")
memory.add("I prefer Python and FastAPI for backend development.")

# retrieve relevant context
ctx = memory.get("What does this person do for work?")
print(ctx.summary)

# check stats
print(memory.stats())
# → {'session_id': 'default', 'vector_count': 3, 'node_count': 4, 'edge_count': 2}

With ChromaDB persistence

from memoryweave import MemoryWeave, MemoryConfig

memory = MemoryWeave(MemoryConfig(
    store_type="chroma",
    store_path="./my_memory_db",
    default_session_id="user-ravi",
))

memory.add("Ravi prefers dark mode and mechanical keyboards.")
ctx = memory.get("What are this user's preferences?")

With the REST API (any language)

Start the server:

uvicorn memoryweave.server:app --reload

Then from TypeScript/JavaScript:

import { MemoryWeave } from "@memoryweave/sdk";

const memory = new MemoryWeave({ sessionId: "user-123" });
await memory.add("My name is Ravi and I prefer Python.");
const ctx = await memory.get("What language does the user prefer?");
console.log(ctx.summary);

Or with plain curl:

curl -X POST http://localhost:8000/memory/add \
  -H "Content-Type: application/json" \
  -d '{"text": "Ravi prefers Python.", "session_id": "demo"}'

curl -X POST http://localhost:8000/memory/get \
  -H "Content-Type: application/json" \
  -d '{"query": "What language?", "session_id": "demo"}'

How it works

memory.add(text)
  │
  ├─ Extractor (spaCy)         → entities + facts
  ├─ Embedder (sentence-transformers) → 384-dim vector
  ├─ BaseStore (InMemory/Chroma)     → vector storage
  └─ KnowledgeGraph (NetworkX) → entity + fact graph

memory.get(query)
  │
  ├─ Embedder → query vector
  ├─ BaseStore.search() → top-k similar memories
  ├─ KnowledgeGraph.query() → related facts
  └─ Ranker.fuse() → weighted blend → MemoryContext

Fusion formula: score = 0.6 × vector_score + 0.4 × graph_score


Configuration

from memoryweave import MemoryConfig

config = MemoryConfig(
    store_type="memory",        # "memory" | "chroma" | "qdrant"
    store_path="./mw_db",       # path for chroma/qdrant
    embedding_model="all-MiniLM-L6-v2",  # any sentence-transformers model
    spacy_model="en_core_web_sm",        # any spaCy model
    top_k=5,                    # memories to retrieve per get()
    vector_weight=0.6,          # fusion weight for vector search
    graph_weight=0.4,           # fusion weight for graph search
    default_session_id="default",        # session namespace
)

REST API

Start the server: uvicorn memoryweave.server:app --reload

Method Endpoint Description
GET /health Health check
POST /memory/add Add a memory
POST /memory/get Retrieve context
DELETE /memory/forget Wipe a session
GET /memory/stats Session stats

Full interactive docs at http://localhost:8000/docs


Project status

✅ Phase 1 — Foundation
✅ Phase 2 — NLP extraction pipeline (spaCy)
✅ Phase 3 — Storage layer (vector store + knowledge graph)
✅ Phase 4 — Core memory API v0.1.0
✅ Phase 5 — TypeScript SDK
✅ Phase 6 — FastAPI REST server
⬜ Phase 7 — Documentation
⬜ Phase 8 — Launch v1.0.0 (Product Hunt + Hacker News)

Test coverage: 225+ tests · 90%+ coverage · CI green on Python 3.10/3.11/3.12


Contributing

See CONTRIBUTING.md for guidelines.

git clone https://github.com/ravii-k/memoryweave.git
cd memoryweave
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
python -m spacy download en_core_web_sm
pytest tests/ -v

License

MIT — see LICENSE for details.


Built by Ravi Kashyap · Started March 2026

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memoryweave-1.0.0.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memoryweave-1.0.0-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

Details for the file memoryweave-1.0.0.tar.gz.

File metadata

  • Download URL: memoryweave-1.0.0.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for memoryweave-1.0.0.tar.gz
Algorithm Hash digest
SHA256 58cfd274af6ef268600bfee4304dad5149292333aa5d3fa578d05cdec4b080ef
MD5 bebcd9859068b8ccdaf7a6a40903db16
BLAKE2b-256 1340bd4b8cab883f863cbbbaeba4ce18336ebc0f51b81ebdfedf32ca9cd098ab

See more details on using hashes here.

File details

Details for the file memoryweave-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: memoryweave-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for memoryweave-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7606b5ee99f975c49b31ec14bc440c850f10c77b4a31999518914db47679c6b6
MD5 1b7f63df96402b76bf251716a1da9cab
BLAKE2b-256 380a0b85b38492daa206805260471638e3c0d70adbaa3bb4fdfafe7dc1ad8280

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page