Seed existing MEMORY.md knowledge into Mem0#317
Conversation
Review by KaiPR Review: Seed MEMORY.md into Mem0Overall the implementation is clean and well-reasoned. A few real issues below. Warning1. Test isolation - Every test that sets
Both pass only if 2. Missing memory directory not explicitly handled for path in sorted(target_dir.glob("*.md")):On Python < 3.12, Suggestion3. Redundant skip list in if filename in ("MEMORY.md", "api-reference.md"):
return None
return mapping.get(filename)Neither 4. Bare if stripped.startswith("#"):
current_heading = stripped.lstrip("#").strip()A line like 5. Integration tests copy-paste production logic The four tests inline a verbatim copy of the seed block from No security issues found. The flag-key format ( |
Review by KaiPR Review: Seed MEMORY.md into Mem0All three warnings/suggestions from the prior review have been addressed: the missing directory guard is present, the redundant skip-list in One new finding below. SuggestionHeading detection is asymmetric for ATX headings without a space if stripped.startswith("# ") or (len(stripped) > 1 and stripped[0] == "#" and stripped[1] == "#"):The fix correctly rejects No other new issues. The implementation is solid: the thread-executor offload is correct, partial-failure retry logic is sound, per-user flag isolation is correct, and the 38-test suite covers the meaningful paths including the new missing-directory guard and the bare-hash edge case. No security issues found. |
Review by KaiPR Review: Seed MEMORY.md into Mem0The heading detection fix ( Two new findings below. Warning
try:
entries = _parse_topic_file(path)
except OSError:
counts["failed"] += 1
continue
Suggestion
def _is_duplicate(content: str, *, user_id: str, threshold: float = 0.9) -> bool:
results = search(content, user_id=user_id, limit=1) # no try-except
if not results:
return False
return results[0].score >= thresholdThe docstring says failures return No security issues. Logic is sound - the partial-failure retry design, per-user flag isolation, thread-executor offload, and dedup threshold are all correct. |
Review by KaiPR Review: Seed MEMORY.md into Mem0 (Round 4)All three issues from the prior round are correctly addressed:
No new critical issues or warnings found. Suggestion
patch("kai.sessions.get_setting", mock_get_setting),
No security issues. The thread-executor offload, per-user flag isolation, partial-failure retry design, dedup threshold, and missing-directory guard are all correct. The 38-test suite is thorough and the |
Review by KaiPR Review: Seed MEMORY.md into Mem0 (Round 5)All findings from prior rounds have been addressed. One new finding below. Suggestion
def mock_search(query, **kwargs):
for s in stored:
if s["memory"] == query:
return {"results": [{"id": s["id"], "memory": s["memory"], "score": 0.95, ...}]}
return {"results": []}
No new bugs, logic errors, or security issues. The |
Summary
Seeds existing MEMORY.md topic files into the Mem0 semantic memory store at startup, bridging the gap between Kai's structured markdown memory and the new vector-based search layer.
add_structured()for explicit Track 2 ingestion (infer=False) with type/tag metadataseed_from_memory_md()which parses topic files, classifies them by type, deduplicates via cosine similarity, and stores entries per-usermemory_seeded:<user_id>flag in settings table)Implementation details
memory.py - 5 new functions:
add_structured()- stores content withinfer=False, builds metadata with type/tags/source_classify_source_file()- maps known files to memory types (fact/preference), skips index/api-reference_parse_topic_file()- markdown parser handling bullets, paragraphs, headings, code blocks_is_duplicate()- top-1 cosine similarity search with 0.9 thresholdseed_from_memory_md()- orchestrator iterating users x topic files with per-entry dedupmain.py - startup migration block:
memory_seeded:<user_id>flag per allowed userTest plan
TestAddStructured(10 tests) - fact/preference/custom types, metadata, tags, edge casesTestParseTopicFile(6 tests) - bullets, headings, paragraphs, code blocks, empty filesTestClassifySourceFile(3 tests) - known files, skip files, unknown filesTestSeedFromMemoryMd(15 tests) - full seeding flow, idempotency, multi-user, partial failureTestMemorySeedIntegration(4 tests) - startup flag logic, skip-when-present, failure handlingmake checkclean (ruff check + format)Closes #311