cortexdb-cli 0.3.0__py3-none-any.whl → 0.4.0__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.
- cortexdb_cli/__init__.py +1 -1
- cortexdb_cli/commands/recall.py +121 -99
- {cortexdb_cli-0.3.0.dist-info → cortexdb_cli-0.4.0.dist-info}/METADATA +1 -1
- {cortexdb_cli-0.3.0.dist-info → cortexdb_cli-0.4.0.dist-info}/RECORD +6 -6
- {cortexdb_cli-0.3.0.dist-info → cortexdb_cli-0.4.0.dist-info}/WHEEL +0 -0
- {cortexdb_cli-0.3.0.dist-info → cortexdb_cli-0.4.0.dist-info}/entry_points.txt +0 -0
cortexdb_cli/__init__.py
CHANGED
cortexdb_cli/commands/recall.py
CHANGED
|
@@ -1,99 +1,121 @@
|
|
|
1
|
-
"""cortexdb recall — POST /v1/recall."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from typing import Any
|
|
6
|
-
|
|
7
|
-
import click
|
|
8
|
-
|
|
9
|
-
from cortexdb_cli.client import get_client
|
|
10
|
-
from cortexdb_cli.errors import handle_errors
|
|
11
|
-
from cortexdb_cli.output import is_json_mode, print_recall, spinner
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@click.command("recall")
|
|
15
|
-
@click.argument("query")
|
|
16
|
-
@click.option("--scope", "-S", help="Scope path (defaults to your default scope)")
|
|
17
|
-
@click.option(
|
|
18
|
-
"--view",
|
|
19
|
-
type=click.Choice(["raw", "granular", "structured", "holistic", "descend"]),
|
|
20
|
-
default=None,
|
|
21
|
-
help="Pack shape. Defaults to your configured view (CORTEXDB_VIEW env or "
|
|
22
|
-
"`cortexdb config set view ...`), else 'holistic'. 'descend' = the scope + all "
|
|
23
|
-
"child scopes; 'holistic' = the scope + its parents; 'granular' = exact scope only.",
|
|
24
|
-
)
|
|
25
|
-
@click.option(
|
|
26
|
-
"--include",
|
|
27
|
-
multiple=True,
|
|
28
|
-
type=click.Choice(["events", "episodes", "facts", "beliefs", "understanding"]),
|
|
29
|
-
help="Layers to fill (repeatable). Default: facts + beliefs + episodes.",
|
|
30
|
-
)
|
|
31
|
-
@click.option(
|
|
32
|
-
"--temporal",
|
|
33
|
-
default=None,
|
|
34
|
-
help='Natural-language time window, e.g. "last 30 days".',
|
|
35
|
-
)
|
|
36
|
-
@click.option(
|
|
37
|
-
"--max-tokens",
|
|
38
|
-
type=int,
|
|
39
|
-
default=None,
|
|
40
|
-
help="Budget for the returned context_block (string).",
|
|
41
|
-
)
|
|
42
|
-
@click.option(
|
|
43
|
-
"--diagnostics",
|
|
44
|
-
type=click.Choice(["none", "summary", "full"]),
|
|
45
|
-
default="none",
|
|
46
|
-
show_default=True,
|
|
47
|
-
help='"none" works on every tier. "summary"/"full" need the diagnostics.read capability.',
|
|
48
|
-
)
|
|
49
|
-
@click.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
"""cortexdb recall — POST /v1/recall."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from cortexdb_cli.client import get_client
|
|
10
|
+
from cortexdb_cli.errors import handle_errors
|
|
11
|
+
from cortexdb_cli.output import is_json_mode, print_recall, spinner
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@click.command("recall")
|
|
15
|
+
@click.argument("query")
|
|
16
|
+
@click.option("--scope", "-S", help="Scope path (defaults to your default scope)")
|
|
17
|
+
@click.option(
|
|
18
|
+
"--view",
|
|
19
|
+
type=click.Choice(["raw", "granular", "structured", "holistic", "descend"]),
|
|
20
|
+
default=None,
|
|
21
|
+
help="Pack shape. Defaults to your configured view (CORTEXDB_VIEW env or "
|
|
22
|
+
"`cortexdb config set view ...`), else 'holistic'. 'descend' = the scope + all "
|
|
23
|
+
"child scopes; 'holistic' = the scope + its parents; 'granular' = exact scope only.",
|
|
24
|
+
)
|
|
25
|
+
@click.option(
|
|
26
|
+
"--include",
|
|
27
|
+
multiple=True,
|
|
28
|
+
type=click.Choice(["events", "episodes", "facts", "beliefs", "understanding"]),
|
|
29
|
+
help="Layers to fill (repeatable). Default: facts + beliefs + episodes.",
|
|
30
|
+
)
|
|
31
|
+
@click.option(
|
|
32
|
+
"--temporal",
|
|
33
|
+
default=None,
|
|
34
|
+
help='Natural-language time window, e.g. "last 30 days".',
|
|
35
|
+
)
|
|
36
|
+
@click.option(
|
|
37
|
+
"--max-tokens",
|
|
38
|
+
type=int,
|
|
39
|
+
default=None,
|
|
40
|
+
help="Budget for the returned context_block (string).",
|
|
41
|
+
)
|
|
42
|
+
@click.option(
|
|
43
|
+
"--diagnostics",
|
|
44
|
+
type=click.Choice(["none", "summary", "full"]),
|
|
45
|
+
default="none",
|
|
46
|
+
show_default=True,
|
|
47
|
+
help='"none" works on every tier. "summary"/"full" need the diagnostics.read capability.',
|
|
48
|
+
)
|
|
49
|
+
@click.option(
|
|
50
|
+
"--filter",
|
|
51
|
+
"filters",
|
|
52
|
+
multiple=True,
|
|
53
|
+
metavar="KEY=VALUE",
|
|
54
|
+
help="Hard attribute filter, repeatable (AND across keys, any-of when a "
|
|
55
|
+
"key repeats). Keys: labels, intent, modality, caller, observed_actor. "
|
|
56
|
+
"Example: --filter labels=primary_inbox",
|
|
57
|
+
)
|
|
58
|
+
@click.pass_context
|
|
59
|
+
@handle_errors
|
|
60
|
+
def recall_cmd(
|
|
61
|
+
ctx: click.Context,
|
|
62
|
+
query: str,
|
|
63
|
+
scope: str | None,
|
|
64
|
+
view: str,
|
|
65
|
+
include: tuple[str, ...],
|
|
66
|
+
temporal: str | None,
|
|
67
|
+
max_tokens: int | None,
|
|
68
|
+
diagnostics: str,
|
|
69
|
+
filters: tuple[str, ...],
|
|
70
|
+
) -> None:
|
|
71
|
+
"""Recall context from memory.
|
|
72
|
+
|
|
73
|
+
\b
|
|
74
|
+
cortexdb recall "what did we decide about Acme?"
|
|
75
|
+
cortexdb recall "renewal status" --temporal "last 30 days"
|
|
76
|
+
"""
|
|
77
|
+
cfg = ctx.obj
|
|
78
|
+
view = view or cfg.get("view") or "holistic"
|
|
79
|
+
if view not in ("raw", "granular", "structured", "holistic", "descend"):
|
|
80
|
+
raise click.UsageError(
|
|
81
|
+
f"Invalid view {view!r}. Choose: raw, granular, structured, holistic, descend."
|
|
82
|
+
)
|
|
83
|
+
target_scope = scope or cfg.get("scope") or cfg.get("actor")
|
|
84
|
+
if not target_scope:
|
|
85
|
+
raise click.UsageError(
|
|
86
|
+
"No scope configured. Run `cortexdb init` first, or pass --scope explicitly."
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
body: dict[str, Any] = {
|
|
90
|
+
"scope": target_scope,
|
|
91
|
+
"view": view,
|
|
92
|
+
"query": query,
|
|
93
|
+
"diagnostics": diagnostics,
|
|
94
|
+
}
|
|
95
|
+
if include:
|
|
96
|
+
body["include"] = list(include)
|
|
97
|
+
if temporal:
|
|
98
|
+
body["temporal"] = {"natural": temporal}
|
|
99
|
+
if max_tokens is not None:
|
|
100
|
+
body["budgets"] = {"max_tokens": max_tokens}
|
|
101
|
+
if filters:
|
|
102
|
+
fmap: dict[str, Any] = {}
|
|
103
|
+
for f in filters:
|
|
104
|
+
if "=" not in f:
|
|
105
|
+
raise click.UsageError(f"--filter must be KEY=VALUE, got {f!r}")
|
|
106
|
+
k, v = f.split("=", 1)
|
|
107
|
+
if k in fmap:
|
|
108
|
+
prev = fmap[k] if isinstance(fmap[k], list) else [fmap[k]]
|
|
109
|
+
fmap[k] = prev + [v]
|
|
110
|
+
else:
|
|
111
|
+
fmap[k] = v
|
|
112
|
+
body["filters"] = {"metadata": fmap}
|
|
113
|
+
|
|
114
|
+
with get_client(cfg) as client:
|
|
115
|
+
if not is_json_mode(cfg):
|
|
116
|
+
with spinner("Recalling..."):
|
|
117
|
+
resp = client.post("/v1/recall", json=body)
|
|
118
|
+
else:
|
|
119
|
+
resp = client.post("/v1/recall", json=body)
|
|
120
|
+
resp.raise_for_status()
|
|
121
|
+
print_recall(resp.json(), cfg)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cortexdb_cli/__init__.py,sha256=
|
|
1
|
+
cortexdb_cli/__init__.py,sha256=DGPDvdCGq9U0gNcwMV7qmJCGEGpdy28_Fb86_vPPl3U,92
|
|
2
2
|
cortexdb_cli/client.py,sha256=_T_DUBkuUB63xrLy7NZeveKZPWnihGzpNJmStUWv48w,2958
|
|
3
3
|
cortexdb_cli/config.py,sha256=CA_bYOlV_zhurAfTvA9F_W7hOfsMbbZb_WFmMq9SJkM,3909
|
|
4
4
|
cortexdb_cli/errors.py,sha256=xwxAWYY7KtNa-e7dyLQECnsKcciVcKC41CXFFF_-0VU,3924
|
|
@@ -24,11 +24,11 @@ cortexdb_cli/commands/import_cmd.py,sha256=gBNnzFtXVH8YWD8b1J7r98oY3USK0WwOq9DP5
|
|
|
24
24
|
cortexdb_cli/commands/init.py,sha256=HHC2qkrMuRO8zaNKgua_99IvSM5elEOhbjsaMBo-VFA,3130
|
|
25
25
|
cortexdb_cli/commands/interactive.py,sha256=DmkVFMz0ZX9MqrXSDiAtypAAqykg4h8SW_UWCJRcyRk,9772
|
|
26
26
|
cortexdb_cli/commands/policy.py,sha256=SXwX4g1maBS6MF3yXkonbmqCVIoN-AwSfDiC1ew7dDM,3461
|
|
27
|
-
cortexdb_cli/commands/recall.py,sha256=
|
|
27
|
+
cortexdb_cli/commands/recall.py,sha256=pPeotJtq3fTwwVCBaU1SGmEOV6iV3v6sfo5RLiEx5PY,3845
|
|
28
28
|
cortexdb_cli/commands/scopes.py,sha256=-nmSnIXyGq6ZhvoFRoLULk5XL05_TkLoqZJzXr92vSY,3150
|
|
29
29
|
cortexdb_cli/commands/search.py,sha256=H-qWDApZa7KehG64tU4aWreTo6oPcUBmIJhMIh50SH0,2021
|
|
30
30
|
cortexdb_cli/commands/understanding.py,sha256=zaOXamWYJf-e4iVPsAWX91RHdi54x3YTPeIhn9uhSUE,5533
|
|
31
|
-
cortexdb_cli-0.
|
|
32
|
-
cortexdb_cli-0.
|
|
33
|
-
cortexdb_cli-0.
|
|
34
|
-
cortexdb_cli-0.
|
|
31
|
+
cortexdb_cli-0.4.0.dist-info/METADATA,sha256=7jXgwFqdMcbYslk3LfAm_WNZyQ6LGXFYGpkui6B8Sn0,4429
|
|
32
|
+
cortexdb_cli-0.4.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
33
|
+
cortexdb_cli-0.4.0.dist-info/entry_points.txt,sha256=h3sEbdqqvtv8LBbRLUgybYPo9N2lpU85fQUSh5ToEvs,51
|
|
34
|
+
cortexdb_cli-0.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|