@dooor-ai/cortexdb 0.1.0
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.
- package/LICENSE +22 -0
- package/README.md +302 -0
- package/dist/client/index.d.ts +29 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +41 -0
- package/dist/client/index.js.map +1 -0
- package/dist/collections/api.d.ts +89 -0
- package/dist/collections/api.d.ts.map +1 -0
- package/dist/collections/api.js +106 -0
- package/dist/collections/api.js.map +1 -0
- package/dist/exceptions/index.d.ts +50 -0
- package/dist/exceptions/index.d.ts.map +1 -0
- package/dist/exceptions/index.js +93 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/http/client.d.ts +71 -0
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/client.js +150 -0
- package/dist/http/client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/records/api.d.ts +47 -0
- package/dist/records/api.d.ts.map +1 -0
- package/dist/records/api.js +62 -0
- package/dist/records/api.js.map +1 -0
- package/dist/types/index.d.ts +113 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 CortexDB
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# CortexDB TypeScript/JavaScript SDK
|
|
2
|
+
|
|
3
|
+
Official TypeScript/JavaScript client for **CortexDB** - A powerful multi-modal RAG (Retrieval Augmented Generation) platform with advanced document processing capabilities.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/%40dooor-ai%2Fcortexdb)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🚀 **Simple & Intuitive API** - Easy to use, TypeScript-first design
|
|
11
|
+
- 🔍 **Semantic Search** - Vector-based semantic search with embeddings
|
|
12
|
+
- 📄 **Document Processing** - Advanced PDF, DOCX, XLSX processing with Docling
|
|
13
|
+
- 🎯 **Type Safe** - Full TypeScript support with type definitions
|
|
14
|
+
- ⚡ **Async/Await** - Modern async/await API
|
|
15
|
+
- 🛡️ **Error Handling** - Comprehensive error types for better debugging
|
|
16
|
+
- 🔌 **Flexible** - Works with Node.js, Deno, and modern browsers
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @dooor-ai/cortexdb
|
|
22
|
+
# or
|
|
23
|
+
yarn add @dooor-ai/cortexdb
|
|
24
|
+
# or
|
|
25
|
+
pnpm add @dooor-ai/cortexdb
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- Node.js >= 18.0.0 (uses native `fetch`)
|
|
31
|
+
- CortexDB gateway running (default: `http://localhost:8000`)
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { CortexClient, FieldType } from '@dooor-ai/cortexdb';
|
|
37
|
+
|
|
38
|
+
async function main() {
|
|
39
|
+
// Initialize client
|
|
40
|
+
const client = new CortexClient({
|
|
41
|
+
baseUrl: 'http://localhost:8000',
|
|
42
|
+
// apiKey: 'YOUR_API_KEY', // Optional: if authentication is enabled
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Check health
|
|
46
|
+
const isHealthy = await client.healthcheck();
|
|
47
|
+
console.log('CortexDB:', isHealthy ? 'Connected ✓' : 'Disconnected ✗');
|
|
48
|
+
|
|
49
|
+
// Create a collection
|
|
50
|
+
await client.collections.create('my_docs', [
|
|
51
|
+
{ name: 'title', type: FieldType.STRING },
|
|
52
|
+
{ name: 'content', type: FieldType.STRING },
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
// Create a record
|
|
56
|
+
const record = await client.records.create('my_docs', {
|
|
57
|
+
title: 'Hello World',
|
|
58
|
+
content: 'This is my first document',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log('Created:', record.id);
|
|
62
|
+
|
|
63
|
+
// Get the record
|
|
64
|
+
const fetched = await client.records.get('my_docs', record.id);
|
|
65
|
+
console.log('Fetched:', fetched.data);
|
|
66
|
+
|
|
67
|
+
// List all records
|
|
68
|
+
const results = await client.records.list('my_docs');
|
|
69
|
+
console.log('Total:', results.total);
|
|
70
|
+
|
|
71
|
+
// Clean up
|
|
72
|
+
await client.collections.delete('my_docs');
|
|
73
|
+
await client.close();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Semantic Search Example
|
|
80
|
+
|
|
81
|
+
Enable semantic search by creating a collection with `vectorize: true` and an embedding provider:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { CortexClient, FieldType } from '@dooor-ai/cortexdb';
|
|
85
|
+
|
|
86
|
+
async function semanticSearch() {
|
|
87
|
+
const client = new CortexClient({ baseUrl: 'http://localhost:8000' });
|
|
88
|
+
|
|
89
|
+
// Create collection with vectorization
|
|
90
|
+
await client.collections.create(
|
|
91
|
+
'knowledge_base',
|
|
92
|
+
[
|
|
93
|
+
{ name: 'title', type: FieldType.STRING },
|
|
94
|
+
{ name: 'content', type: FieldType.STRING, vectorize: true },
|
|
95
|
+
],
|
|
96
|
+
'your-embedding-provider-id' // Required for vectorization
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Add documents
|
|
100
|
+
await client.records.create('knowledge_base', {
|
|
101
|
+
title: 'Machine Learning',
|
|
102
|
+
content: 'ML is a branch of AI that focuses on learning from data.',
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
await client.records.create('knowledge_base', {
|
|
106
|
+
title: 'Deep Learning',
|
|
107
|
+
content: 'Deep learning uses neural networks with multiple layers.',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Perform semantic search
|
|
111
|
+
const results = await client.records.search(
|
|
112
|
+
'knowledge_base',
|
|
113
|
+
'What is artificial intelligence?',
|
|
114
|
+
undefined, // filters
|
|
115
|
+
5 // limit
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
results.results.forEach((result) => {
|
|
119
|
+
console.log(`${result.record.data.title} (score: ${result.score})`);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
await client.close();
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## API Reference
|
|
127
|
+
|
|
128
|
+
### CortexClient
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
const client = new CortexClient({
|
|
132
|
+
baseUrl?: string; // Default: 'http://localhost:8000'
|
|
133
|
+
apiKey?: string; // Optional API key
|
|
134
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Methods
|
|
139
|
+
|
|
140
|
+
- `health()` - Get health status
|
|
141
|
+
- `healthcheck()` - Returns boolean health status
|
|
142
|
+
- `close()` - Close the client
|
|
143
|
+
|
|
144
|
+
### Collections API
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
// List all collections
|
|
148
|
+
const collections = await client.collections.list();
|
|
149
|
+
|
|
150
|
+
// Get a collection
|
|
151
|
+
const collection = await client.collections.get('my_collection');
|
|
152
|
+
|
|
153
|
+
// Create a collection
|
|
154
|
+
await client.collections.create(
|
|
155
|
+
'my_collection',
|
|
156
|
+
[
|
|
157
|
+
{ name: 'title', type: FieldType.STRING, required: true },
|
|
158
|
+
{ name: 'content', type: FieldType.STRING, vectorize: true },
|
|
159
|
+
],
|
|
160
|
+
'embedding-provider-id' // Optional: required if vectorize is true
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
// Update a collection
|
|
164
|
+
await client.collections.update('my_collection', fields, embeddingProvider);
|
|
165
|
+
|
|
166
|
+
// Delete a collection
|
|
167
|
+
await client.collections.delete('my_collection');
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Records API
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
// Create a record
|
|
174
|
+
const record = await client.records.create('collection_name', {
|
|
175
|
+
title: 'My Document',
|
|
176
|
+
content: 'Document content...',
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Get a record
|
|
180
|
+
const record = await client.records.get('collection_name', 'record-id');
|
|
181
|
+
|
|
182
|
+
// List records with filters
|
|
183
|
+
const results = await client.records.list('collection_name', {
|
|
184
|
+
filters: { year: 2024 },
|
|
185
|
+
limit: 10,
|
|
186
|
+
offset: 0,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// Update a record
|
|
190
|
+
await client.records.update('collection_name', 'record-id', {
|
|
191
|
+
title: 'Updated Title',
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Delete a record
|
|
195
|
+
await client.records.delete('collection_name', 'record-id');
|
|
196
|
+
|
|
197
|
+
// Semantic search
|
|
198
|
+
const results = await client.records.search(
|
|
199
|
+
'collection_name',
|
|
200
|
+
'search query',
|
|
201
|
+
{ category: 'tech' }, // optional filters
|
|
202
|
+
10 // limit
|
|
203
|
+
);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Field Types
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { FieldType, StoreLocation } from '@cortexdb/sdk';
|
|
210
|
+
|
|
211
|
+
const field = {
|
|
212
|
+
name: 'my_field',
|
|
213
|
+
type: FieldType.STRING, // STRING, NUMBER, BOOLEAN, FILE, ARRAY
|
|
214
|
+
vectorize: true, // Enable semantic search
|
|
215
|
+
required: false, // Make field required
|
|
216
|
+
store_in: [ // Storage locations
|
|
217
|
+
StoreLocation.POSTGRES,
|
|
218
|
+
StoreLocation.QDRANT_PAYLOAD,
|
|
219
|
+
],
|
|
220
|
+
};
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Error Handling
|
|
224
|
+
|
|
225
|
+
The SDK provides specific error types for better error handling:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import {
|
|
229
|
+
CortexDBError,
|
|
230
|
+
CortexDBConnectionError,
|
|
231
|
+
CortexDBTimeoutError,
|
|
232
|
+
CortexDBNotFoundError,
|
|
233
|
+
CortexDBValidationError,
|
|
234
|
+
CortexDBAuthenticationError,
|
|
235
|
+
CortexDBPermissionError,
|
|
236
|
+
CortexDBServerError,
|
|
237
|
+
} from '@cortexdb/sdk';
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
await client.records.get('collection', 'invalid-id');
|
|
241
|
+
} catch (error) {
|
|
242
|
+
if (error instanceof CortexDBNotFoundError) {
|
|
243
|
+
console.log('Record not found');
|
|
244
|
+
} else if (error instanceof CortexDBConnectionError) {
|
|
245
|
+
console.log('Connection failed');
|
|
246
|
+
} else if (error instanceof CortexDBTimeoutError) {
|
|
247
|
+
console.log('Request timed out');
|
|
248
|
+
} else {
|
|
249
|
+
console.log('Unknown error:', error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Examples
|
|
255
|
+
|
|
256
|
+
Check out the [examples](./examples) directory for more:
|
|
257
|
+
|
|
258
|
+
- [quickstart.ts](./examples/quickstart.ts) - Complete quickstart guide
|
|
259
|
+
- [search.ts](./examples/search.ts) - Semantic search with filters
|
|
260
|
+
- [basic.ts](./examples/basic.ts) - Basic operations
|
|
261
|
+
|
|
262
|
+
Run examples:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
cd examples
|
|
266
|
+
npx ts-node -O '{"module":"commonjs"}' quickstart.ts
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Development
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# Install dependencies
|
|
273
|
+
npm install
|
|
274
|
+
|
|
275
|
+
# Build
|
|
276
|
+
npm run build
|
|
277
|
+
|
|
278
|
+
# Watch mode
|
|
279
|
+
npm run build:watch
|
|
280
|
+
|
|
281
|
+
# Clean
|
|
282
|
+
npm run clean
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Contributing
|
|
286
|
+
|
|
287
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
292
|
+
|
|
293
|
+
## Support
|
|
294
|
+
|
|
295
|
+
- 📖 [Documentation](https://github.com/cortexdb/cortexdb)
|
|
296
|
+
- 🐛 [Issue Tracker](https://github.com/cortexdb/cortexdb/issues)
|
|
297
|
+
- 💬 [Discussions](https://github.com/cortexdb/cortexdb/discussions)
|
|
298
|
+
|
|
299
|
+
## Related
|
|
300
|
+
|
|
301
|
+
- [CortexDB Python SDK](../python) - Python client for CortexDB
|
|
302
|
+
- [CortexDB Gateway](../../gateway) - CortexDB backend service
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Main CortexDB client */
|
|
2
|
+
import { CollectionsAPI } from "../collections/api";
|
|
3
|
+
import { RecordsAPI } from "../records/api";
|
|
4
|
+
export interface CortexClientOptions {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class CortexClient {
|
|
10
|
+
private http;
|
|
11
|
+
collections: CollectionsAPI;
|
|
12
|
+
records: RecordsAPI;
|
|
13
|
+
constructor(options?: CortexClientOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Check if the connection to CortexDB is working
|
|
16
|
+
*/
|
|
17
|
+
health(): Promise<{
|
|
18
|
+
status: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Shorthand for health check that returns boolean
|
|
22
|
+
*/
|
|
23
|
+
healthcheck(): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Close the client (cleanup if needed)
|
|
26
|
+
*/
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAG3B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAAa;IAClB,WAAW,EAAE,cAAc,CAAC;IAC5B,OAAO,EAAE,UAAU,CAAC;gBAEf,OAAO,GAAE,mBAAwB;IAY7C;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAI3C;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IASrC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Main CortexDB client */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CortexClient = void 0;
|
|
5
|
+
const client_1 = require("../http/client");
|
|
6
|
+
const api_1 = require("../collections/api");
|
|
7
|
+
const api_2 = require("../records/api");
|
|
8
|
+
class CortexClient {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
const { baseUrl = "http://localhost:8000", apiKey, timeout = 30000, } = options;
|
|
11
|
+
this.http = new client_1.HTTPClient(baseUrl, apiKey, timeout);
|
|
12
|
+
this.collections = new api_1.CollectionsAPI(this.http);
|
|
13
|
+
this.records = new api_2.RecordsAPI(this.http);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if the connection to CortexDB is working
|
|
17
|
+
*/
|
|
18
|
+
async health() {
|
|
19
|
+
return this.http.get("/health");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Shorthand for health check that returns boolean
|
|
23
|
+
*/
|
|
24
|
+
async healthcheck() {
|
|
25
|
+
try {
|
|
26
|
+
const response = await this.health();
|
|
27
|
+
return response.status === "ok";
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Close the client (cleanup if needed)
|
|
35
|
+
*/
|
|
36
|
+
async close() {
|
|
37
|
+
// Future: cleanup connections, cancel pending requests, etc.
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.CortexClient = CortexClient;
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;AAE3B,2CAA4C;AAC5C,4CAAoD;AACpD,wCAA4C;AAQ5C,MAAa,YAAY;IAKvB,YAAY,UAA+B,EAAE;QAC3C,MAAM,EACJ,OAAO,GAAG,uBAAuB,EACjC,MAAM,EACN,OAAO,GAAG,KAAK,GAChB,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,IAAI,GAAG,IAAI,mBAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,IAAI,oBAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,IAAI,gBAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW;QACf,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;YACrC,OAAO,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,6DAA6D;IAC/D,CAAC;CACF;AA1CD,oCA0CC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collections API for CortexDB
|
|
3
|
+
*
|
|
4
|
+
* Provides methods to create, read, update, and delete collections.
|
|
5
|
+
* Collections define the schema and structure for records.
|
|
6
|
+
*/
|
|
7
|
+
import { Collection, FieldDefinition } from "../types";
|
|
8
|
+
import { HTTPClient } from "../http/client";
|
|
9
|
+
/**
|
|
10
|
+
* API for managing CortexDB collections
|
|
11
|
+
*/
|
|
12
|
+
export declare class CollectionsAPI {
|
|
13
|
+
private http;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new CollectionsAPI instance
|
|
16
|
+
*
|
|
17
|
+
* @param http - HTTP client for making requests
|
|
18
|
+
*/
|
|
19
|
+
constructor(http: HTTPClient);
|
|
20
|
+
/**
|
|
21
|
+
* List all collections in the database
|
|
22
|
+
*
|
|
23
|
+
* @returns Array of all collections
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const collections = await client.collections.list();
|
|
27
|
+
* console.log(`Found ${collections.length} collections`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
list(): Promise<Collection[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Get a specific collection by name
|
|
33
|
+
*
|
|
34
|
+
* @param name - Name of the collection to retrieve
|
|
35
|
+
* @returns Collection details including schema
|
|
36
|
+
* @throws {CortexDBNotFoundError} If collection doesn't exist
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const collection = await client.collections.get('my_collection');
|
|
40
|
+
* console.log(collection.fields);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
get(name: string): Promise<Collection>;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new collection with the specified schema
|
|
46
|
+
*
|
|
47
|
+
* @param name - Name for the new collection
|
|
48
|
+
* @param fields - Array of field definitions
|
|
49
|
+
* @param embedding_provider - Optional embedding provider ID (required if any field has vectorize=true)
|
|
50
|
+
* @returns Created collection details
|
|
51
|
+
* @throws {CortexDBValidationError} If schema is invalid or embedding provider is missing when required
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const collection = await client.collections.create('documents', [
|
|
55
|
+
* { name: 'title', type: FieldType.STRING },
|
|
56
|
+
* { name: 'content', type: FieldType.STRING, vectorize: true }
|
|
57
|
+
* ], 'embedding-provider-id');
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
create(name: string, fields: FieldDefinition[], embedding_provider?: string): Promise<Collection>;
|
|
61
|
+
/**
|
|
62
|
+
* Update an existing collection's schema
|
|
63
|
+
*
|
|
64
|
+
* @param name - Name of the collection to update
|
|
65
|
+
* @param fields - New field definitions
|
|
66
|
+
* @returns Updated collection details
|
|
67
|
+
* @throws {CortexDBNotFoundError} If collection doesn't exist
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const updated = await client.collections.update('documents', [
|
|
71
|
+
* { name: 'title', type: FieldType.STRING },
|
|
72
|
+
* { name: 'description', type: FieldType.STRING }
|
|
73
|
+
* ]);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
update(name: string, fields: FieldDefinition[]): Promise<Collection>;
|
|
77
|
+
/**
|
|
78
|
+
* Delete a collection and all its records
|
|
79
|
+
*
|
|
80
|
+
* @param name - Name of the collection to delete
|
|
81
|
+
* @throws {CortexDBNotFoundError} If collection doesn't exist
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* await client.collections.delete('old_collection');
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
delete(name: string): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/collections/api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAoB,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,qBAAa,cAAc;IAMb,OAAO,CAAC,IAAI;IALxB;;;;OAIG;gBACiB,IAAI,EAAE,UAAU;IAEpC;;;;;;;;;OASG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAInC;;;;;;;;;;;OAWG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI5C;;;;;;;;;;;;;;;OAeG;IACG,MAAM,CACV,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,EAAE,EACzB,kBAAkB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC,UAAU,CAAC;IAQtB;;;;;;;;;;;;;;OAcG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAI1E;;;;;;;;;OASG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG1C"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Collections API for CortexDB
|
|
4
|
+
*
|
|
5
|
+
* Provides methods to create, read, update, and delete collections.
|
|
6
|
+
* Collections define the schema and structure for records.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CollectionsAPI = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* API for managing CortexDB collections
|
|
12
|
+
*/
|
|
13
|
+
class CollectionsAPI {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new CollectionsAPI instance
|
|
16
|
+
*
|
|
17
|
+
* @param http - HTTP client for making requests
|
|
18
|
+
*/
|
|
19
|
+
constructor(http) {
|
|
20
|
+
this.http = http;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* List all collections in the database
|
|
24
|
+
*
|
|
25
|
+
* @returns Array of all collections
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const collections = await client.collections.list();
|
|
29
|
+
* console.log(`Found ${collections.length} collections`);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
async list() {
|
|
33
|
+
return this.http.get("/collections");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get a specific collection by name
|
|
37
|
+
*
|
|
38
|
+
* @param name - Name of the collection to retrieve
|
|
39
|
+
* @returns Collection details including schema
|
|
40
|
+
* @throws {CortexDBNotFoundError} If collection doesn't exist
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const collection = await client.collections.get('my_collection');
|
|
44
|
+
* console.log(collection.fields);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
async get(name) {
|
|
48
|
+
return this.http.get(`/collections/${name}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a new collection with the specified schema
|
|
52
|
+
*
|
|
53
|
+
* @param name - Name for the new collection
|
|
54
|
+
* @param fields - Array of field definitions
|
|
55
|
+
* @param embedding_provider - Optional embedding provider ID (required if any field has vectorize=true)
|
|
56
|
+
* @returns Created collection details
|
|
57
|
+
* @throws {CortexDBValidationError} If schema is invalid or embedding provider is missing when required
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const collection = await client.collections.create('documents', [
|
|
61
|
+
* { name: 'title', type: FieldType.STRING },
|
|
62
|
+
* { name: 'content', type: FieldType.STRING, vectorize: true }
|
|
63
|
+
* ], 'embedding-provider-id');
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async create(name, fields, embedding_provider) {
|
|
67
|
+
const payload = { name, fields };
|
|
68
|
+
if (embedding_provider) {
|
|
69
|
+
payload.config = { embedding_provider_id: embedding_provider };
|
|
70
|
+
}
|
|
71
|
+
return this.http.post("/collections", payload);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Update an existing collection's schema
|
|
75
|
+
*
|
|
76
|
+
* @param name - Name of the collection to update
|
|
77
|
+
* @param fields - New field definitions
|
|
78
|
+
* @returns Updated collection details
|
|
79
|
+
* @throws {CortexDBNotFoundError} If collection doesn't exist
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const updated = await client.collections.update('documents', [
|
|
83
|
+
* { name: 'title', type: FieldType.STRING },
|
|
84
|
+
* { name: 'description', type: FieldType.STRING }
|
|
85
|
+
* ]);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
async update(name, fields) {
|
|
89
|
+
return this.http.put(`/collections/${name}`, { fields });
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Delete a collection and all its records
|
|
93
|
+
*
|
|
94
|
+
* @param name - Name of the collection to delete
|
|
95
|
+
* @throws {CortexDBNotFoundError} If collection doesn't exist
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* await client.collections.delete('old_collection');
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
async delete(name) {
|
|
102
|
+
await this.http.delete(`/collections/${name}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.CollectionsAPI = CollectionsAPI;
|
|
106
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/collections/api.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAKH;;GAEG;AACH,MAAa,cAAc;IACzB;;;;OAIG;IACH,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAe,cAAc,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAa,gBAAgB,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,MAAM,CACV,IAAY,EACZ,MAAyB,EACzB,kBAA2B;QAE3B,MAAM,OAAO,GAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACtC,IAAI,kBAAkB,EAAE,CAAC;YACvB,OAAO,CAAC,MAAM,GAAG,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAa,cAAc,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,MAAyB;QAClD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAa,gBAAgB,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;AAlGD,wCAkGC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Custom exceptions for CortexDB SDK */
|
|
2
|
+
/**
|
|
3
|
+
* Base exception for all CortexDB errors
|
|
4
|
+
*/
|
|
5
|
+
export declare class CortexDBError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Exception raised for connection errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class CortexDBConnectionError extends CortexDBError {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Exception raised for timeout errors
|
|
16
|
+
*/
|
|
17
|
+
export declare class CortexDBTimeoutError extends CortexDBError {
|
|
18
|
+
constructor(message?: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Exception raised for 404 Not Found errors
|
|
22
|
+
*/
|
|
23
|
+
export declare class CortexDBNotFoundError extends CortexDBError {
|
|
24
|
+
constructor(message?: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Exception raised for validation errors (400)
|
|
28
|
+
*/
|
|
29
|
+
export declare class CortexDBValidationError extends CortexDBError {
|
|
30
|
+
constructor(message?: string);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Exception raised for authentication errors (401)
|
|
34
|
+
*/
|
|
35
|
+
export declare class CortexDBAuthenticationError extends CortexDBError {
|
|
36
|
+
constructor(message?: string);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Exception raised for permission errors (403)
|
|
40
|
+
*/
|
|
41
|
+
export declare class CortexDBPermissionError extends CortexDBError {
|
|
42
|
+
constructor(message?: string);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Exception raised for server errors (5xx)
|
|
46
|
+
*/
|
|
47
|
+
export declare class CortexDBServerError extends CortexDBError {
|
|
48
|
+
constructor(message?: string);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;gBAC5C,OAAO,GAAE,MAAwC;CAK9D;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;gBACzC,OAAO,GAAE,MAA4B;CAKlD;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,aAAa;gBAC1C,OAAO,GAAE,MAA6B;CAKnD;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;gBAC5C,OAAO,GAAE,MAA2B;CAKjD;AAED;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,aAAa;gBAChD,OAAO,GAAE,MAAgC;CAKtD;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;gBAC5C,OAAO,GAAE,MAA4B;CAKlD;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,GAAE,MAAuB;CAK7C"}
|