cortexlayer 0.1.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.
@@ -0,0 +1,266 @@
1
+ Metadata-Version: 2.4
2
+ Name: cortexlayer
3
+ Version: 0.1.0
4
+ Summary: Cortex: a memory layer for AI agents (linked pages + link-expansion retrieval) — hosted client and embedded engine.
5
+ License-Expression: Apache-2.0
6
+ Keywords: memory,agents,llm,mcp,rag,cortex
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Typing :: Typed
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ License-File: NOTICE
16
+ Requires-Dist: httpx>=0.27
17
+ Provides-Extra: local
18
+ Requires-Dist: chromadb>=1.0; extra == "local"
19
+ Requires-Dist: spacy>=3.7; extra == "local"
20
+ Provides-Extra: dev
21
+ Requires-Dist: cortexlayer[local]; extra == "dev"
22
+ Requires-Dist: pytest>=8.0; extra == "dev"
23
+ Requires-Dist: build>=1.2; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # cortexlayer
27
+
28
+ Python library for **Cortex**, a memory layer for AI agents. Cortex stores memories as linked
29
+ pages and retrieves with vector search **plus link-expansion**, so multi-hop facts come back
30
+ without over-fetching a large top-k.
31
+
32
+ Two ways to use it, with the same method names and result types:
33
+
34
+ | | What it is | Install |
35
+ |---|---|---|
36
+ | **`Memory`** | The engine, embedded in your process. No server; data stays on your machine. | `pip install "cortexlayer[local]"` |
37
+ | **`CortexClient`** | A client for a running Cortex server (hosted or self-hosted). | `pip install cortexlayer` |
38
+
39
+ Python 3.10+. The client needs only `httpx`; the embedded engine adds Chroma and spaCy.
40
+
41
+ > **Status: 0.1 (alpha), not yet on PyPI.** Local `Memory` has two engines: `raw` (default, no LLM)
42
+ > and `facts` (Mem0-style LLM fact extraction; see below). The Cortex server runs on this same library:
43
+ > its `facts` backend is `Memory(backend="facts")`, and it no longer depends on the `mem0ai` package.
44
+
45
+ ## Quickstart: embedded (`Memory`)
46
+
47
+ ```bash
48
+ pip install "cortexlayer[local]"
49
+ python -m spacy download en_core_web_sm # recommended: better entity extraction
50
+ ```
51
+
52
+ ```python
53
+ from cortexlayer import Memory
54
+
55
+ m = Memory() # ~/.cortexlayer, or Memory("path/to/dir")
56
+
57
+ m.add("Christopher Nolan directed Inception.", user_id="alice")
58
+ m.add("Christopher Nolan was born in London in 1970.", user_id="alice")
59
+ m.relink(user_id="alice") # batch linking pass: run after adding several
60
+
61
+ m.search("Who directed Inception?", user_id="alice", limit=1)
62
+ # [SearchResult(title='Christopher Nolan directed Inception.', via='direct', …),
63
+ # SearchResult(title='Christopher Nolan was born in London in 1970.',
64
+ # via='link', linked_from='…')] <- pulled in through the shared entity
65
+ ```
66
+
67
+ - **One store, many users:** every call takes an optional `user_id`; each user gets an isolated
68
+ collection, so users can never see each other's pages. Omit it and the default user is used.
69
+ - **Linking is a batch pass**, never per insert: call `relink()` after adding memories (or pass
70
+ `auto_relink=True` to relink after every `add`, which costs a scan of all pages).
71
+ - **Local and private:** memories live in an embedded Chroma store under `data_dir`. Nothing leaves
72
+ your machine (Chroma's anonymous telemetry is switched off). Two one-time downloads: Chroma's small
73
+ ONNX embedding model on first use (~80 MB), and the spaCy model if you install it.
74
+ - **No model? It still runs.** With `entity_extractor="auto"` (the default) `Memory` falls back to a
75
+ simpler regex extractor, with a one-time warning, if spaCy or its model is missing. Entities drive
76
+ linking, so the fallback finds fewer links. Force a choice with `"spacy"` or `"regex"`, or pass your
77
+ own object with `entities(text)` and `sentences(text)` methods.
78
+ - **Short answers (optional):** `m.answer("Where did Alice move?")` retrieves and has an LLM distil a
79
+ direct answer plus the supporting page ids. It uses a local Ollama by default
80
+ (`$OLLAMA_HOST`); pass `chat=fn(prompt, model) -> str` to use any model.
81
+
82
+ | `Memory` method | Returns |
83
+ |---|---|
84
+ | `add(text, user_id=, timestamp=)` | `AddResult` (long text is chunked into several pages) |
85
+ | `search(query, user_id=, limit=4, expand_links=True)` | `list[SearchResult]` |
86
+ | `get(id)` / `get_all(query=, limit=, offset=)` | `Page` / `PageList` |
87
+ | `update(id, text)` / `delete(id)` / `delete_all(user_id=)` | `None` / `None` / count removed |
88
+ | `relink()` / `count()` | `{"pages", "links_written"}` / `int` |
89
+ | `answer(query, limit=, model=, chat=)` | `Answer(answer, source_page_ids)` |
90
+
91
+ `Memory.from_config({...})` builds one from a dict (`data_dir`, `entity_extractor`, `spacy_model`,
92
+ `default_user_id`, `auto_relink`, `backend`, `llm`, `embedder`, `custom_instructions`,
93
+ `observation_date_from_timestamp`, `keyword_scoring`).
94
+
95
+ ### Fact memory: `Memory(backend="facts")`
96
+
97
+ The default `raw` engine stores your text as small pages and never calls an LLM. `facts` works like
98
+ Mem0: each `add` asks an LLM to distil the text into self-contained facts (resolving dates and pronouns),
99
+ stores those, and boosts search results by the entities they share with your query.
100
+
101
+ ```python
102
+ m = Memory(
103
+ backend="facts",
104
+ llm={"model": "qwen3.5:9b"}, # Ollama at $OLLAMA_HOST by default
105
+ embedder={"provider": "ollama", "model": "qwen3-embedding:8b"}, # default: Chroma's built-in ONNX model
106
+ )
107
+ m.add("[8 May, 2023] Caroline: I moved to Lisbon last week and adopted a dog named Max.", user_id="alice")
108
+ m.search("What is Caroline's dog called?", user_id="alice") # -> "Caroline adopted a dog named Max ..."
109
+ ```
110
+
111
+ - **Same API** as the raw engine, including `relink()` and link-expansion (links are entity overlap over the
112
+ extracted facts).
113
+ - **Bring your own model:** `llm` can be a dict, a callable `fn(system, user) -> str`, or any object with
114
+ `generate()`; `embedder` any object with `embed_batch(texts, action)` and a `name`. A store records which
115
+ embedder made its vectors and refuses to open with a different one.
116
+ - **Failure is loud:** an unreachable LLM or embedder raises `LLMError` (nothing is stored). "The model found
117
+ nothing worth remembering" is a normal empty result.
118
+ - **It costs an LLM call per `add`** (plus embeddings). The `raw` engine costs none.
119
+ - **Relative dates:** like Mem0, the extractor resolves "yesterday" against *today* unless told the
120
+ conversation's date. `observation_date_from_timestamp=True` passes your `add(timestamp=...)` as that date.
121
+ - **Exact words:** embedding scores are often compressed into a narrow band, so a fact that literally contains
122
+ a query word can rank below generic ones. Search fuses a BM25 keyword score by default (`keyword_scoring=False`
123
+ gives plain semantic + entity scoring, identical to Mem0 on Chroma; on a small LOCOMO subset it lifted F1 from 0.37 to 0.47 at the same token cost — not yet a
124
+ statistical result).
125
+ - **Facts are ordinary pages:** each fact is stored as a page in the user's Chroma collection, so links are
126
+ persisted and `get` / `get_all` / `update` / `delete` work on facts exactly as on raw pages.
127
+ - **Origin:** the extraction prompt and pipeline are adapted from [Mem0](https://github.com/mem0ai/mem0)
128
+ (Apache-2.0); cortexlayer does not depend on the `mem0ai` package. See `NOTICE`. The larger
129
+ multi-conversation comparison against Mem0 is still open.
130
+
131
+ ## Quickstart: hosted (`CortexClient`)
132
+
133
+ ```bash
134
+ pip install cortexlayer
135
+ ```
136
+
137
+ ```python
138
+ from cortexlayer import CortexClient
139
+
140
+ client = CortexClient(api_key="...") # or set CORTEX_API_KEY
141
+
142
+ client.search("Where does Alice live?", limit=5)
143
+ # [SearchResult(id='…', title='Alice moved to Lisbon in March.', via='direct', …),
144
+ # SearchResult(id='…', title='…', via='link', linked_from='…'), …]
145
+
146
+ client.get_all(limit=50) # browse pages
147
+ client.get(page_id) # one page + its links
148
+ ```
149
+
150
+ Create a key in the Cortex web app (**Keys**). Point at a self-hosted server with
151
+ `base_url="http://localhost:8000"` (or `CORTEX_BASE_URL`).
152
+
153
+ Writes:
154
+
155
+ ```python
156
+ client.add("I moved to Lisbon in March.") # long text is chunked into several pages
157
+ client.update(page_id, "…")
158
+ client.delete(page_id)
159
+ client.relink() # re-run the batch linking pass after adding several
160
+ ```
161
+
162
+ > **Writes need a server with REST write endpoints** (added in Cortex server task 0073; the hosted
163
+ > server has them). Against an older self-hosted server these four raise `WritesNotSupportedError`;
164
+ > reads, search, graph and usage work on every version.
165
+
166
+ ### Async
167
+
168
+ ```python
169
+ from cortexlayer import AsyncCortexClient
170
+
171
+ async with AsyncCortexClient(api_key="...") as client:
172
+ hits = await client.search("Where does Alice live?")
173
+ ```
174
+
175
+ Same methods, awaited.
176
+
177
+ ## Results
178
+
179
+ Plain frozen dataclasses (no pydantic). Unknown fields from a newer server are ignored.
180
+
181
+ | Call | Returns |
182
+ |---|---|
183
+ | `search(query, limit=4, expand_links=True)` | `list[SearchResult]` — `id, title, snippet, score, via, linked_from` |
184
+ | `get(id)` | `Page` — `id, title, content, links, linked_from, degree, created_at` |
185
+ | `get_all(query=None, limit=50, offset=0)` | `PageList` — `pages, total, limit, offset` |
186
+ | `add(text, timestamp=None)` | `AddResult` — `page_ids` |
187
+ | `me()` | `Account` — `user_id, account_name` |
188
+ | `usage(group_by="day", since=None, until=None)` | `Usage` — your own API usage, by `day` / `key` / `operation` |
189
+ | `graph(limit=None)`, `neighbors(id, depth=1)` | `Graph` — `nodes, edges, truncated, stale` |
190
+
191
+ `via` is `"direct"` for a vector hit and `"link"` for a page pulled in by link-expansion
192
+ (`linked_from` is the page that led to it). `score` semantics depend on the backend: on `raw` it is a
193
+ distance (lower is closer); on `facts` it is the fused semantic + keyword + entity score (higher is
194
+ closer). Compare within one store or server, not across.
195
+
196
+ ## Errors
197
+
198
+ Every failure is a `CortexError`:
199
+
200
+ | Exception | When |
201
+ |---|---|
202
+ | `InvalidRequestError` (also a `ValueError`) | bad arguments (caught before any request) or a server 400 |
203
+ | `AuthenticationError` | 401 — key missing, wrong or revoked |
204
+ | `PermissionDeniedError` | 403 — `.code` is the server's reason (`session_required`, …) |
205
+ | `NotFoundError` | 404 — unknown page (another user's page looks the same) |
206
+ | `ConflictError` | 409 |
207
+ | `RateLimitError` | 429 — `.retry_after` seconds if sent |
208
+ | `ServerError` | 5xx or an unreadable reply |
209
+ | `ConnectionError` | no response (DNS, refused, timeout) |
210
+ | `WritesNotSupportedError` | the server is too old to have REST write endpoints |
211
+ | `CortexConfigError` | bad client configuration (e.g. no API key) |
212
+
213
+ Reads and search are retried (default 2×, with backoff) on connection errors and 502/503/504.
214
+ **Writes are never retried**, so an `add` can't be applied twice.
215
+
216
+ ```python
217
+ from cortexlayer import CortexClient, NotFoundError
218
+
219
+ try:
220
+ client.get("does-not-exist")
221
+ except NotFoundError:
222
+ ...
223
+ ```
224
+
225
+ ## Configuration
226
+
227
+ ```python
228
+ CortexClient(
229
+ api_key=None, # or CORTEX_API_KEY
230
+ base_url=None, # or CORTEX_BASE_URL; default https://api.cortexlayer.net
231
+ timeout=30.0,
232
+ max_retries=2,
233
+ http_client=None, # bring your own httpx.Client (proxies, transports, tests)
234
+ )
235
+ ```
236
+
237
+ The key is never included in `repr()`. Use the client as a context manager (or `.close()`) to
238
+ release connections; a client you pass in is never closed for you.
239
+
240
+ ## Coming from Mem0
241
+
242
+ | Mem0 | cortexlayer |
243
+ |---|---|
244
+ | `Memory()` (embedded) | `Memory()` |
245
+ | `MemoryClient(api_key=...)` (hosted) | `CortexClient(api_key=...)` |
246
+ | `m.add(messages, user_id=...)` | `m.add(text, user_id=...)` |
247
+ | `m.search(query, user_id=...)` | `m.search(query, user_id=...)` — results add `via` / `linked_from` provenance |
248
+ | `m.get_all(...)` / `m.get(id)` | `m.get_all()` / `m.get(id)` |
249
+ | `m.update(id, data)` / `m.delete(id)` / `m.delete_all(...)` | `m.update(id, text)` / `m.delete(id)` / `m.delete_all(user_id=)` |
250
+ | — | `m.relink()` — Cortex links pages in a batch pass, never per insert |
251
+
252
+ Differences worth knowing: Cortex takes plain text, not chat-message lists. The default `raw` engine
253
+ stores your text as small pages and links them by shared entities, so **adding never needs an LLM**;
254
+ `Memory(backend="facts")` is the Mem0-style engine that extracts facts with an LLM. On `CortexClient`
255
+ there is no `user_id` argument: each API key belongs to exactly one user.
256
+
257
+ ## Development
258
+
259
+ ```bash
260
+ python -m venv .venv && .venv/bin/pip install -e ".[dev]"
261
+ .venv/bin/python -m pytest
262
+ ```
263
+
264
+ ## Licence
265
+
266
+ [Apache-2.0](LICENSE).
@@ -0,0 +1,29 @@
1
+ cortexlayer/__init__.py,sha256=zKPO5mhHm6qmBdrgtlstJaMMR3tmOLv3NbJ1SrcnECc,1821
2
+ cortexlayer/_validate.py,sha256=ppbcYz4v_Obv9x4TnNtiY16qMBch0R-0UicSPgtWkqo,825
3
+ cortexlayer/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
4
+ cortexlayer/client.py,sha256=V8hOg-s5M-tnOmUDyCNGWZzqwWVkJOJ6qOIrJ2SJlnM,18888
5
+ cortexlayer/errors.py,sha256=DLrhks7x0ddtcudtvvnDeKoQDOzLEN18jLpadjG1dFI,3382
6
+ cortexlayer/memory.py,sha256=fh84P_CkMPqMLUyoOyrMFpzPU3QRhw5G5bRj0FzfFPM,16243
7
+ cortexlayer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ cortexlayer/types.py,sha256=vPkP6ZjVEPuhu-H5KcYP-lv9AdOELZ2g5e-FxuuVFYM,5826
9
+ cortexlayer/_engine/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ cortexlayer/_engine/compression.py,sha256=OfKvs-oeqvyerQbshuNJPOH7dovJYEYeQ0CztlhSuKo,3456
11
+ cortexlayer/_engine/ingestion.py,sha256=QyxDzLJ2XgCw66FoI5XG6iVhx0CUIuTsdkNEMJWQJ-0,2653
12
+ cortexlayer/_engine/linking.py,sha256=XkoMb9pYVcvuZbyR1d2KT-GUC7f6uuJJiliPwqYsGFo,2477
13
+ cortexlayer/_engine/nlp.py,sha256=9cYqbhw3jP5SuvbXZDUndQRFLiAXNj0Tx0rD53e_GjA,6215
14
+ cortexlayer/_engine/retrieval.py,sha256=ibcW3CJvV8GIm6j7HXQimgDQ-RIyrX6IG0HeGA3BkWY,2258
15
+ cortexlayer/_engine/shaping.py,sha256=bP_UoqndLzZomhew-wykUEID9F_voor6kMn4QY1oSjk,2944
16
+ cortexlayer/_engine/storage.py,sha256=XctWES1gNk5ezESPSozqj9EPnK_6KaQrujnizWD90kA,10261
17
+ cortexlayer/_engine/facts/__init__.py,sha256=1xoTpWLTSW8FaMk70NVzjw7N5fQVwtz7fDMZm9e1s5s,86
18
+ cortexlayer/_engine/facts/additive_extraction_prompt.txt,sha256=rRkYejeBPvd-4VbnFMBlDm7HSeAmS9wH1Jm8myQRUVU,33831
19
+ cortexlayer/_engine/facts/backends.py,sha256=uxYYSbCsFY7taw6pGaG73-MjFD71oAzMsLqz9xVSK9s,7027
20
+ cortexlayer/_engine/facts/engine.py,sha256=fikYhK2T_kCXW09ACNqr_TPWZAcy0mqdZmYo8bAarV8,24208
21
+ cortexlayer/_engine/facts/entities.py,sha256=EL8Jj49FTy4XGGRnKAYdrYTCkrvVoqFAgDHZWjo3fmI,22440
22
+ cortexlayer/_engine/facts/prompts.py,sha256=LvsdmhQNz4yP9J54nOaahZ6Y4NzaGjbuptAnv-h4Vfo,3733
23
+ cortexlayer/_engine/facts/scoring.py,sha256=ma4FEtxamrEi0cEQBhTb2jrCtP_-RFPdNIJZSfqq_AI,5737
24
+ cortexlayer-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
25
+ cortexlayer-0.1.0.dist-info/licenses/NOTICE,sha256=xaDRyokng60bCPC6WacrWz2r6e_v_2sGl4QYPonsKxI,1928
26
+ cortexlayer-0.1.0.dist-info/METADATA,sha256=W7zGeM74kusZy4sEVkQR5ZBTatij5_D3n8Qi7A18fUc,12542
27
+ cortexlayer-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
28
+ cortexlayer-0.1.0.dist-info/top_level.txt,sha256=FKvfKZDu082td37gHcA3GQBlfdfp0SWdxyKpeVhhbo8,12
29
+ cortexlayer-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,40 @@
1
+ cortexlayer
2
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
3
+
4
+ This product includes software derived from Mem0:
5
+
6
+ Mem0 — https://github.com/mem0ai/mem0 (PyPI: mem0ai 2.1.0)
7
+ Author: Mem0 <support@mem0.ai>
8
+ Licensed under the Apache License, Version 2.0.
9
+
10
+ The following files reproduce or adapt Mem0 source code or prompt text. Each
11
+ carries a notice in its header describing what was changed, as required by the
12
+ Apache License, Version 2.0, section 4.
13
+
14
+ src/cortexlayer/_engine/facts/additive_extraction_prompt.txt
15
+ Mem0's additive extraction system prompt (ADDITIVE_EXTRACTION_PROMPT from
16
+ mem0/configs/prompts.py). Copied unchanged.
17
+
18
+ src/cortexlayer/_engine/facts/prompts.py
19
+ Adapted from the user-prompt builder in mem0/configs/prompts.py
20
+ (generate_additive_extraction_prompt and helpers). Re-typed with type
21
+ hints; behavior unchanged.
22
+
23
+ src/cortexlayer/_engine/facts/entities.py
24
+ Adapted from mem0/utils/entity_extraction.py. The extraction heuristics are
25
+ unchanged; the two public entry points accept an optional spaCy pipeline and
26
+ no longer import mem0's model loader (which downloads a model at runtime).
27
+
28
+ src/cortexlayer/_engine/facts/scoring.py
29
+ Adapted from mem0/utils/scoring.py and Memory._compute_entity_boosts in
30
+ mem0/memory/main.py. Mem0's BM25 term never runs with its Chroma vector
31
+ store, so it is off by default; an optional keyword term uses our own
32
+ dependency-free BM25 (not Mem0's lemmatizer/normalisation) fused with the
33
+ same (semantic + keyword + entity) / max_possible formula.
34
+
35
+ src/cortexlayer/_engine/facts/engine.py
36
+ Implements the algorithm of Mem0's add/search pipeline (mem0/memory/main.py,
37
+ "V3 phased batch pipeline") on cortexlayer's own storage. See the module
38
+ docstring for the deliberate differences.
39
+
40
+ cortexlayer does not depend on, import, or redistribute the mem0ai package.
@@ -0,0 +1 @@
1
+ cortexlayer