mengram-ai 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mengram_ai-1.0.0/LICENSE +21 -0
- mengram_ai-1.0.0/PKG-INFO +367 -0
- mengram_ai-1.0.0/README.md +318 -0
- mengram_ai-1.0.0/api/__init__.py +1 -0
- mengram_ai-1.0.0/api/cloud_mcp_server.py +270 -0
- mengram_ai-1.0.0/api/mcp_server.py +363 -0
- mengram_ai-1.0.0/api/rest_server.py +394 -0
- mengram_ai-1.0.0/cli.py +458 -0
- mengram_ai-1.0.0/engine/__init__.py +1 -0
- mengram_ai-1.0.0/engine/brain.py +591 -0
- mengram_ai-1.0.0/engine/extractor/__init__.py +0 -0
- mengram_ai-1.0.0/engine/extractor/conversation_extractor.py +272 -0
- mengram_ai-1.0.0/engine/extractor/llm_client.py +166 -0
- mengram_ai-1.0.0/engine/graph/__init__.py +0 -0
- mengram_ai-1.0.0/engine/graph/knowledge_graph.py +448 -0
- mengram_ai-1.0.0/engine/parser/__init__.py +0 -0
- mengram_ai-1.0.0/engine/parser/markdown_parser.py +322 -0
- mengram_ai-1.0.0/engine/retrieval/__init__.py +0 -0
- mengram_ai-1.0.0/engine/retrieval/hybrid_search.py +226 -0
- mengram_ai-1.0.0/engine/vault_manager/__init__.py +0 -0
- mengram_ai-1.0.0/engine/vault_manager/vault_manager.py +361 -0
- mengram_ai-1.0.0/engine/vector/__init__.py +0 -0
- mengram_ai-1.0.0/engine/vector/embedder.py +83 -0
- mengram_ai-1.0.0/engine/vector/vector_store.py +244 -0
- mengram_ai-1.0.0/mengram.py +450 -0
- mengram_ai-1.0.0/mengram_ai.egg-info/PKG-INFO +367 -0
- mengram_ai-1.0.0/mengram_ai.egg-info/SOURCES.txt +33 -0
- mengram_ai-1.0.0/mengram_ai.egg-info/dependency_links.txt +1 -0
- mengram_ai-1.0.0/mengram_ai.egg-info/entry_points.txt +2 -0
- mengram_ai-1.0.0/mengram_ai.egg-info/requires.txt +30 -0
- mengram_ai-1.0.0/mengram_ai.egg-info/top_level.txt +5 -0
- mengram_ai-1.0.0/mengram_middleware.py +230 -0
- mengram_ai-1.0.0/pyproject.toml +69 -0
- mengram_ai-1.0.0/setup.cfg +4 -0
- mengram_ai-1.0.0/tests/test_parser.py +122 -0
mengram_ai-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ali Baizhanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mengram-ai
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: AI memory layer for apps. Open-source Mem0 alternative. Like Mem0, but you own your data.
|
|
5
|
+
Author: Ali Baizhanov
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/alibaizhanov/mengram
|
|
8
|
+
Project-URL: Repository, https://github.com/alibaizhanov/mengram
|
|
9
|
+
Project-URL: Issues, https://github.com/alibaizhanov/mengram/issues
|
|
10
|
+
Project-URL: Documentation, https://mengram.io
|
|
11
|
+
Keywords: memory,mengram,knowledge-graph,llm,ai,mcp,second-brain,rag,semantic-search,embeddings
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: pyyaml>=6.0
|
|
26
|
+
Requires-Dist: numpy>=1.24
|
|
27
|
+
Provides-Extra: anthropic
|
|
28
|
+
Requires-Dist: anthropic>=0.40; extra == "anthropic"
|
|
29
|
+
Provides-Extra: openai
|
|
30
|
+
Requires-Dist: openai>=1.0; extra == "openai"
|
|
31
|
+
Provides-Extra: embeddings
|
|
32
|
+
Requires-Dist: sentence-transformers>=2.2; extra == "embeddings"
|
|
33
|
+
Provides-Extra: mcp
|
|
34
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
35
|
+
Provides-Extra: api
|
|
36
|
+
Requires-Dist: fastapi>=0.100; extra == "api"
|
|
37
|
+
Requires-Dist: uvicorn>=0.20; extra == "api"
|
|
38
|
+
Provides-Extra: all
|
|
39
|
+
Requires-Dist: anthropic>=0.40; extra == "all"
|
|
40
|
+
Requires-Dist: openai>=1.0; extra == "all"
|
|
41
|
+
Requires-Dist: sentence-transformers>=2.2; extra == "all"
|
|
42
|
+
Requires-Dist: mcp>=1.0; extra == "all"
|
|
43
|
+
Requires-Dist: fastapi>=0.100; extra == "all"
|
|
44
|
+
Requires-Dist: uvicorn>=0.20; extra == "all"
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
47
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# 🧠 Mengram
|
|
51
|
+
|
|
52
|
+
**AI memory as a typed knowledge graph in Obsidian.**
|
|
53
|
+
|
|
54
|
+
Every conversation with your AI builds a structured second brain — people, projects, technologies, companies — all as `.md` files with `[[wikilinks]]` you can browse in [Obsidian](https://obsidian.md).
|
|
55
|
+
|
|
56
|
+
Like [Mem0](https://github.com/mem0ai/mem0), but **you own your data** — and it actually saves your solutions with code, not just "user uses PostgreSQL".
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Why Mengram?
|
|
61
|
+
|
|
62
|
+
| | **Mem0** | **Basic Memory** | **Mengram** |
|
|
63
|
+
|---|---|---|---|
|
|
64
|
+
| Storage | Cloud vectors | Flat markdown | **Typed knowledge graph in .md** |
|
|
65
|
+
| Entity types | ❌ Flat facts | ❌ One note per chat | ✅ Person, Project, Technology, Company |
|
|
66
|
+
| Relations | ❌ | ❌ | ✅ `works_at`, `uses`, `depends_on` |
|
|
67
|
+
| **Rich knowledge** | ❌ | ❌ | ✅ **Solutions, configs, formulas with code** |
|
|
68
|
+
| **Proactive context** | ❌ | ❌ | ✅ **Auto-injected — no manual recall** |
|
|
69
|
+
| Obsidian graph | ❌ | Partial | ✅ Full `[[wikilinks]]` + graph view |
|
|
70
|
+
| Semantic search | ✅ Cloud | ❌ | ✅ Local embeddings (384D) |
|
|
71
|
+
| Own your data | ❌ Cloud lock-in | ✅ | ✅ Plain `.md` files |
|
|
72
|
+
| LLM agnostic | ❌ | Partial | ✅ Claude / GPT / Ollama |
|
|
73
|
+
| Pricing | $24/mo+ | $14/mo | **Free & open source** |
|
|
74
|
+
|
|
75
|
+
### What it actually does
|
|
76
|
+
|
|
77
|
+
You chat with Claude (or any LLM). Mengram **automatically**:
|
|
78
|
+
|
|
79
|
+
1. **Extracts** entities, facts, relationships, and **rich knowledge** (solutions, commands, configs with code)
|
|
80
|
+
2. **Creates** typed `.md` files in your Obsidian vault
|
|
81
|
+
3. **Links** everything with `[[wikilinks]]` and YAML frontmatter
|
|
82
|
+
4. **Indexes** with local vector embeddings for semantic search
|
|
83
|
+
5. **Proactively injects** relevant context into every conversation — no manual recall needed
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
You: "We fixed the OOM with Redis cache. Config: hikari.pool-size=20"
|
|
87
|
+
|
|
88
|
+
┌─────────────────────────────────────┐
|
|
89
|
+
│ vault/PostgreSQL.md │
|
|
90
|
+
│ type: technology │
|
|
91
|
+
│ │
|
|
92
|
+
│ ## Facts │
|
|
93
|
+
│ - Main database, version 15 │
|
|
94
|
+
│ │
|
|
95
|
+
│ ## Knowledge │
|
|
96
|
+
│ **[solution] Connection pool fix** │
|
|
97
|
+
│ OOM at 200+ WebSocket → Redis cache │
|
|
98
|
+
│ ```yaml │
|
|
99
|
+
│ spring.datasource.hikari. │
|
|
100
|
+
│ maximum-pool-size: 20 │
|
|
101
|
+
│ ``` │
|
|
102
|
+
└─────────────────────────────────────┘
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Next time you ask "How did we fix the OOM?" → Claude **already knows**, with the config.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Quick Start
|
|
110
|
+
|
|
111
|
+
### 1. Install
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install mengram[all]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 2. Setup (one command)
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
mengram init
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
This will:
|
|
124
|
+
- Ask for your LLM provider and API key
|
|
125
|
+
- Create `~/.mengram/config.yaml` and vault
|
|
126
|
+
- Auto-configure Claude Desktop MCP integration
|
|
127
|
+
- Tell you to restart Claude Desktop
|
|
128
|
+
|
|
129
|
+
That's it. **Talk to Claude — it remembers automatically and always has context.**
|
|
130
|
+
|
|
131
|
+
### Non-interactive:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
mengram init --provider anthropic --api-key sk-ant-...
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Other commands:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
mengram status # Check setup
|
|
141
|
+
mengram stats # Vault statistics
|
|
142
|
+
mengram server # Start MCP server manually
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Proactive Context (v0.5.0)
|
|
148
|
+
|
|
149
|
+
The killer feature. Claude Desktop gets your knowledge profile **automatically** — no manual attach, no "recall", no "remember what I told you".
|
|
150
|
+
|
|
151
|
+
**How it works:**
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
Claude Desktop starts
|
|
155
|
+
→ MCP server reads vault
|
|
156
|
+
→ Generates compact knowledge index (scales to 1000+ notes)
|
|
157
|
+
→ Injects into Claude's instructions
|
|
158
|
+
→ Warms up semantic search model
|
|
159
|
+
|
|
160
|
+
You open any chat → Claude already knows:
|
|
161
|
+
- Your tech stack, projects, team
|
|
162
|
+
- Past solutions with code/configs
|
|
163
|
+
- Entity relationships
|
|
164
|
+
|
|
165
|
+
You ask a question → Claude auto-calls recall()
|
|
166
|
+
→ Gets full details + code artifacts
|
|
167
|
+
→ Answers with context
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Rich Knowledge (v0.5.0)
|
|
173
|
+
|
|
174
|
+
Not just "user uses PostgreSQL" — but **solutions with code**, commands, formulas, configs.
|
|
175
|
+
|
|
176
|
+
The LLM **automatically** chooses the knowledge type based on context:
|
|
177
|
+
|
|
178
|
+
| Domain | Knowledge types | Example |
|
|
179
|
+
|---|---|---|
|
|
180
|
+
| Developer | `solution`, `command`, `config`, `debug` | HikariCP pool config with YAML |
|
|
181
|
+
| Doctor | `treatment`, `lab_result`, `diagnosis` | Metformin 500mg dosage |
|
|
182
|
+
| Scientist | `experiment`, `formula`, `hypothesis` | Protein denaturation at 60°C |
|
|
183
|
+
| Student | `formula`, `example`, `insight` | Bayes theorem with example |
|
|
184
|
+
| Chef | `recipe`, `tip`, `substitution` | Sourdough hydration ratio |
|
|
185
|
+
|
|
186
|
+
**No configuration needed.** The system adapts to any domain.
|
|
187
|
+
|
|
188
|
+
```markdown
|
|
189
|
+
## Knowledge
|
|
190
|
+
|
|
191
|
+
**[solution] Connection pool exhaustion fix** (2024-02-10)
|
|
192
|
+
OOM at 200+ WebSocket connections → Redis cache for UserService
|
|
193
|
+
```yaml
|
|
194
|
+
spring.datasource.hikari.maximum-pool-size: 20
|
|
195
|
+
spring.datasource.hikari.idle-timeout: 30000
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**[command] Debug database connections** (2024-02-10)
|
|
199
|
+
Monitor active PostgreSQL connections
|
|
200
|
+
```sql
|
|
201
|
+
SELECT count(*), state FROM pg_stat_activity GROUP BY state;
|
|
202
|
+
```
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Python SDK (Mem0-compatible API)
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from mengram import Memory
|
|
211
|
+
|
|
212
|
+
m = Memory(
|
|
213
|
+
vault_path="./my-brain",
|
|
214
|
+
llm_provider="anthropic",
|
|
215
|
+
api_key="sk-ant-..."
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
# Remember — extracts entities, facts, relations, AND knowledge
|
|
219
|
+
m.add("I work at Uzum Bank, backend on Spring Boot and PostgreSQL", user_id="ali")
|
|
220
|
+
|
|
221
|
+
# Semantic search (finds by MEANING, not just keywords)
|
|
222
|
+
results = m.search("database issues", user_id="ali")
|
|
223
|
+
for r in results:
|
|
224
|
+
print(f"{r.memory.name} (score={r.score:.2f})")
|
|
225
|
+
print(r.memory.facts)
|
|
226
|
+
|
|
227
|
+
# Get everything
|
|
228
|
+
all_memories = m.get_all(user_id="ali")
|
|
229
|
+
|
|
230
|
+
# Stats
|
|
231
|
+
print(m.stats(user_id="ali"))
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Auto-Memory Middleware
|
|
235
|
+
|
|
236
|
+
Drop-in wrapper that automatically remembers and recalls:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from mengram import Memory
|
|
240
|
+
from mengram_middleware import AutoMemory
|
|
241
|
+
|
|
242
|
+
m = Memory(vault_path="./vault", llm_provider="anthropic", api_key="sk-ant-...")
|
|
243
|
+
auto = AutoMemory(memory=m, user_id="ali")
|
|
244
|
+
|
|
245
|
+
# Automatically: recall context → inject → LLM response → remember new knowledge
|
|
246
|
+
response = auto.chat("Help me fix the PostgreSQL connection pool issue")
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## How It Works
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
Conversation → Extractor (LLM) → Entities + Facts + Relations + Knowledge
|
|
255
|
+
↓
|
|
256
|
+
Vault Manager → .md files with [[wikilinks]]
|
|
257
|
+
↓
|
|
258
|
+
Vector Index → local embeddings (SQLite)
|
|
259
|
+
↓
|
|
260
|
+
MCP Server → instructions (compact index)
|
|
261
|
+
→ tools (recall, remember)
|
|
262
|
+
↓
|
|
263
|
+
Claude Desktop → auto-context every chat
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Semantic Search (Hybrid)
|
|
267
|
+
|
|
268
|
+
3-level search strategy:
|
|
269
|
+
|
|
270
|
+
1. **Vector Search** — `all-MiniLM-L6-v2` (80MB, runs locally). Finds "database" when you search "PostgreSQL" — by meaning, not keywords.
|
|
271
|
+
2. **Graph Expansion** — follows `[[wikilinks]]` from top results. Found PostgreSQL? Also returns linked Project Alpha.
|
|
272
|
+
3. **Text Fallback** — substring match for edge cases.
|
|
273
|
+
|
|
274
|
+
### Entity Types
|
|
275
|
+
|
|
276
|
+
| Type | Examples |
|
|
277
|
+
|---|---|
|
|
278
|
+
| `person` | Team members, contacts |
|
|
279
|
+
| `project` | Services, repos, products |
|
|
280
|
+
| `technology` | PostgreSQL, Spring Boot, Kafka |
|
|
281
|
+
| `company` | Employers, clients, partners |
|
|
282
|
+
| `concept` | Patterns, strategies, ideas |
|
|
283
|
+
|
|
284
|
+
### File Format
|
|
285
|
+
|
|
286
|
+
```markdown
|
|
287
|
+
---
|
|
288
|
+
type: technology
|
|
289
|
+
created: 2024-02-10 15:30
|
|
290
|
+
updated: 2024-02-11 09:15
|
|
291
|
+
tags: [technology]
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
# PostgreSQL
|
|
295
|
+
|
|
296
|
+
## Facts
|
|
297
|
+
|
|
298
|
+
- Main database, version 15
|
|
299
|
+
- Connection pool issue in [[Project Alpha]]
|
|
300
|
+
|
|
301
|
+
## Relations
|
|
302
|
+
|
|
303
|
+
- ← uses [[Project Alpha]]: Main DB
|
|
304
|
+
|
|
305
|
+
## Knowledge
|
|
306
|
+
|
|
307
|
+
**[solution] Connection pool exhaustion fix** (2024-02-10)
|
|
308
|
+
OOM at 200+ WebSocket → Redis cache for UserService
|
|
309
|
+
```yaml
|
|
310
|
+
spring.datasource.hikari.maximum-pool-size: 20
|
|
311
|
+
```
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Configuration
|
|
317
|
+
|
|
318
|
+
```yaml
|
|
319
|
+
# config.yaml
|
|
320
|
+
vault_path: "./vault"
|
|
321
|
+
|
|
322
|
+
llm:
|
|
323
|
+
provider: "anthropic" # anthropic | openai | ollama | mock
|
|
324
|
+
anthropic:
|
|
325
|
+
api_key: "sk-ant-..."
|
|
326
|
+
model: "claude-sonnet-4-20250514"
|
|
327
|
+
|
|
328
|
+
semantic_search:
|
|
329
|
+
enabled: true
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
| Provider | Install | Cost |
|
|
333
|
+
|---|---|---|
|
|
334
|
+
| Anthropic (Claude) | `pip install mengram[anthropic]` | API pricing |
|
|
335
|
+
| OpenAI (GPT) | `pip install mengram[openai]` | API pricing |
|
|
336
|
+
| Ollama (local) | Install [ollama](https://ollama.ai) | Free |
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Roadmap
|
|
341
|
+
|
|
342
|
+
- [x] Typed entity extraction (person, project, technology, company)
|
|
343
|
+
- [x] Obsidian vault with `[[wikilinks]]` + YAML frontmatter
|
|
344
|
+
- [x] MCP Server for Claude Desktop
|
|
345
|
+
- [x] Semantic search with local embeddings
|
|
346
|
+
- [x] Hybrid retrieval (vector + graph)
|
|
347
|
+
- [x] Mem0-compatible Python SDK
|
|
348
|
+
- [x] Auto-memory middleware
|
|
349
|
+
- [x] **Rich knowledge extraction (solutions, configs, formulas with code)**
|
|
350
|
+
- [x] **Proactive context (auto-injected via MCP instructions)**
|
|
351
|
+
- [ ] Entity deduplication
|
|
352
|
+
- [ ] Obsidian plugin (TypeScript)
|
|
353
|
+
- [ ] Web dashboard
|
|
354
|
+
- [ ] REST API
|
|
355
|
+
|
|
356
|
+
## Contributing
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
git clone https://github.com/alibaizhanov/mengram
|
|
360
|
+
cd mengram
|
|
361
|
+
pip install -e ".[all,dev]"
|
|
362
|
+
pytest
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## License
|
|
366
|
+
|
|
367
|
+
MIT
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
# 🧠 Mengram
|
|
2
|
+
|
|
3
|
+
**AI memory as a typed knowledge graph in Obsidian.**
|
|
4
|
+
|
|
5
|
+
Every conversation with your AI builds a structured second brain — people, projects, technologies, companies — all as `.md` files with `[[wikilinks]]` you can browse in [Obsidian](https://obsidian.md).
|
|
6
|
+
|
|
7
|
+
Like [Mem0](https://github.com/mem0ai/mem0), but **you own your data** — and it actually saves your solutions with code, not just "user uses PostgreSQL".
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why Mengram?
|
|
12
|
+
|
|
13
|
+
| | **Mem0** | **Basic Memory** | **Mengram** |
|
|
14
|
+
|---|---|---|---|
|
|
15
|
+
| Storage | Cloud vectors | Flat markdown | **Typed knowledge graph in .md** |
|
|
16
|
+
| Entity types | ❌ Flat facts | ❌ One note per chat | ✅ Person, Project, Technology, Company |
|
|
17
|
+
| Relations | ❌ | ❌ | ✅ `works_at`, `uses`, `depends_on` |
|
|
18
|
+
| **Rich knowledge** | ❌ | ❌ | ✅ **Solutions, configs, formulas with code** |
|
|
19
|
+
| **Proactive context** | ❌ | ❌ | ✅ **Auto-injected — no manual recall** |
|
|
20
|
+
| Obsidian graph | ❌ | Partial | ✅ Full `[[wikilinks]]` + graph view |
|
|
21
|
+
| Semantic search | ✅ Cloud | ❌ | ✅ Local embeddings (384D) |
|
|
22
|
+
| Own your data | ❌ Cloud lock-in | ✅ | ✅ Plain `.md` files |
|
|
23
|
+
| LLM agnostic | ❌ | Partial | ✅ Claude / GPT / Ollama |
|
|
24
|
+
| Pricing | $24/mo+ | $14/mo | **Free & open source** |
|
|
25
|
+
|
|
26
|
+
### What it actually does
|
|
27
|
+
|
|
28
|
+
You chat with Claude (or any LLM). Mengram **automatically**:
|
|
29
|
+
|
|
30
|
+
1. **Extracts** entities, facts, relationships, and **rich knowledge** (solutions, commands, configs with code)
|
|
31
|
+
2. **Creates** typed `.md` files in your Obsidian vault
|
|
32
|
+
3. **Links** everything with `[[wikilinks]]` and YAML frontmatter
|
|
33
|
+
4. **Indexes** with local vector embeddings for semantic search
|
|
34
|
+
5. **Proactively injects** relevant context into every conversation — no manual recall needed
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
You: "We fixed the OOM with Redis cache. Config: hikari.pool-size=20"
|
|
38
|
+
|
|
39
|
+
┌─────────────────────────────────────┐
|
|
40
|
+
│ vault/PostgreSQL.md │
|
|
41
|
+
│ type: technology │
|
|
42
|
+
│ │
|
|
43
|
+
│ ## Facts │
|
|
44
|
+
│ - Main database, version 15 │
|
|
45
|
+
│ │
|
|
46
|
+
│ ## Knowledge │
|
|
47
|
+
│ **[solution] Connection pool fix** │
|
|
48
|
+
│ OOM at 200+ WebSocket → Redis cache │
|
|
49
|
+
│ ```yaml │
|
|
50
|
+
│ spring.datasource.hikari. │
|
|
51
|
+
│ maximum-pool-size: 20 │
|
|
52
|
+
│ ``` │
|
|
53
|
+
└─────────────────────────────────────┘
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Next time you ask "How did we fix the OOM?" → Claude **already knows**, with the config.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Quick Start
|
|
61
|
+
|
|
62
|
+
### 1. Install
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install mengram[all]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 2. Setup (one command)
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
mengram init
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This will:
|
|
75
|
+
- Ask for your LLM provider and API key
|
|
76
|
+
- Create `~/.mengram/config.yaml` and vault
|
|
77
|
+
- Auto-configure Claude Desktop MCP integration
|
|
78
|
+
- Tell you to restart Claude Desktop
|
|
79
|
+
|
|
80
|
+
That's it. **Talk to Claude — it remembers automatically and always has context.**
|
|
81
|
+
|
|
82
|
+
### Non-interactive:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
mengram init --provider anthropic --api-key sk-ant-...
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Other commands:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
mengram status # Check setup
|
|
92
|
+
mengram stats # Vault statistics
|
|
93
|
+
mengram server # Start MCP server manually
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Proactive Context (v0.5.0)
|
|
99
|
+
|
|
100
|
+
The killer feature. Claude Desktop gets your knowledge profile **automatically** — no manual attach, no "recall", no "remember what I told you".
|
|
101
|
+
|
|
102
|
+
**How it works:**
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
Claude Desktop starts
|
|
106
|
+
→ MCP server reads vault
|
|
107
|
+
→ Generates compact knowledge index (scales to 1000+ notes)
|
|
108
|
+
→ Injects into Claude's instructions
|
|
109
|
+
→ Warms up semantic search model
|
|
110
|
+
|
|
111
|
+
You open any chat → Claude already knows:
|
|
112
|
+
- Your tech stack, projects, team
|
|
113
|
+
- Past solutions with code/configs
|
|
114
|
+
- Entity relationships
|
|
115
|
+
|
|
116
|
+
You ask a question → Claude auto-calls recall()
|
|
117
|
+
→ Gets full details + code artifacts
|
|
118
|
+
→ Answers with context
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Rich Knowledge (v0.5.0)
|
|
124
|
+
|
|
125
|
+
Not just "user uses PostgreSQL" — but **solutions with code**, commands, formulas, configs.
|
|
126
|
+
|
|
127
|
+
The LLM **automatically** chooses the knowledge type based on context:
|
|
128
|
+
|
|
129
|
+
| Domain | Knowledge types | Example |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| Developer | `solution`, `command`, `config`, `debug` | HikariCP pool config with YAML |
|
|
132
|
+
| Doctor | `treatment`, `lab_result`, `diagnosis` | Metformin 500mg dosage |
|
|
133
|
+
| Scientist | `experiment`, `formula`, `hypothesis` | Protein denaturation at 60°C |
|
|
134
|
+
| Student | `formula`, `example`, `insight` | Bayes theorem with example |
|
|
135
|
+
| Chef | `recipe`, `tip`, `substitution` | Sourdough hydration ratio |
|
|
136
|
+
|
|
137
|
+
**No configuration needed.** The system adapts to any domain.
|
|
138
|
+
|
|
139
|
+
```markdown
|
|
140
|
+
## Knowledge
|
|
141
|
+
|
|
142
|
+
**[solution] Connection pool exhaustion fix** (2024-02-10)
|
|
143
|
+
OOM at 200+ WebSocket connections → Redis cache for UserService
|
|
144
|
+
```yaml
|
|
145
|
+
spring.datasource.hikari.maximum-pool-size: 20
|
|
146
|
+
spring.datasource.hikari.idle-timeout: 30000
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**[command] Debug database connections** (2024-02-10)
|
|
150
|
+
Monitor active PostgreSQL connections
|
|
151
|
+
```sql
|
|
152
|
+
SELECT count(*), state FROM pg_stat_activity GROUP BY state;
|
|
153
|
+
```
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Python SDK (Mem0-compatible API)
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from mengram import Memory
|
|
162
|
+
|
|
163
|
+
m = Memory(
|
|
164
|
+
vault_path="./my-brain",
|
|
165
|
+
llm_provider="anthropic",
|
|
166
|
+
api_key="sk-ant-..."
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# Remember — extracts entities, facts, relations, AND knowledge
|
|
170
|
+
m.add("I work at Uzum Bank, backend on Spring Boot and PostgreSQL", user_id="ali")
|
|
171
|
+
|
|
172
|
+
# Semantic search (finds by MEANING, not just keywords)
|
|
173
|
+
results = m.search("database issues", user_id="ali")
|
|
174
|
+
for r in results:
|
|
175
|
+
print(f"{r.memory.name} (score={r.score:.2f})")
|
|
176
|
+
print(r.memory.facts)
|
|
177
|
+
|
|
178
|
+
# Get everything
|
|
179
|
+
all_memories = m.get_all(user_id="ali")
|
|
180
|
+
|
|
181
|
+
# Stats
|
|
182
|
+
print(m.stats(user_id="ali"))
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Auto-Memory Middleware
|
|
186
|
+
|
|
187
|
+
Drop-in wrapper that automatically remembers and recalls:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from mengram import Memory
|
|
191
|
+
from mengram_middleware import AutoMemory
|
|
192
|
+
|
|
193
|
+
m = Memory(vault_path="./vault", llm_provider="anthropic", api_key="sk-ant-...")
|
|
194
|
+
auto = AutoMemory(memory=m, user_id="ali")
|
|
195
|
+
|
|
196
|
+
# Automatically: recall context → inject → LLM response → remember new knowledge
|
|
197
|
+
response = auto.chat("Help me fix the PostgreSQL connection pool issue")
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## How It Works
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
Conversation → Extractor (LLM) → Entities + Facts + Relations + Knowledge
|
|
206
|
+
↓
|
|
207
|
+
Vault Manager → .md files with [[wikilinks]]
|
|
208
|
+
↓
|
|
209
|
+
Vector Index → local embeddings (SQLite)
|
|
210
|
+
↓
|
|
211
|
+
MCP Server → instructions (compact index)
|
|
212
|
+
→ tools (recall, remember)
|
|
213
|
+
↓
|
|
214
|
+
Claude Desktop → auto-context every chat
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Semantic Search (Hybrid)
|
|
218
|
+
|
|
219
|
+
3-level search strategy:
|
|
220
|
+
|
|
221
|
+
1. **Vector Search** — `all-MiniLM-L6-v2` (80MB, runs locally). Finds "database" when you search "PostgreSQL" — by meaning, not keywords.
|
|
222
|
+
2. **Graph Expansion** — follows `[[wikilinks]]` from top results. Found PostgreSQL? Also returns linked Project Alpha.
|
|
223
|
+
3. **Text Fallback** — substring match for edge cases.
|
|
224
|
+
|
|
225
|
+
### Entity Types
|
|
226
|
+
|
|
227
|
+
| Type | Examples |
|
|
228
|
+
|---|---|
|
|
229
|
+
| `person` | Team members, contacts |
|
|
230
|
+
| `project` | Services, repos, products |
|
|
231
|
+
| `technology` | PostgreSQL, Spring Boot, Kafka |
|
|
232
|
+
| `company` | Employers, clients, partners |
|
|
233
|
+
| `concept` | Patterns, strategies, ideas |
|
|
234
|
+
|
|
235
|
+
### File Format
|
|
236
|
+
|
|
237
|
+
```markdown
|
|
238
|
+
---
|
|
239
|
+
type: technology
|
|
240
|
+
created: 2024-02-10 15:30
|
|
241
|
+
updated: 2024-02-11 09:15
|
|
242
|
+
tags: [technology]
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
# PostgreSQL
|
|
246
|
+
|
|
247
|
+
## Facts
|
|
248
|
+
|
|
249
|
+
- Main database, version 15
|
|
250
|
+
- Connection pool issue in [[Project Alpha]]
|
|
251
|
+
|
|
252
|
+
## Relations
|
|
253
|
+
|
|
254
|
+
- ← uses [[Project Alpha]]: Main DB
|
|
255
|
+
|
|
256
|
+
## Knowledge
|
|
257
|
+
|
|
258
|
+
**[solution] Connection pool exhaustion fix** (2024-02-10)
|
|
259
|
+
OOM at 200+ WebSocket → Redis cache for UserService
|
|
260
|
+
```yaml
|
|
261
|
+
spring.datasource.hikari.maximum-pool-size: 20
|
|
262
|
+
```
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Configuration
|
|
268
|
+
|
|
269
|
+
```yaml
|
|
270
|
+
# config.yaml
|
|
271
|
+
vault_path: "./vault"
|
|
272
|
+
|
|
273
|
+
llm:
|
|
274
|
+
provider: "anthropic" # anthropic | openai | ollama | mock
|
|
275
|
+
anthropic:
|
|
276
|
+
api_key: "sk-ant-..."
|
|
277
|
+
model: "claude-sonnet-4-20250514"
|
|
278
|
+
|
|
279
|
+
semantic_search:
|
|
280
|
+
enabled: true
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
| Provider | Install | Cost |
|
|
284
|
+
|---|---|---|
|
|
285
|
+
| Anthropic (Claude) | `pip install mengram[anthropic]` | API pricing |
|
|
286
|
+
| OpenAI (GPT) | `pip install mengram[openai]` | API pricing |
|
|
287
|
+
| Ollama (local) | Install [ollama](https://ollama.ai) | Free |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Roadmap
|
|
292
|
+
|
|
293
|
+
- [x] Typed entity extraction (person, project, technology, company)
|
|
294
|
+
- [x] Obsidian vault with `[[wikilinks]]` + YAML frontmatter
|
|
295
|
+
- [x] MCP Server for Claude Desktop
|
|
296
|
+
- [x] Semantic search with local embeddings
|
|
297
|
+
- [x] Hybrid retrieval (vector + graph)
|
|
298
|
+
- [x] Mem0-compatible Python SDK
|
|
299
|
+
- [x] Auto-memory middleware
|
|
300
|
+
- [x] **Rich knowledge extraction (solutions, configs, formulas with code)**
|
|
301
|
+
- [x] **Proactive context (auto-injected via MCP instructions)**
|
|
302
|
+
- [ ] Entity deduplication
|
|
303
|
+
- [ ] Obsidian plugin (TypeScript)
|
|
304
|
+
- [ ] Web dashboard
|
|
305
|
+
- [ ] REST API
|
|
306
|
+
|
|
307
|
+
## Contributing
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
git clone https://github.com/alibaizhanov/mengram
|
|
311
|
+
cd mengram
|
|
312
|
+
pip install -e ".[all,dev]"
|
|
313
|
+
pytest
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## License
|
|
317
|
+
|
|
318
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Mengram MCP Server."""
|