Metadata-Version: 2.5
Name: meminumb
Version: 0.1.0
Summary: Lightweight, reliable memory layer for AI agents — atomic writes, explicit outcomes
Project-URL: Repository, https://github.com/H-S-Prajwal/Meminumb
Project-URL: Issues, https://github.com/H-S-Prajwal/Meminumb/issues
License: MIT License
        
        Copyright (c) 2026 2025sl93074
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agents,ai,llm,memory
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Provides-Extra: groq
Requires-Dist: groq>=0.9; extra == 'groq'
Provides-Extra: local
Requires-Dist: sentence-transformers>=2.7; extra == 'local'
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == 'openai'
Description-Content-Type: text/markdown

# Meminumb

**Lightweight, reliable memory layer for AI agents.**

Meminumb stores facts about users across sessions so your AI agent can remember context — with two guarantees that common libraries miss:

1. **Atomic writes** — a failure never leaves orphaned data behind
2. **Explicit outcomes** — `add()` always tells you what happened to every fact, and why

---

## The problem Meminumb solves

Most AI memory libraries swallow failures silently. If your database write partially succeeds, you get orphaned entries and duplicate facts on retry. And if a fact is skipped (duplicate, embed error), you never find out why.

Meminumb fixes this by design:

| Feature | Meminumb | Typical library |
|---|---|---|
| Atomic writes (no orphaned data) | ✅ | ❌ |
| Explicit outcome per fact | ✅ | ❌ |
| Content-addressed IDs (idempotent) | ✅ | ❌ |
| Zero mandatory external deps | ✅ | ❌ |
| Pluggable embedders | ✅ | varies |

---

## Install

```bash
pip install meminumb                    # core only (SQLite, no embeddings API)
pip install "meminumb[local]"           # + sentence-transformers (offline)
pip install "meminumb[openai]"          # + OpenAI embeddings API
pip install "meminumb[dev]"             # + pytest, ruff (for contributors)
```

---

## Quickstart

```python
from meminumb import Memory

mem = Memory()   # uses offline DummyEmbedder by default

result = mem.add(
    ["Alice prefers dark mode", "Alice is a backend developer"],
    user_id="alice",
)
print(result)
# AddResult(stored=2, skipped=0, failed=0)

# Try adding a duplicate
result2 = mem.add(["Alice prefers dark mode"], user_id="alice")
print(result2)
# AddResult(stored=0, skipped=1, failed=0)

skip = result2.skipped[0]
print(skip.reason, skip.existing_id)
# SkipReason.DUPLICATE  3f2a1b8e...

# Search
hits = mem.search("what does Alice like in her editor?", user_id="alice")
print(hits[0].content)
# Alice prefers dark mode
```

### With local embeddings (semantic search, offline)

```python
from meminumb import Memory
from meminumb.embedder import LocalEmbedder

mem = Memory(embedder=LocalEmbedder())   # downloads ~90 MB model on first run
mem.add(["Bob enjoys hiking on weekends"], user_id="bob")
hits = mem.search("outdoor activities", user_id="bob")
print(hits[0].content)
# Bob enjoys hiking on weekends
```

---

## API reference

### `Memory(store=None, embedder=None, db_path=":memory:")`

| Parameter | Default | Description |
|---|---|---|
| `store` | `SQLiteStore(":memory:")` | Storage backend |
| `embedder` | `DummyEmbedder()` | Embedding backend |
| `db_path` | `":memory:"` | SQLite file path (pass a real path to persist) |

### `Memory.add(facts, user_id="", agent_id="", metadata=None) → AddResult`

Returns an `AddResult` with three lists:

```python
result.stored   # List[MemoryItem]   — successfully written
result.skipped  # List[SkippedItem]  — not written, with reason
result.failed   # List[SkippedItem]  — write attempted, raised error
result.all_succeeded  # bool
```

Each `SkippedItem` has:
- `.content` — the original fact
- `.reason` — `SkipReason.DUPLICATE` | `EMBED_FAILED` | `INSERT_FAILED`
- `.existing_id` — set when reason is DUPLICATE
- `.error` — error message when reason is EMBED_FAILED or INSERT_FAILED

### Other methods

```python
mem.search(query, user_id="", top_k=5)   # → List[MemoryItem]
mem.get(memory_id)                        # → MemoryItem | None
mem.get_all(user_id="")                   # → List[MemoryItem]
mem.delete(memory_id)                     # → bool
mem.clear(user_id="")                     # → int (count deleted)
```

---

## Chat demo — a bot that remembers you

The most direct way to see Meminumb in action is the conversational demo. It uses a Groq-hosted LLM (free, no credit card) and stores everything Meminumb hears about you persistently.

```bash
pip install groq
export GROQ_API_KEY="your-key-here"   # free at console.groq.com
python examples/chat_demo.py
```

**First session:**
```
You: Hi, I'm Prajwal. I love jazz and I'm a backend developer.
[Meminumb] Stored 3 new fact(s)
Bot: Nice to meet you Prajwal! Jazz is a great taste. What do you work on?

You: quit
```

**Second session (new process, same memories):**
```
[Meminumb] I remember 3 fact(s) about you from last time.

You: What do you remember about me?
Bot: You're Prajwal, a backend developer who loves jazz!
```

Type `memory` to inspect stored facts, `clear` to wipe them.

---

## Persistent storage

```python
mem = Memory(db_path="~/.meminumb/myapp.db")
```

The database file is created automatically. Use the same path across sessions to persist memory.

---

## Architecture and design decisions

### Why SQLite instead of a vector database?

Most AI memory libraries use a dedicated vector database (Qdrant, Pinecone, Chroma) alongside a separate metadata store. This creates two systems that can go out of sync — if the vector write succeeds but the metadata write fails, you have an orphaned vector with no history record. This is exactly the bug that inspired Meminumb (see [mem0ai/mem0#7879](https://github.com/mem0ai/mem0/issues/7879)).

Meminumb stores everything — content, embedding, metadata — in a single SQLite table. SQLite's WAL-mode transactions mean a write either fully commits or fully rolls back. One system, one failure mode, no orphans.

### Why content-addressed IDs instead of random UUIDs?

A random UUID means every `add()` call needs a full-text scan to detect duplicates. It also means retrying a failed add creates a new ID each time, potentially producing duplicates.

Meminumb derives the ID from the content:
```python
id = sha256(user_id + agent_id + content.strip().lower())[:16]
```

Same fact + same user always produces the same ID. Duplicate detection is a single existence check. Retries are naturally idempotent — re-adding a fact that already exists is a no-op, not a duplicate.

### Why `AddResult` instead of raising exceptions?

Raising an exception on the first failure stops processing the entire batch. In an agent loop adding 10 facts, one embed failure would silently discard the other 9.

`AddResult` processes every fact independently and classifies each into `stored`, `skipped`, or `failed` with a machine-readable `SkipReason`. The caller decides what to do — retry the failed ones, alert on duplicates, or just log. Nothing is ever silently dropped.

### Why `update()` re-embeds on content change?

Embeddings are what power semantic search. If you change the content text but keep the old embedding, search would still find this memory based on the *old* meaning. Re-embedding on every content change keeps search results accurate with no extra work from the caller.

---

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).

---

## License

MIT — see [LICENSE](LICENSE).
