cortexdbai 0.2.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,45 @@
1
+ # Rust
2
+ /target
3
+ **/*.rs.bk
4
+
5
+ # Environment / secrets
6
+ .env
7
+ .env.local
8
+ .env*.local
9
+ *.pem
10
+ *.key
11
+
12
+ # SQLite database
13
+ website/data/
14
+ *.sqlite
15
+ *.sqlite-wal
16
+ *.sqlite-shm
17
+
18
+ # OS
19
+ .DS_Store
20
+ Thumbs.db
21
+ desktop.ini
22
+
23
+ # IDE
24
+ .idea/
25
+ .vscode/
26
+ *.swp
27
+ *.swo
28
+
29
+ # Data directories
30
+ cortexdb_data*/
31
+ /data/
32
+
33
+ # Python
34
+ __pycache__/
35
+ *.pyc
36
+ .venv/
37
+ venv/
38
+
39
+ # Node
40
+ node_modules/
41
+ dist/
42
+ .next/
43
+
44
+ # Egg info
45
+ *.egg-info/
@@ -0,0 +1,236 @@
1
+ Metadata-Version: 2.4
2
+ Name: cortexdbai
3
+ Version: 0.2.0
4
+ Summary: The Long-Term Memory Layer for AI Systems
5
+ Project-URL: Homepage, https://cortexdb.io
6
+ Project-URL: Documentation, https://docs.cortexdb.io
7
+ Project-URL: Repository, https://github.com/cortexdb/cortexdb
8
+ Project-URL: Issues, https://github.com/cortexdb/cortexdb/issues
9
+ Project-URL: Changelog, https://github.com/cortexdb/cortexdb/blob/main/CHANGELOG.md
10
+ Author-email: Prashant Malik <prashant@cortexdb.io>
11
+ License-Expression: Apache-2.0
12
+ Keywords: ai,cortexdb,event-sourcing,knowledge-graph,llm,memory
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Database
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: httpx>=0.24
27
+ Requires-Dist: pydantic>=2.0
28
+ Requires-Dist: tenacity>=8.0
29
+ Provides-Extra: async
30
+ Requires-Dist: httpx[http2]; extra == 'async'
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
33
+ Requires-Dist: pytest>=8.0; extra == 'dev'
34
+ Requires-Dist: ruff>=0.4; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # CortexDB Python SDK
38
+
39
+ **The Long-Term Memory Layer for AI Systems.**
40
+
41
+ CortexDB gives your AI agents persistent, searchable memory. Store conversations, decisions, incidents, and domain knowledge as structured episodes. Retrieve relevant context with a single call.
42
+
43
+ [![PyPI version](https://img.shields.io/pypi/v/cortexdb.svg)](https://pypi.org/project/cortexdb/)
44
+ [![Python](https://img.shields.io/pypi/pyversions/cortexdb.svg)](https://pypi.org/project/cortexdb/)
45
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/cortexdb/cortexdb/blob/main/LICENSE)
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ pip install cortexdb
51
+ ```
52
+
53
+ For HTTP/2 support (recommended for async workloads):
54
+
55
+ ```bash
56
+ pip install cortexdb[async]
57
+ ```
58
+
59
+ ## Quick Start
60
+
61
+ ```python
62
+ from cortexdb import Cortex
63
+
64
+ # Connect to CortexDB
65
+ cortex = Cortex("http://localhost:3141", api_key="your-api-key")
66
+
67
+ # Remember something
68
+ cortex.remember("The payments service was migrated to Kubernetes on March 15th.")
69
+
70
+ # Recall relevant memories
71
+ result = cortex.recall("When did we migrate payments?")
72
+ for match in result.matches:
73
+ print(f"[{match.confidence:.0%}] {match.content}")
74
+
75
+ # Forget when needed (GDPR, cleanup, etc.)
76
+ cortex.forget(query="old deploy logs", reason="quarterly cleanup")
77
+
78
+ # Search with filters
79
+ results = cortex.search(
80
+ "deploy failure",
81
+ source="github",
82
+ time_range="7d",
83
+ limit=10,
84
+ )
85
+ print(results.context)
86
+ ```
87
+
88
+ ## Async Usage
89
+
90
+ Every method has an async counterpart via `AsyncCortex`:
91
+
92
+ ```python
93
+ import asyncio
94
+ from cortexdb import AsyncCortex
95
+
96
+ async def main():
97
+ async with AsyncCortex("http://localhost:3141", api_key="your-api-key") as cortex:
98
+ await cortex.remember("Async memory storage works great.")
99
+
100
+ result = await cortex.recall("How does async work?")
101
+ for match in result.matches:
102
+ print(match.content)
103
+
104
+ asyncio.run(main())
105
+ ```
106
+
107
+ ## Episode Ingestion
108
+
109
+ For structured data, use episodes with full metadata:
110
+
111
+ ```python
112
+ from cortexdb import Cortex, IngestEpisodeRequest, Actor, Source, ActorType, EpisodeType
113
+
114
+ cortex = Cortex("http://localhost:3141")
115
+
116
+ # Ingest a structured episode
117
+ episode = IngestEpisodeRequest(
118
+ content="PR #412: Add retry logic to payment processor",
119
+ episode_type=EpisodeType.CODE_CHANGE,
120
+ actor=Actor(id="ci-bot", name="CI Bot", actor_type=ActorType.SERVICE),
121
+ source=Source(connector="github", external_id="pr-412", url="https://github.com/org/repo/pull/412"),
122
+ metadata={"branch": "main", "files_changed": 3},
123
+ )
124
+ response = cortex.ingest_episode(episode)
125
+ print(f"Episode {response.episode_id} ingested.")
126
+
127
+ # Or use the smart store shorthand
128
+ cortex.store("Plain text goes through remember().")
129
+ cortex.store({
130
+ "content": "Dict data goes through ingest_episode().",
131
+ "type": "deployment",
132
+ "source": "slack",
133
+ })
134
+ ```
135
+
136
+ ## Entity Lookup
137
+
138
+ Explore entities and their relationships in the knowledge graph:
139
+
140
+ ```python
141
+ cortex = Cortex("http://localhost:3141")
142
+
143
+ # Look up an entity
144
+ entity = cortex.entity("payments-service")
145
+ print(f"{entity.name} ({entity.entity_type})")
146
+ print(f" Episodes: {entity.episode_count}")
147
+ print(f" First seen: {entity.first_seen}")
148
+
149
+ # Browse relationships
150
+ for rel in entity.relationships:
151
+ print(f" {rel.relationship} -> {rel.target_entity_id} ({rel.confidence:.0%})")
152
+
153
+ # Create explicit relationships
154
+ cortex.link(
155
+ source_entity_id="payments-service",
156
+ target_entity_id="auth-service",
157
+ relationship="DEPENDS_ON",
158
+ fact="Payments calls auth for token validation",
159
+ confidence=0.95,
160
+ )
161
+ ```
162
+
163
+ ## Error Handling
164
+
165
+ The SDK provides a structured exception hierarchy:
166
+
167
+ ```python
168
+ from cortexdb import Cortex
169
+ from cortexdb.exceptions import (
170
+ CortexError, # Base exception
171
+ CortexAPIError, # HTTP 4xx/5xx errors
172
+ CortexAuthError, # HTTP 401/403
173
+ CortexRateLimitError, # HTTP 429 (includes retry_after)
174
+ CortexConnectionError,# Network failures
175
+ CortexTimeoutError, # Request timeouts
176
+ )
177
+
178
+ cortex = Cortex("http://localhost:3141")
179
+
180
+ try:
181
+ cortex.remember("important data")
182
+ except CortexRateLimitError as e:
183
+ print(f"Rate limited. Retry after {e.retry_after}s")
184
+ except CortexAuthError as e:
185
+ print(f"Authentication failed: {e.message}")
186
+ except CortexConnectionError:
187
+ print("Cannot reach CortexDB server")
188
+ except CortexAPIError as e:
189
+ print(f"API error [{e.status_code}]: {e.message}")
190
+ ```
191
+
192
+ Transient errors (429, 502, 503, 504) and connection failures are automatically retried with exponential backoff. Configure retry behavior at client initialization:
193
+
194
+ ```python
195
+ cortex = Cortex(
196
+ "http://localhost:3141",
197
+ max_retries=5, # default: 3
198
+ timeout=60.0, # default: 30.0 seconds
199
+ )
200
+ ```
201
+
202
+ ## Configuration
203
+
204
+ ### Constructor Parameters
205
+
206
+ | Parameter | Type | Default | Description |
207
+ |----------------|---------|--------------------------|------------------------------------|
208
+ | `base_url` | `str` | `http://localhost:3141` | CortexDB server URL |
209
+ | `api_key` | `str` | `None` | Bearer token for authentication |
210
+ | `timeout` | `float` | `30.0` | Request timeout in seconds |
211
+ | `max_retries` | `int` | `3` | Max retries for transient failures |
212
+
213
+ ### Environment Variables
214
+
215
+ | Variable | Description |
216
+ |---------------------|----------------------------------------------|
217
+ | `CORTEXDB_API_KEY` | Fallback API key when none is passed directly |
218
+
219
+ ## Convenience Methods
220
+
221
+ | Method | Description |
222
+ |-----------------------|-------------------------------------------------------|
223
+ | `cortex.memory(q)` | Alias for `recall()` -- the GTM one-liner |
224
+ | `cortex.store(data)` | Smart dispatch: `str` -> `remember()`, `dict` -> `ingest_episode()` |
225
+ | `cortex.context(q)` | Recall with higher token budget (8192) for LLM agents |
226
+
227
+ ## Links
228
+
229
+ - [Documentation](https://docs.cortexdb.io)
230
+ - [GitHub Repository](https://github.com/cortexdb/cortexdb)
231
+ - [Issue Tracker](https://github.com/cortexdb/cortexdb/issues)
232
+ - [Changelog](https://github.com/cortexdb/cortexdb/blob/main/CHANGELOG.md)
233
+
234
+ ## License
235
+
236
+ Apache-2.0
@@ -0,0 +1,200 @@
1
+ # CortexDB Python SDK
2
+
3
+ **The Long-Term Memory Layer for AI Systems.**
4
+
5
+ CortexDB gives your AI agents persistent, searchable memory. Store conversations, decisions, incidents, and domain knowledge as structured episodes. Retrieve relevant context with a single call.
6
+
7
+ [![PyPI version](https://img.shields.io/pypi/v/cortexdb.svg)](https://pypi.org/project/cortexdb/)
8
+ [![Python](https://img.shields.io/pypi/pyversions/cortexdb.svg)](https://pypi.org/project/cortexdb/)
9
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/cortexdb/cortexdb/blob/main/LICENSE)
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install cortexdb
15
+ ```
16
+
17
+ For HTTP/2 support (recommended for async workloads):
18
+
19
+ ```bash
20
+ pip install cortexdb[async]
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```python
26
+ from cortexdb import Cortex
27
+
28
+ # Connect to CortexDB
29
+ cortex = Cortex("http://localhost:3141", api_key="your-api-key")
30
+
31
+ # Remember something
32
+ cortex.remember("The payments service was migrated to Kubernetes on March 15th.")
33
+
34
+ # Recall relevant memories
35
+ result = cortex.recall("When did we migrate payments?")
36
+ for match in result.matches:
37
+ print(f"[{match.confidence:.0%}] {match.content}")
38
+
39
+ # Forget when needed (GDPR, cleanup, etc.)
40
+ cortex.forget(query="old deploy logs", reason="quarterly cleanup")
41
+
42
+ # Search with filters
43
+ results = cortex.search(
44
+ "deploy failure",
45
+ source="github",
46
+ time_range="7d",
47
+ limit=10,
48
+ )
49
+ print(results.context)
50
+ ```
51
+
52
+ ## Async Usage
53
+
54
+ Every method has an async counterpart via `AsyncCortex`:
55
+
56
+ ```python
57
+ import asyncio
58
+ from cortexdb import AsyncCortex
59
+
60
+ async def main():
61
+ async with AsyncCortex("http://localhost:3141", api_key="your-api-key") as cortex:
62
+ await cortex.remember("Async memory storage works great.")
63
+
64
+ result = await cortex.recall("How does async work?")
65
+ for match in result.matches:
66
+ print(match.content)
67
+
68
+ asyncio.run(main())
69
+ ```
70
+
71
+ ## Episode Ingestion
72
+
73
+ For structured data, use episodes with full metadata:
74
+
75
+ ```python
76
+ from cortexdb import Cortex, IngestEpisodeRequest, Actor, Source, ActorType, EpisodeType
77
+
78
+ cortex = Cortex("http://localhost:3141")
79
+
80
+ # Ingest a structured episode
81
+ episode = IngestEpisodeRequest(
82
+ content="PR #412: Add retry logic to payment processor",
83
+ episode_type=EpisodeType.CODE_CHANGE,
84
+ actor=Actor(id="ci-bot", name="CI Bot", actor_type=ActorType.SERVICE),
85
+ source=Source(connector="github", external_id="pr-412", url="https://github.com/org/repo/pull/412"),
86
+ metadata={"branch": "main", "files_changed": 3},
87
+ )
88
+ response = cortex.ingest_episode(episode)
89
+ print(f"Episode {response.episode_id} ingested.")
90
+
91
+ # Or use the smart store shorthand
92
+ cortex.store("Plain text goes through remember().")
93
+ cortex.store({
94
+ "content": "Dict data goes through ingest_episode().",
95
+ "type": "deployment",
96
+ "source": "slack",
97
+ })
98
+ ```
99
+
100
+ ## Entity Lookup
101
+
102
+ Explore entities and their relationships in the knowledge graph:
103
+
104
+ ```python
105
+ cortex = Cortex("http://localhost:3141")
106
+
107
+ # Look up an entity
108
+ entity = cortex.entity("payments-service")
109
+ print(f"{entity.name} ({entity.entity_type})")
110
+ print(f" Episodes: {entity.episode_count}")
111
+ print(f" First seen: {entity.first_seen}")
112
+
113
+ # Browse relationships
114
+ for rel in entity.relationships:
115
+ print(f" {rel.relationship} -> {rel.target_entity_id} ({rel.confidence:.0%})")
116
+
117
+ # Create explicit relationships
118
+ cortex.link(
119
+ source_entity_id="payments-service",
120
+ target_entity_id="auth-service",
121
+ relationship="DEPENDS_ON",
122
+ fact="Payments calls auth for token validation",
123
+ confidence=0.95,
124
+ )
125
+ ```
126
+
127
+ ## Error Handling
128
+
129
+ The SDK provides a structured exception hierarchy:
130
+
131
+ ```python
132
+ from cortexdb import Cortex
133
+ from cortexdb.exceptions import (
134
+ CortexError, # Base exception
135
+ CortexAPIError, # HTTP 4xx/5xx errors
136
+ CortexAuthError, # HTTP 401/403
137
+ CortexRateLimitError, # HTTP 429 (includes retry_after)
138
+ CortexConnectionError,# Network failures
139
+ CortexTimeoutError, # Request timeouts
140
+ )
141
+
142
+ cortex = Cortex("http://localhost:3141")
143
+
144
+ try:
145
+ cortex.remember("important data")
146
+ except CortexRateLimitError as e:
147
+ print(f"Rate limited. Retry after {e.retry_after}s")
148
+ except CortexAuthError as e:
149
+ print(f"Authentication failed: {e.message}")
150
+ except CortexConnectionError:
151
+ print("Cannot reach CortexDB server")
152
+ except CortexAPIError as e:
153
+ print(f"API error [{e.status_code}]: {e.message}")
154
+ ```
155
+
156
+ Transient errors (429, 502, 503, 504) and connection failures are automatically retried with exponential backoff. Configure retry behavior at client initialization:
157
+
158
+ ```python
159
+ cortex = Cortex(
160
+ "http://localhost:3141",
161
+ max_retries=5, # default: 3
162
+ timeout=60.0, # default: 30.0 seconds
163
+ )
164
+ ```
165
+
166
+ ## Configuration
167
+
168
+ ### Constructor Parameters
169
+
170
+ | Parameter | Type | Default | Description |
171
+ |----------------|---------|--------------------------|------------------------------------|
172
+ | `base_url` | `str` | `http://localhost:3141` | CortexDB server URL |
173
+ | `api_key` | `str` | `None` | Bearer token for authentication |
174
+ | `timeout` | `float` | `30.0` | Request timeout in seconds |
175
+ | `max_retries` | `int` | `3` | Max retries for transient failures |
176
+
177
+ ### Environment Variables
178
+
179
+ | Variable | Description |
180
+ |---------------------|----------------------------------------------|
181
+ | `CORTEXDB_API_KEY` | Fallback API key when none is passed directly |
182
+
183
+ ## Convenience Methods
184
+
185
+ | Method | Description |
186
+ |-----------------------|-------------------------------------------------------|
187
+ | `cortex.memory(q)` | Alias for `recall()` -- the GTM one-liner |
188
+ | `cortex.store(data)` | Smart dispatch: `str` -> `remember()`, `dict` -> `ingest_episode()` |
189
+ | `cortex.context(q)` | Recall with higher token budget (8192) for LLM agents |
190
+
191
+ ## Links
192
+
193
+ - [Documentation](https://docs.cortexdb.io)
194
+ - [GitHub Repository](https://github.com/cortexdb/cortexdb)
195
+ - [Issue Tracker](https://github.com/cortexdb/cortexdb/issues)
196
+ - [Changelog](https://github.com/cortexdb/cortexdb/blob/main/CHANGELOG.md)
197
+
198
+ ## License
199
+
200
+ Apache-2.0
@@ -0,0 +1,79 @@
1
+ """CortexDB Python SDK — The Long-Term Memory Layer for AI Systems."""
2
+
3
+ from cortexdb.client import AsyncCortex, Cortex
4
+ from cortexdb.exceptions import (
5
+ CortexAPIError,
6
+ CortexAuthError,
7
+ CortexConnectionError,
8
+ CortexError,
9
+ CortexRateLimitError,
10
+ CortexTimeoutError,
11
+ )
12
+ from cortexdb.models import (
13
+ Actor,
14
+ ActorType,
15
+ EntityRef,
16
+ EntityRelationship,
17
+ EntityResponse,
18
+ Episode,
19
+ EpisodeBrief,
20
+ EpisodeType,
21
+ ForgetRequest,
22
+ ForgetResponse,
23
+ HealthResponse,
24
+ IngestEpisodeRequest,
25
+ IngestEpisodeResponse,
26
+ LinkResponse,
27
+ ListEpisodesResponse,
28
+ MetricsResponse,
29
+ RecallRequest,
30
+ RecallResponse,
31
+ RememberRequest,
32
+ RememberResponse,
33
+ SearchResponse,
34
+ Source,
35
+ Visibility,
36
+ VisibilityLevel,
37
+ )
38
+
39
+ __version__ = "0.1.0"
40
+ __all__ = [
41
+ # Clients
42
+ "Cortex",
43
+ "AsyncCortex",
44
+ # Enums
45
+ "EpisodeType",
46
+ "ActorType",
47
+ "VisibilityLevel",
48
+ # Core models
49
+ "Actor",
50
+ "Source",
51
+ "Visibility",
52
+ "EntityRef",
53
+ "Episode",
54
+ # Request models
55
+ "IngestEpisodeRequest",
56
+ "RememberRequest",
57
+ "RecallRequest",
58
+ "ForgetRequest",
59
+ # Response models
60
+ "IngestEpisodeResponse",
61
+ "RememberResponse",
62
+ "RecallResponse",
63
+ "ForgetResponse",
64
+ "ListEpisodesResponse",
65
+ "HealthResponse",
66
+ "MetricsResponse",
67
+ "EntityResponse",
68
+ "EntityRelationship",
69
+ "EpisodeBrief",
70
+ "LinkResponse",
71
+ "SearchResponse",
72
+ # Exceptions
73
+ "CortexError",
74
+ "CortexAPIError",
75
+ "CortexConnectionError",
76
+ "CortexTimeoutError",
77
+ "CortexAuthError",
78
+ "CortexRateLimitError",
79
+ ]