cortexdbai 0.2.0__tar.gz → 0.2.2__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.
- cortexdbai-0.2.2/.gitignore +71 -0
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/PKG-INFO +9 -9
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/README.md +200 -200
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/cortexdb/__init__.py +116 -79
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/cortexdb/client.py +1103 -962
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/cortexdb/exceptions.py +69 -69
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/cortexdb/models.py +446 -390
- cortexdbai-0.2.2/cortexdb/v1/__init__.py +60 -0
- cortexdbai-0.2.2/cortexdb/v1/client.py +691 -0
- cortexdbai-0.2.2/cortexdb/v1/exceptions.py +92 -0
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/pyproject.toml +65 -65
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/tests/conftest.py +39 -39
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/tests/test_client.py +659 -659
- cortexdbai-0.2.0/.gitignore +0 -45
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/cortexdb/py.typed +0 -0
- {cortexdbai-0.2.0 → cortexdbai-0.2.2}/tests/__init__.py +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Rust
|
|
2
|
+
/target
|
|
3
|
+
**/*.rs.bk
|
|
4
|
+
|
|
5
|
+
# Environment / secrets
|
|
6
|
+
.env
|
|
7
|
+
.env.local
|
|
8
|
+
.env*.local
|
|
9
|
+
*.pem
|
|
10
|
+
*.key
|
|
11
|
+
.npmrc
|
|
12
|
+
|
|
13
|
+
# SQLite database
|
|
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
|
+
# Per-bench tenant stores (RocksDB + Tantivy + HNSW state; regeneratable per run)
|
|
33
|
+
/data_*/
|
|
34
|
+
# Experimental per-branch stores (not tracked on this branch but left gitignored
|
|
35
|
+
# so checkout from other branches doesn't surface them in git status)
|
|
36
|
+
/event_memory_store/
|
|
37
|
+
/llm_cache/
|
|
38
|
+
|
|
39
|
+
# Benchmark inputs and per-run outputs (kept local, regenerated each run)
|
|
40
|
+
benchmarks/longmemeval/data/
|
|
41
|
+
benchmarks/longmemeval/server_results/
|
|
42
|
+
benchmarks/longmemeval/fast_results/
|
|
43
|
+
benchmarks/longmemeval/micro_results/
|
|
44
|
+
benchmarks/longmemeval/server_logs/
|
|
45
|
+
benchmarks/longmemeval/*.log
|
|
46
|
+
benchmarks/locomo/locomo_results*.json
|
|
47
|
+
benchmarks/locomo/server_results/
|
|
48
|
+
benchmarks/locomo/*.log
|
|
49
|
+
/answer_out.json
|
|
50
|
+
|
|
51
|
+
# Local Claude Code state
|
|
52
|
+
.claude/
|
|
53
|
+
.tmp/
|
|
54
|
+
|
|
55
|
+
# Python
|
|
56
|
+
__pycache__/
|
|
57
|
+
*.pyc
|
|
58
|
+
.venv/
|
|
59
|
+
venv/
|
|
60
|
+
|
|
61
|
+
# Node
|
|
62
|
+
node_modules/
|
|
63
|
+
dist/
|
|
64
|
+
.next/
|
|
65
|
+
|
|
66
|
+
# Egg info
|
|
67
|
+
*.egg-info/
|
|
68
|
+
|
|
69
|
+
# Scratch/debug text files at root
|
|
70
|
+
/*.txt
|
|
71
|
+
/*.log
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cortexdbai
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: The Long-Term Memory Layer for AI Systems
|
|
5
|
-
Project-URL: Homepage, https://cortexdb.
|
|
6
|
-
Project-URL: Documentation, https://docs.cortexdb.
|
|
5
|
+
Project-URL: Homepage, https://cortexdb.ai
|
|
6
|
+
Project-URL: Documentation, https://docs.cortexdb.ai
|
|
7
7
|
Project-URL: Repository, https://github.com/cortexdb/cortexdb
|
|
8
8
|
Project-URL: Issues, https://github.com/cortexdb/cortexdb/issues
|
|
9
9
|
Project-URL: Changelog, https://github.com/cortexdb/cortexdb/blob/main/CHANGELOG.md
|
|
10
|
-
Author-email: Prashant Malik <prashant@cortexdb.
|
|
10
|
+
Author-email: Prashant Malik <prashant@cortexdb.ai>
|
|
11
11
|
License-Expression: Apache-2.0
|
|
12
12
|
Keywords: ai,cortexdb,event-sourcing,knowledge-graph,llm,memory
|
|
13
13
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -40,20 +40,20 @@ Description-Content-Type: text/markdown
|
|
|
40
40
|
|
|
41
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
42
|
|
|
43
|
-
[](https://pypi.org/project/
|
|
44
|
-
[](https://pypi.org/project/
|
|
43
|
+
[](https://pypi.org/project/cortexdbai/)
|
|
44
|
+
[](https://pypi.org/project/cortexdbai/)
|
|
45
45
|
[](https://github.com/cortexdb/cortexdb/blob/main/LICENSE)
|
|
46
46
|
|
|
47
47
|
## Installation
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
|
-
pip install
|
|
50
|
+
pip install cortexdbai
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
For HTTP/2 support (recommended for async workloads):
|
|
54
54
|
|
|
55
55
|
```bash
|
|
56
|
-
pip install
|
|
56
|
+
pip install cortexdbai[async]
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
## Quick Start
|
|
@@ -226,7 +226,7 @@ cortex = Cortex(
|
|
|
226
226
|
|
|
227
227
|
## Links
|
|
228
228
|
|
|
229
|
-
- [Documentation](https://docs.cortexdb.
|
|
229
|
+
- [Documentation](https://docs.cortexdb.ai)
|
|
230
230
|
- [GitHub Repository](https://github.com/cortexdb/cortexdb)
|
|
231
231
|
- [Issue Tracker](https://github.com/cortexdb/cortexdb/issues)
|
|
232
232
|
- [Changelog](https://github.com/cortexdb/cortexdb/blob/main/CHANGELOG.md)
|
|
@@ -1,200 +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
|
-
[](https://pypi.org/project/
|
|
8
|
-
[](https://pypi.org/project/
|
|
9
|
-
[](https://github.com/cortexdb/cortexdb/blob/main/LICENSE)
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
pip install
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
For HTTP/2 support (recommended for async workloads):
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
pip install
|
|
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.
|
|
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
|
|
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
|
+
[](https://pypi.org/project/cortexdbai/)
|
|
8
|
+
[](https://pypi.org/project/cortexdbai/)
|
|
9
|
+
[](https://github.com/cortexdb/cortexdb/blob/main/LICENSE)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install cortexdbai
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For HTTP/2 support (recommended for async workloads):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install cortexdbai[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.ai)
|
|
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
|