korely-memory 0.1.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.
@@ -0,0 +1,98 @@
1
+ # ── Backups (PII — never commit) ──────────────────────
2
+ backups/
3
+
4
+ # ── Python ────────────────────────────────────────────
5
+ __pycache__/
6
+ *.py[cod]
7
+ *.egg-info/
8
+ .env
9
+ .env.local
10
+ .env.*.local
11
+ .env.production
12
+ .env.staging
13
+ # But keep .env.example
14
+ !.env.example
15
+ .venv/
16
+ venv/
17
+ # ── Node / React ──────────────────────────────────────
18
+ node_modules/
19
+ dist/
20
+ .build/
21
+ # ── VSCode / IDE files ────────────────────────────────
22
+ .vscode/
23
+ .idea/
24
+ # ── Cursor / Claude Code / agenti (auto-generated skills, debug logs) ──
25
+ .agents/skills/
26
+ .cursor/skills/
27
+ .cursor/debug*.log
28
+ .cursor/*.log
29
+ .adal
30
+ .agent
31
+ .augment
32
+ .claude
33
+ .cline
34
+ .codebuddy
35
+ .commandcode
36
+ .continue
37
+ .crush
38
+ .factory
39
+ .goose
40
+ .iflow
41
+ .junie
42
+ .kilocode
43
+ .kiro
44
+ .kode
45
+ .mcpjam
46
+ .mux
47
+ .neovate
48
+ .openhands
49
+ .pi
50
+ .pochi
51
+ .qoder
52
+ .qwen
53
+ .roo
54
+ .trae
55
+ .vibe
56
+ .windsurf
57
+ .zencoder
58
+ # ── OS / Misc ─────────────────────────────────────────
59
+ .DS_Store
60
+ Thumbs.db
61
+ app_logs.txt
62
+ test_*.log
63
+ # ── Docker ───────────────────────────────────────────
64
+ **/db_data/
65
+ # ── Security / Deployment ────────────────────────────
66
+ *.pem
67
+ *.key
68
+ *.p12
69
+ *firebase*adminsdk*.json
70
+ scripts/.env.*
71
+ **/secrets/
72
+ ghp_*
73
+ *token*
74
+ *.token
75
+ # Exceptions: source files, not secrets
76
+ !backend/app/services/token_service.py
77
+ !backend/app/services/token_tracking.py
78
+ !backend/app/services/token_encryption.py
79
+ !frontend/src/components/TokenUsageDashboard.tsx
80
+ !backend/alembic/versions/step16_token_usage_table.py
81
+ !backend/alembic/versions/a4a1c714fbee_add_thoughts_tokens_to_api_usage_logs.py
82
+ !backend/alembic/versions/tiers004_token_based_allowances.py
83
+ !backend/alembic/versions/billing002_setup_pack_tokens_purchased.py
84
+ # MacOS
85
+ .DS_Store
86
+ *\ 2.*
87
+ *\ 2
88
+ # Desktop test runner artifacts
89
+ .last-run*.json
90
+ # Local dev media (uploads stored in R2 in production)
91
+ backend/media/
92
+ backend/Render log/
93
+ .gstack/
94
+
95
+ # BigQuery / GCP billing exports (analisi locali, non versionare)
96
+ bquxjob_*.csv
97
+ *.bq.csv
98
+ .snapshots/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Korely
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,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: korely-memory
3
+ Version: 0.1.0
4
+ Summary: Python SDK for Korely Agents — memory for AI agents with bi-temporal typed facts.
5
+ Project-URL: Homepage, https://korely.ai/agents
6
+ Project-URL: Documentation, https://korely.ai/agents/docs/surfaces/sdk
7
+ Project-URL: API Reference, https://korely.ai/agents/docs/api-reference
8
+ Author: Korely
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,knowledge-graph,llm,memory,rag
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+
24
+ # korely-memory
25
+
26
+ The Python SDK for [Korely Agents](https://korely.ai/agents) — memory for AI
27
+ agents, with bi-temporal typed facts and contradiction checking built in.
28
+
29
+ A typed, **zero-dependency** client over the Korely REST API. Every method maps
30
+ 1:1 onto an endpoint, so anything you can do with curl you can do here, and the
31
+ JSON shapes in the [API reference](https://korely.ai/agents/docs/api-reference)
32
+ are the attribute shapes you get back. All the intelligence — embeddings, entity
33
+ and typed-fact extraction, contradiction checking, bi-temporal validity — runs
34
+ server-side, so your install stays small and your process stays light.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ pip install korely-memory
40
+ ```
41
+
42
+ Python 3.9 or later.
43
+
44
+ ## Quickstart
45
+
46
+ ```python
47
+ from korely_memory import Korely
48
+
49
+ korely = Korely(api_key="kor_live_...", region="eu")
50
+ # or read the key from the environment (KORELY_API_KEY)
51
+ korely = Korely(region="eu")
52
+
53
+ # Remember — the write path extracts facts and resolves contradictions
54
+ korely.add("User prefers TypeScript with strict mode", agent_id="coding-assistant")
55
+ korely.add("Actually I switched to Rust", agent_id="coding-assistant")
56
+
57
+ # Recall — superseded facts drop out automatically
58
+ for hit in korely.search("user's preferred language", limit=5):
59
+ print(hit.id, hit.score, hit.snippet)
60
+
61
+ # One-call, prompt-ready context for your LLM
62
+ ctx = korely.get_context(query="plan the project", user_id="dana", token_budget=800)
63
+ messages = [{"role": "system", "content": f"You are helpful.\n\n{ctx.context}"}]
64
+ ```
65
+
66
+ ## Methods
67
+
68
+ Every method wraps exactly one REST endpoint.
69
+
70
+ | Method | Endpoint |
71
+ |---|---|
72
+ | `add(content, *, agent_id=, user_id=, run_id=, metadata=)` | `POST /v1/memories` |
73
+ | `search(query, *, user_id=, agent_id=, limit=)` | `POST /v1/memories/search` |
74
+ | `get_all(*, user_id=, agent_id=, limit=, offset=)` | `GET /v1/memories` |
75
+ | `get(memory_id)` | `GET /v1/memories/:id` |
76
+ | `update(memory_id, *, content, expected_updated_at=)` | `PATCH /v1/memories/:id` |
77
+ | `delete(memory_id)` | `DELETE /v1/memories/:id` |
78
+ | `delete_all(*, user_id)` | `DELETE /v1/users/:user_id/memories` |
79
+ | `get_facts(*, subject=, entity=, predicate=, predicate_family=, include_invalidated=, as_of=, …)` | `GET /v1/facts` |
80
+ | `get_context(*, query, user_id=, agent_id=, token_budget=)` | `GET /v1/context` |
81
+ | `batch(memories)` | `POST /v1/batch` |
82
+ | `batch_status(job_id)` | `GET /v1/batch/:id` |
83
+
84
+ ## Bi-temporal facts
85
+
86
+ The differentiator: typed `(subject, predicate, object)` facts with validity over
87
+ time. Ask what was true on any date.
88
+
89
+ ```python
90
+ # Current state
91
+ facts = korely.get_facts(entity="Northwind Hosting")
92
+ print(facts[0].object) # 50 euro per month
93
+ print(facts[0].invalid_at) # None — active
94
+
95
+ # Point-in-time: what did we believe on June 1?
96
+ facts = korely.get_facts(entity="Northwind Hosting", as_of="2026-06-01")
97
+ print(facts[0].object) # 40 euro per month
98
+ ```
99
+
100
+ ## Scoping
101
+
102
+ Three identifiers, three levels of scope — the same everywhere (SDK, REST, MCP):
103
+
104
+ - `agent_id` — your application or agent (one namespace per product surface)
105
+ - `user_id` — your end user (free-form string; **unlimited on every tier**)
106
+ - `run_id` — one session or run (sub-scope inside a user)
107
+
108
+ ```python
109
+ korely.add("Asked to be contacted on Slack", agent_id="support-bot", user_id="customer-4812")
110
+ results = korely.search("contact preference", user_id="customer-4812")
111
+ ```
112
+
113
+ > Always pass `user_id` on reads in multi-tenant products. Filters are additive
114
+ > (AND); a search without `user_id` spans every end user in the namespace.
115
+
116
+ ## Error handling
117
+
118
+ The SDK raises typed exceptions that map onto the REST error codes; all subclass
119
+ `KorelyError`.
120
+
121
+ ```python
122
+ import time
123
+ from korely_memory import Korely, AuthenticationError, NotFoundError, QuotaExceededError
124
+
125
+ korely = Korely(api_key="kor_live_...")
126
+ try:
127
+ memory = korely.get("mem_8f2c1a")
128
+ except AuthenticationError:
129
+ raise # 401 — check or rotate the key
130
+ except NotFoundError:
131
+ memory = None # 404 — forgotten or never existed
132
+ except QuotaExceededError as err:
133
+ time.sleep(err.retry_after) # 429 — back off and retry
134
+ memory = korely.get("mem_8f2c1a")
135
+ ```
136
+
137
+ | Exception | Status |
138
+ |---|---|
139
+ | `AuthenticationError` | 401 |
140
+ | `NamespaceForbiddenError` | 403 |
141
+ | `NotFoundError` | 404 |
142
+ | `StaleWriteError` | 409 |
143
+ | `QuotaExceededError` (`.retry_after`) | 429 |
144
+ | `APIError` | other |
145
+
146
+ ## Links
147
+
148
+ - [SDK docs](https://korely.ai/agents/docs/surfaces/sdk)
149
+ - [API reference](https://korely.ai/agents/docs/api-reference)
150
+ - [Cookbook: a chatbot that remembers](https://korely.ai/agents/docs/cookbooks/chatbot-that-remembers)
151
+
152
+ MIT licensed.
@@ -0,0 +1,129 @@
1
+ # korely-memory
2
+
3
+ The Python SDK for [Korely Agents](https://korely.ai/agents) — memory for AI
4
+ agents, with bi-temporal typed facts and contradiction checking built in.
5
+
6
+ A typed, **zero-dependency** client over the Korely REST API. Every method maps
7
+ 1:1 onto an endpoint, so anything you can do with curl you can do here, and the
8
+ JSON shapes in the [API reference](https://korely.ai/agents/docs/api-reference)
9
+ are the attribute shapes you get back. All the intelligence — embeddings, entity
10
+ and typed-fact extraction, contradiction checking, bi-temporal validity — runs
11
+ server-side, so your install stays small and your process stays light.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install korely-memory
17
+ ```
18
+
19
+ Python 3.9 or later.
20
+
21
+ ## Quickstart
22
+
23
+ ```python
24
+ from korely_memory import Korely
25
+
26
+ korely = Korely(api_key="kor_live_...", region="eu")
27
+ # or read the key from the environment (KORELY_API_KEY)
28
+ korely = Korely(region="eu")
29
+
30
+ # Remember — the write path extracts facts and resolves contradictions
31
+ korely.add("User prefers TypeScript with strict mode", agent_id="coding-assistant")
32
+ korely.add("Actually I switched to Rust", agent_id="coding-assistant")
33
+
34
+ # Recall — superseded facts drop out automatically
35
+ for hit in korely.search("user's preferred language", limit=5):
36
+ print(hit.id, hit.score, hit.snippet)
37
+
38
+ # One-call, prompt-ready context for your LLM
39
+ ctx = korely.get_context(query="plan the project", user_id="dana", token_budget=800)
40
+ messages = [{"role": "system", "content": f"You are helpful.\n\n{ctx.context}"}]
41
+ ```
42
+
43
+ ## Methods
44
+
45
+ Every method wraps exactly one REST endpoint.
46
+
47
+ | Method | Endpoint |
48
+ |---|---|
49
+ | `add(content, *, agent_id=, user_id=, run_id=, metadata=)` | `POST /v1/memories` |
50
+ | `search(query, *, user_id=, agent_id=, limit=)` | `POST /v1/memories/search` |
51
+ | `get_all(*, user_id=, agent_id=, limit=, offset=)` | `GET /v1/memories` |
52
+ | `get(memory_id)` | `GET /v1/memories/:id` |
53
+ | `update(memory_id, *, content, expected_updated_at=)` | `PATCH /v1/memories/:id` |
54
+ | `delete(memory_id)` | `DELETE /v1/memories/:id` |
55
+ | `delete_all(*, user_id)` | `DELETE /v1/users/:user_id/memories` |
56
+ | `get_facts(*, subject=, entity=, predicate=, predicate_family=, include_invalidated=, as_of=, …)` | `GET /v1/facts` |
57
+ | `get_context(*, query, user_id=, agent_id=, token_budget=)` | `GET /v1/context` |
58
+ | `batch(memories)` | `POST /v1/batch` |
59
+ | `batch_status(job_id)` | `GET /v1/batch/:id` |
60
+
61
+ ## Bi-temporal facts
62
+
63
+ The differentiator: typed `(subject, predicate, object)` facts with validity over
64
+ time. Ask what was true on any date.
65
+
66
+ ```python
67
+ # Current state
68
+ facts = korely.get_facts(entity="Northwind Hosting")
69
+ print(facts[0].object) # 50 euro per month
70
+ print(facts[0].invalid_at) # None — active
71
+
72
+ # Point-in-time: what did we believe on June 1?
73
+ facts = korely.get_facts(entity="Northwind Hosting", as_of="2026-06-01")
74
+ print(facts[0].object) # 40 euro per month
75
+ ```
76
+
77
+ ## Scoping
78
+
79
+ Three identifiers, three levels of scope — the same everywhere (SDK, REST, MCP):
80
+
81
+ - `agent_id` — your application or agent (one namespace per product surface)
82
+ - `user_id` — your end user (free-form string; **unlimited on every tier**)
83
+ - `run_id` — one session or run (sub-scope inside a user)
84
+
85
+ ```python
86
+ korely.add("Asked to be contacted on Slack", agent_id="support-bot", user_id="customer-4812")
87
+ results = korely.search("contact preference", user_id="customer-4812")
88
+ ```
89
+
90
+ > Always pass `user_id` on reads in multi-tenant products. Filters are additive
91
+ > (AND); a search without `user_id` spans every end user in the namespace.
92
+
93
+ ## Error handling
94
+
95
+ The SDK raises typed exceptions that map onto the REST error codes; all subclass
96
+ `KorelyError`.
97
+
98
+ ```python
99
+ import time
100
+ from korely_memory import Korely, AuthenticationError, NotFoundError, QuotaExceededError
101
+
102
+ korely = Korely(api_key="kor_live_...")
103
+ try:
104
+ memory = korely.get("mem_8f2c1a")
105
+ except AuthenticationError:
106
+ raise # 401 — check or rotate the key
107
+ except NotFoundError:
108
+ memory = None # 404 — forgotten or never existed
109
+ except QuotaExceededError as err:
110
+ time.sleep(err.retry_after) # 429 — back off and retry
111
+ memory = korely.get("mem_8f2c1a")
112
+ ```
113
+
114
+ | Exception | Status |
115
+ |---|---|
116
+ | `AuthenticationError` | 401 |
117
+ | `NamespaceForbiddenError` | 403 |
118
+ | `NotFoundError` | 404 |
119
+ | `StaleWriteError` | 409 |
120
+ | `QuotaExceededError` (`.retry_after`) | 429 |
121
+ | `APIError` | other |
122
+
123
+ ## Links
124
+
125
+ - [SDK docs](https://korely.ai/agents/docs/surfaces/sdk)
126
+ - [API reference](https://korely.ai/agents/docs/api-reference)
127
+ - [Cookbook: a chatbot that remembers](https://korely.ai/agents/docs/cookbooks/chatbot-that-remembers)
128
+
129
+ MIT licensed.
@@ -0,0 +1,64 @@
1
+ """korely-memory — the Python SDK for Korely Agents.
2
+
3
+ A typed, dependency-free client over the Korely REST API. Every method maps
4
+ 1:1 onto an endpoint; the moat (typed bi-temporal facts, contradiction
5
+ checking) runs server-side.
6
+
7
+ from korely_memory import Korely
8
+
9
+ korely = Korely(api_key="kor_live_...", region="eu")
10
+ korely.add("User prefers TypeScript", agent_id="coding-assistant")
11
+ ctx = korely.get_context(query="what does the user like?", user_id="dana")
12
+ """
13
+ from .client import Korely, __version__
14
+ from .exceptions import (
15
+ APIError,
16
+ AuthenticationError,
17
+ KorelyError,
18
+ NamespaceForbiddenError,
19
+ NotFoundError,
20
+ QuotaExceededError,
21
+ StaleWriteError,
22
+ )
23
+ from .models import (
24
+ BatchJob,
25
+ BulkReceipt,
26
+ Context,
27
+ DeleteReceipt,
28
+ Fact,
29
+ HistoryEvent,
30
+ Memory,
31
+ MemoryHistory,
32
+ MemoryPage,
33
+ Profile,
34
+ SearchHit,
35
+ UserScope,
36
+ UsersPage,
37
+ )
38
+
39
+ __all__ = [
40
+ "Korely",
41
+ "__version__",
42
+ # exceptions
43
+ "KorelyError",
44
+ "AuthenticationError",
45
+ "NamespaceForbiddenError",
46
+ "NotFoundError",
47
+ "StaleWriteError",
48
+ "QuotaExceededError",
49
+ "APIError",
50
+ # models
51
+ "Memory",
52
+ "Fact",
53
+ "SearchHit",
54
+ "MemoryPage",
55
+ "DeleteReceipt",
56
+ "BulkReceipt",
57
+ "Context",
58
+ "BatchJob",
59
+ "Profile",
60
+ "HistoryEvent",
61
+ "MemoryHistory",
62
+ "UserScope",
63
+ "UsersPage",
64
+ ]