memdream 0.1.1__py3-none-any.whl

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.
Files changed (113) hide show
  1. memdream/__init__.py +70 -0
  2. memdream/__main__.py +109 -0
  3. memdream/client.py +861 -0
  4. memdream/embedded.py +977 -0
  5. memdream/engine/__init__.py +7 -0
  6. memdream/engine/api/__init__.py +0 -0
  7. memdream/engine/api/deps.py +138 -0
  8. memdream/engine/api/routes_dream.py +165 -0
  9. memdream/engine/api/routes_health.py +94 -0
  10. memdream/engine/api/routes_memory.py +348 -0
  11. memdream/engine/api/routes_search.py +73 -0
  12. memdream/engine/container.py +319 -0
  13. memdream/engine/core/__init__.py +0 -0
  14. memdream/engine/core/auth.py +195 -0
  15. memdream/engine/core/config.py +798 -0
  16. memdream/engine/core/exceptions.py +83 -0
  17. memdream/engine/core/identity.py +157 -0
  18. memdream/engine/core/logging.py +151 -0
  19. memdream/engine/core/metrics.py +328 -0
  20. memdream/engine/core/policy.py +114 -0
  21. memdream/engine/core/prompts.py +197 -0
  22. memdream/engine/core/shorthand.py +189 -0
  23. memdream/engine/dream/__init__.py +6 -0
  24. memdream/engine/dream/candidate_selector.py +147 -0
  25. memdream/engine/dream/clustering.py +120 -0
  26. memdream/engine/dream/compaction.py +259 -0
  27. memdream/engine/dream/consolidation.py +377 -0
  28. memdream/engine/dream/engine.py +671 -0
  29. memdream/engine/dream/merge.py +175 -0
  30. memdream/engine/dream/prompts.py +145 -0
  31. memdream/engine/dream/scheduler.py +155 -0
  32. memdream/engine/dream/service.py +236 -0
  33. memdream/engine/dream/supersede.py +150 -0
  34. memdream/engine/dream/synthesis.py +561 -0
  35. memdream/engine/dream/validation.py +146 -0
  36. memdream/engine/main.py +218 -0
  37. memdream/engine/memory/__init__.py +1 -0
  38. memdream/engine/memory/extractor.py +144 -0
  39. memdream/engine/memory/lifecycle.py +349 -0
  40. memdream/engine/memory/ranker.py +126 -0
  41. memdream/engine/memory/retriever.py +320 -0
  42. memdream/engine/memory/service.py +563 -0
  43. memdream/engine/memory/triage.py +115 -0
  44. memdream/engine/models/__init__.py +31 -0
  45. memdream/engine/models/dream.py +444 -0
  46. memdream/engine/models/enums.py +141 -0
  47. memdream/engine/models/memory.py +347 -0
  48. memdream/engine/models/requests.py +366 -0
  49. memdream/engine/models/scope.py +190 -0
  50. memdream/engine/providers/__init__.py +6 -0
  51. memdream/engine/providers/embeddings/__init__.py +4 -0
  52. memdream/engine/providers/embeddings/_openai_style.py +174 -0
  53. memdream/engine/providers/embeddings/azure_openai.py +66 -0
  54. memdream/engine/providers/embeddings/base.py +77 -0
  55. memdream/engine/providers/embeddings/factory.py +33 -0
  56. memdream/engine/providers/embeddings/fake.py +119 -0
  57. memdream/engine/providers/embeddings/gemini.py +154 -0
  58. memdream/engine/providers/embeddings/openai_compatible.py +140 -0
  59. memdream/engine/providers/llm/__init__.py +4 -0
  60. memdream/engine/providers/llm/_openai_style.py +264 -0
  61. memdream/engine/providers/llm/anthropic.py +244 -0
  62. memdream/engine/providers/llm/azure_openai.py +63 -0
  63. memdream/engine/providers/llm/base.py +203 -0
  64. memdream/engine/providers/llm/factory.py +40 -0
  65. memdream/engine/providers/llm/fake.py +674 -0
  66. memdream/engine/providers/llm/gemini.py +222 -0
  67. memdream/engine/providers/llm/openai_compatible.py +155 -0
  68. memdream/engine/providers/queue/__init__.py +4 -0
  69. memdream/engine/providers/queue/base.py +37 -0
  70. memdream/engine/providers/queue/database_queue.py +114 -0
  71. memdream/engine/providers/queue/factory.py +36 -0
  72. memdream/engine/providers/queue/inline_queue.py +266 -0
  73. memdream/engine/providers/vector_store/__init__.py +4 -0
  74. memdream/engine/providers/vector_store/_scope_keys.py +92 -0
  75. memdream/engine/providers/vector_store/azure_search_store.py +271 -0
  76. memdream/engine/providers/vector_store/base.py +93 -0
  77. memdream/engine/providers/vector_store/chroma_store.py +204 -0
  78. memdream/engine/providers/vector_store/factory.py +104 -0
  79. memdream/engine/providers/vector_store/faiss_store.py +447 -0
  80. memdream/engine/providers/vector_store/memory_store.py +107 -0
  81. memdream/engine/providers/vector_store/milvus_store.py +223 -0
  82. memdream/engine/providers/vector_store/pgvector_store.py +243 -0
  83. memdream/engine/providers/vector_store/pinecone_store.py +210 -0
  84. memdream/engine/providers/vector_store/qdrant_store.py +245 -0
  85. memdream/engine/repositories/__init__.py +23 -0
  86. memdream/engine/repositories/base.py +471 -0
  87. memdream/engine/repositories/factory.py +106 -0
  88. memdream/engine/repositories/mongo/__init__.py +36 -0
  89. memdream/engine/repositories/mongo/audit.py +140 -0
  90. memdream/engine/repositories/mongo/database.py +263 -0
  91. memdream/engine/repositories/mongo/jobs.py +177 -0
  92. memdream/engine/repositories/mongo/memories.py +632 -0
  93. memdream/engine/repositories/postgres/__init__.py +37 -0
  94. memdream/engine/repositories/postgres/_sql.py +116 -0
  95. memdream/engine/repositories/postgres/audit.py +160 -0
  96. memdream/engine/repositories/postgres/database.py +324 -0
  97. memdream/engine/repositories/postgres/jobs.py +185 -0
  98. memdream/engine/repositories/postgres/memories.py +734 -0
  99. memdream/engine/workers/__init__.py +0 -0
  100. memdream/engine/workers/synthesis_worker.py +199 -0
  101. memdream/exceptions.py +81 -0
  102. memdream/models.py +293 -0
  103. memdream/templates/prompts/README.md +41 -0
  104. memdream/templates/prompts/compaction.md +11 -0
  105. memdream/templates/prompts/decision.md +23 -0
  106. memdream/templates/prompts/extraction.md +19 -0
  107. memdream/templates/prompts/merge.md +17 -0
  108. memdream/templates/prompts/supersede.md +13 -0
  109. memdream/templates/prompts/synthesis.md +25 -0
  110. memdream-0.1.1.dist-info/METADATA +562 -0
  111. memdream-0.1.1.dist-info/RECORD +113 -0
  112. memdream-0.1.1.dist-info/WHEEL +4 -0
  113. memdream-0.1.1.dist-info/licenses/LICENSE +201 -0
memdream/__init__.py ADDED
@@ -0,0 +1,70 @@
1
+ """The MemDream Python SDK.
2
+
3
+ Two ways in, one surface.
4
+
5
+ **Embedded** — MemDream runs inside your process. No server, no worker::
6
+
7
+ from memdream import MemDream
8
+
9
+ mem = MemDream(user_id="alice")
10
+ mem.add("I moved to Bangalore last month.")
11
+ print(mem.search("where do they live?").as_context())
12
+
13
+ **Hosted** — talk to a running MemDream over HTTP::
14
+
15
+ from memdream import DreamClient
16
+
17
+ mem = DreamClient("https://memory.internal", api_key="...", user_id="alice")
18
+ mem.add("I moved to Bangalore last month.")
19
+
20
+ The method names, arguments and return types are identical, so moving from a
21
+ prototype to a deployed service changes the constructor line and nothing else.
22
+ Both also answer to `.memory` and `.dream` for the namespaced call style.
23
+
24
+ Async equivalents are `AsyncMemDream` and `AsyncDreamClient`.
25
+
26
+ `DreamClient` needs only `httpx`. `MemDream` needs the full package, since it
27
+ builds the engine rather than calling it.
28
+ """
29
+
30
+ from memdream.client import AsyncDreamClient, DreamClient
31
+ from memdream.embedded import AsyncMemDream, MemDream
32
+ from memdream.exceptions import (
33
+ DreamAPIError,
34
+ DreamAuthError,
35
+ DreamConnectionError,
36
+ DreamNotFoundError,
37
+ DreamValidationError,
38
+ )
39
+ from memdream.models import (
40
+ AddResult,
41
+ ConsolidationReport,
42
+ DecisionResult,
43
+ DreamJob,
44
+ MemoryDetail,
45
+ MemoryRecord,
46
+ RelatedMemory,
47
+ SearchResult,
48
+ )
49
+
50
+ __version__ = "0.1.1"
51
+
52
+ __all__ = [
53
+ "AddResult",
54
+ "AsyncDreamClient",
55
+ "AsyncMemDream",
56
+ "ConsolidationReport",
57
+ "DecisionResult",
58
+ "DreamAPIError",
59
+ "DreamAuthError",
60
+ "DreamClient",
61
+ "DreamConnectionError",
62
+ "DreamJob",
63
+ "DreamNotFoundError",
64
+ "DreamValidationError",
65
+ "MemDream",
66
+ "MemoryDetail",
67
+ "MemoryRecord",
68
+ "RelatedMemory",
69
+ "SearchResult",
70
+ ]
memdream/__main__.py ADDED
@@ -0,0 +1,109 @@
1
+ """MemDream's command line.
2
+
3
+ python -m memdream prompts ./prompts copy the starter prompts to edit
4
+ python -m memdream prompts --list show what each prompt decides
5
+
6
+ MemDream ships no prompts: every deployment writes its own, because what is
7
+ worth remembering depends on the product. That makes "where do I start?" the
8
+ first question anyone has, and this is the answer — a set of working prompts,
9
+ copied into your project, yours to edit.
10
+
11
+ They are templates, not defaults. Nothing loads them until you point
12
+ `DREAM_PROMPTS_DIR` (or `MemDream(prompts=...)`) at the directory.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ import shutil
19
+ import sys
20
+ from pathlib import Path
21
+
22
+ #: Copied verbatim from the repository into the wheel at build time.
23
+ TEMPLATE_PACKAGE_DIR = Path(__file__).resolve().parent / "templates" / "prompts"
24
+ #: Running from a checkout, where the templates are still at the repo root.
25
+ TEMPLATE_REPO_DIR = Path(__file__).resolve().parent.parent / "prompts"
26
+
27
+
28
+ def template_dir() -> Path:
29
+ for candidate in (TEMPLATE_PACKAGE_DIR, TEMPLATE_REPO_DIR):
30
+ if candidate.is_dir() and any(candidate.glob("*.md")):
31
+ return candidate
32
+ raise SystemExit(
33
+ "Starter prompts are not bundled with this install. Copy them from\n"
34
+ "https://github.com/Mamlesh18/MemDream/tree/main/prompts"
35
+ )
36
+
37
+
38
+ def copy_prompts(target: Path, *, force: bool = False) -> int:
39
+ source = template_dir()
40
+ target.mkdir(parents=True, exist_ok=True)
41
+
42
+ from memdream.engine.core.prompts import PROMPT_NAMES
43
+
44
+ # Named rather than globbed, so what lands in the directory is exactly the
45
+ # set MemDream can ask for. The README beside them comes too, as its
46
+ # documentation.
47
+ written, skipped = [], []
48
+ for name in [f"{prompt}.md" for prompt in PROMPT_NAMES] + ["README.md"]:
49
+ path = source / name
50
+ if not path.is_file():
51
+ continue
52
+ destination = target / name
53
+ # Never overwrite an edited prompt: this command is run again whenever
54
+ # someone forgets whether they already have them.
55
+ if destination.exists() and not force:
56
+ skipped.append(name)
57
+ continue
58
+ shutil.copyfile(path, destination)
59
+ written.append(name)
60
+
61
+ for name in written:
62
+ print(f" wrote {target / name}")
63
+ for name in skipped:
64
+ print(f" kept {target / name} (already there; --force to replace)")
65
+
66
+ if written:
67
+ copied = [name for name in written if name != "README.md"]
68
+ print(f"\n{len(copied)} prompt(s) copied. Now point MemDream at them:")
69
+ print(f" DREAM_PROMPTS_DIR={target}")
70
+ print(f" MemDream(prompts={str(target)!r})")
71
+ print("\nThey work as they are. Edit them for your product — start with")
72
+ print("extraction.md, which decides what is worth remembering at all.")
73
+ elif skipped:
74
+ print(f"\nNothing to do: {target} already has prompts.")
75
+ return 0
76
+
77
+
78
+ def list_prompts() -> int:
79
+ from memdream.engine.core.prompts import PROMPT_PURPOSE
80
+
81
+ print("MemDream asks for these prompts. Which are required depends on your")
82
+ print("configuration: staged decisions need supersede + merge instead of")
83
+ print("decision, and synthesis and compaction only when enabled.\n")
84
+ for name, purpose in PROMPT_PURPOSE.items():
85
+ print(f" {name:<11} {purpose}")
86
+ print("\nEach must return the JSON shape MemDream appends to your prompt;")
87
+ print("see docs/prompts.md.")
88
+ return 0
89
+
90
+
91
+ def main(argv: list[str] | None = None) -> int:
92
+ parser = argparse.ArgumentParser(prog="memdream", description=__doc__.split("\n")[0])
93
+ subcommands = parser.add_subparsers(dest="command", required=True)
94
+
95
+ prompts = subcommands.add_parser("prompts", help="copy the starter prompts")
96
+ prompts.add_argument("directory", nargs="?", default="./prompts",
97
+ help="where to copy them (default: ./prompts)")
98
+ prompts.add_argument("--force", action="store_true", help="overwrite existing files")
99
+ prompts.add_argument("--list", action="store_true", dest="show",
100
+ help="list the prompts and what each decides")
101
+
102
+ args = parser.parse_args(argv)
103
+ if args.command == "prompts":
104
+ return list_prompts() if args.show else copy_prompts(Path(args.directory), force=args.force)
105
+ return 1
106
+
107
+
108
+ if __name__ == "__main__":
109
+ sys.exit(main())