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.
- memdream/__init__.py +70 -0
- memdream/__main__.py +109 -0
- memdream/client.py +861 -0
- memdream/embedded.py +977 -0
- memdream/engine/__init__.py +7 -0
- memdream/engine/api/__init__.py +0 -0
- memdream/engine/api/deps.py +138 -0
- memdream/engine/api/routes_dream.py +165 -0
- memdream/engine/api/routes_health.py +94 -0
- memdream/engine/api/routes_memory.py +348 -0
- memdream/engine/api/routes_search.py +73 -0
- memdream/engine/container.py +319 -0
- memdream/engine/core/__init__.py +0 -0
- memdream/engine/core/auth.py +195 -0
- memdream/engine/core/config.py +798 -0
- memdream/engine/core/exceptions.py +83 -0
- memdream/engine/core/identity.py +157 -0
- memdream/engine/core/logging.py +151 -0
- memdream/engine/core/metrics.py +328 -0
- memdream/engine/core/policy.py +114 -0
- memdream/engine/core/prompts.py +197 -0
- memdream/engine/core/shorthand.py +189 -0
- memdream/engine/dream/__init__.py +6 -0
- memdream/engine/dream/candidate_selector.py +147 -0
- memdream/engine/dream/clustering.py +120 -0
- memdream/engine/dream/compaction.py +259 -0
- memdream/engine/dream/consolidation.py +377 -0
- memdream/engine/dream/engine.py +671 -0
- memdream/engine/dream/merge.py +175 -0
- memdream/engine/dream/prompts.py +145 -0
- memdream/engine/dream/scheduler.py +155 -0
- memdream/engine/dream/service.py +236 -0
- memdream/engine/dream/supersede.py +150 -0
- memdream/engine/dream/synthesis.py +561 -0
- memdream/engine/dream/validation.py +146 -0
- memdream/engine/main.py +218 -0
- memdream/engine/memory/__init__.py +1 -0
- memdream/engine/memory/extractor.py +144 -0
- memdream/engine/memory/lifecycle.py +349 -0
- memdream/engine/memory/ranker.py +126 -0
- memdream/engine/memory/retriever.py +320 -0
- memdream/engine/memory/service.py +563 -0
- memdream/engine/memory/triage.py +115 -0
- memdream/engine/models/__init__.py +31 -0
- memdream/engine/models/dream.py +444 -0
- memdream/engine/models/enums.py +141 -0
- memdream/engine/models/memory.py +347 -0
- memdream/engine/models/requests.py +366 -0
- memdream/engine/models/scope.py +190 -0
- memdream/engine/providers/__init__.py +6 -0
- memdream/engine/providers/embeddings/__init__.py +4 -0
- memdream/engine/providers/embeddings/_openai_style.py +174 -0
- memdream/engine/providers/embeddings/azure_openai.py +66 -0
- memdream/engine/providers/embeddings/base.py +77 -0
- memdream/engine/providers/embeddings/factory.py +33 -0
- memdream/engine/providers/embeddings/fake.py +119 -0
- memdream/engine/providers/embeddings/gemini.py +154 -0
- memdream/engine/providers/embeddings/openai_compatible.py +140 -0
- memdream/engine/providers/llm/__init__.py +4 -0
- memdream/engine/providers/llm/_openai_style.py +264 -0
- memdream/engine/providers/llm/anthropic.py +244 -0
- memdream/engine/providers/llm/azure_openai.py +63 -0
- memdream/engine/providers/llm/base.py +203 -0
- memdream/engine/providers/llm/factory.py +40 -0
- memdream/engine/providers/llm/fake.py +674 -0
- memdream/engine/providers/llm/gemini.py +222 -0
- memdream/engine/providers/llm/openai_compatible.py +155 -0
- memdream/engine/providers/queue/__init__.py +4 -0
- memdream/engine/providers/queue/base.py +37 -0
- memdream/engine/providers/queue/database_queue.py +114 -0
- memdream/engine/providers/queue/factory.py +36 -0
- memdream/engine/providers/queue/inline_queue.py +266 -0
- memdream/engine/providers/vector_store/__init__.py +4 -0
- memdream/engine/providers/vector_store/_scope_keys.py +92 -0
- memdream/engine/providers/vector_store/azure_search_store.py +271 -0
- memdream/engine/providers/vector_store/base.py +93 -0
- memdream/engine/providers/vector_store/chroma_store.py +204 -0
- memdream/engine/providers/vector_store/factory.py +104 -0
- memdream/engine/providers/vector_store/faiss_store.py +447 -0
- memdream/engine/providers/vector_store/memory_store.py +107 -0
- memdream/engine/providers/vector_store/milvus_store.py +223 -0
- memdream/engine/providers/vector_store/pgvector_store.py +243 -0
- memdream/engine/providers/vector_store/pinecone_store.py +210 -0
- memdream/engine/providers/vector_store/qdrant_store.py +245 -0
- memdream/engine/repositories/__init__.py +23 -0
- memdream/engine/repositories/base.py +471 -0
- memdream/engine/repositories/factory.py +106 -0
- memdream/engine/repositories/mongo/__init__.py +36 -0
- memdream/engine/repositories/mongo/audit.py +140 -0
- memdream/engine/repositories/mongo/database.py +263 -0
- memdream/engine/repositories/mongo/jobs.py +177 -0
- memdream/engine/repositories/mongo/memories.py +632 -0
- memdream/engine/repositories/postgres/__init__.py +37 -0
- memdream/engine/repositories/postgres/_sql.py +116 -0
- memdream/engine/repositories/postgres/audit.py +160 -0
- memdream/engine/repositories/postgres/database.py +324 -0
- memdream/engine/repositories/postgres/jobs.py +185 -0
- memdream/engine/repositories/postgres/memories.py +734 -0
- memdream/engine/workers/__init__.py +0 -0
- memdream/engine/workers/synthesis_worker.py +199 -0
- memdream/exceptions.py +81 -0
- memdream/models.py +293 -0
- memdream/templates/prompts/README.md +41 -0
- memdream/templates/prompts/compaction.md +11 -0
- memdream/templates/prompts/decision.md +23 -0
- memdream/templates/prompts/extraction.md +19 -0
- memdream/templates/prompts/merge.md +17 -0
- memdream/templates/prompts/supersede.md +13 -0
- memdream/templates/prompts/synthesis.md +25 -0
- memdream-0.1.1.dist-info/METADATA +562 -0
- memdream-0.1.1.dist-info/RECORD +113 -0
- memdream-0.1.1.dist-info/WHEEL +4 -0
- 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())
|