@dooor-ai/cortexdb 0.1.0 → 0.1.1
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/README.md +170 -182
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
# CortexDB TypeScript
|
|
1
|
+
# CortexDB TypeScript SDK
|
|
2
2
|
|
|
3
|
-
Official TypeScript/JavaScript client for
|
|
4
|
-
|
|
5
|
-
[](https://badge.fury.io/js/%40dooor-ai%2Fcortexdb)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
Official TypeScript/JavaScript client for CortexDB - Multi-modal RAG Platform.
|
|
7
4
|
|
|
8
5
|
## Features
|
|
9
6
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- 🔌 **Flexible** - Works with Node.js, Deno, and modern browsers
|
|
7
|
+
- Full TypeScript support with type definitions
|
|
8
|
+
- Async/await API using native fetch
|
|
9
|
+
- Semantic search with vector embeddings
|
|
10
|
+
- Collection and record management
|
|
11
|
+
- Custom error types for better debugging
|
|
12
|
+
- Works with Node.js 18+, Deno, and modern browsers
|
|
17
13
|
|
|
18
14
|
## Installation
|
|
19
15
|
|
|
20
16
|
```bash
|
|
21
17
|
npm install @dooor-ai/cortexdb
|
|
22
|
-
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or with yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
23
|
yarn add @dooor-ai/cortexdb
|
|
24
|
-
# or
|
|
25
|
-
pnpm add @dooor-ai/cortexdb
|
|
26
24
|
```
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
Or with pnpm:
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @dooor-ai/cortexdb
|
|
30
|
+
```
|
|
32
31
|
|
|
33
32
|
## Quick Start
|
|
34
33
|
|
|
@@ -36,242 +35,235 @@ pnpm add @dooor-ai/cortexdb
|
|
|
36
35
|
import { CortexClient, FieldType } from '@dooor-ai/cortexdb';
|
|
37
36
|
|
|
38
37
|
async function main() {
|
|
39
|
-
// Initialize client
|
|
40
38
|
const client = new CortexClient({
|
|
41
|
-
baseUrl: 'http://localhost:8000'
|
|
42
|
-
// apiKey: 'YOUR_API_KEY', // Optional: if authentication is enabled
|
|
39
|
+
baseUrl: 'http://localhost:8000'
|
|
43
40
|
});
|
|
44
41
|
|
|
45
|
-
// Check health
|
|
46
|
-
const isHealthy = await client.healthcheck();
|
|
47
|
-
console.log('CortexDB:', isHealthy ? 'Connected ✓' : 'Disconnected ✗');
|
|
48
|
-
|
|
49
42
|
// Create a collection
|
|
50
|
-
await client.collections.create('
|
|
43
|
+
await client.collections.create('documents', [
|
|
51
44
|
{ name: 'title', type: FieldType.STRING },
|
|
52
|
-
{ name: 'content', type: FieldType.STRING }
|
|
45
|
+
{ name: 'content', type: FieldType.STRING, vectorize: true }
|
|
53
46
|
]);
|
|
54
47
|
|
|
55
48
|
// Create a record
|
|
56
|
-
const record = await client.records.create('
|
|
49
|
+
const record = await client.records.create('documents', {
|
|
57
50
|
title: 'Hello World',
|
|
58
|
-
content: 'This is my first document'
|
|
51
|
+
content: 'This is my first document'
|
|
59
52
|
});
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
// Semantic search
|
|
55
|
+
const results = await client.records.search(
|
|
56
|
+
'documents',
|
|
57
|
+
'hello world',
|
|
58
|
+
undefined,
|
|
59
|
+
10
|
|
60
|
+
);
|
|
66
61
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
results.results.forEach(result => {
|
|
63
|
+
console.log(`Score: ${result.score.toFixed(4)} - ${result.record.data.title}`);
|
|
64
|
+
});
|
|
70
65
|
|
|
71
|
-
// Clean up
|
|
72
|
-
await client.collections.delete('my_docs');
|
|
73
66
|
await client.close();
|
|
74
67
|
}
|
|
75
68
|
|
|
76
69
|
main();
|
|
77
70
|
```
|
|
78
71
|
|
|
79
|
-
##
|
|
72
|
+
## Usage
|
|
80
73
|
|
|
81
|
-
|
|
74
|
+
### Initialize Client
|
|
82
75
|
|
|
83
76
|
```typescript
|
|
84
|
-
import { CortexClient
|
|
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
|
-
);
|
|
77
|
+
import { CortexClient } from '@dooor-ai/cortexdb';
|
|
98
78
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|
79
|
+
// Local development
|
|
80
|
+
const client = new CortexClient({
|
|
81
|
+
baseUrl: 'http://localhost:8000'
|
|
82
|
+
});
|
|
127
83
|
|
|
128
|
-
|
|
84
|
+
// With API key
|
|
85
|
+
const client = new CortexClient({
|
|
86
|
+
baseUrl: 'https://api.cortexdb.com',
|
|
87
|
+
apiKey: 'your-api-key'
|
|
88
|
+
});
|
|
129
89
|
|
|
130
|
-
|
|
90
|
+
// Custom timeout
|
|
131
91
|
const client = new CortexClient({
|
|
132
|
-
baseUrl
|
|
133
|
-
|
|
134
|
-
timeout?: number; // Request timeout in ms (default: 30000)
|
|
92
|
+
baseUrl: 'http://localhost:8000',
|
|
93
|
+
timeout: 60000 // 60 seconds
|
|
135
94
|
});
|
|
136
95
|
```
|
|
137
96
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
- `health()` - Get health status
|
|
141
|
-
- `healthcheck()` - Returns boolean health status
|
|
142
|
-
- `close()` - Close the client
|
|
143
|
-
|
|
144
|
-
### Collections API
|
|
97
|
+
### Collections
|
|
145
98
|
|
|
146
99
|
```typescript
|
|
147
|
-
|
|
148
|
-
|
|
100
|
+
import { FieldType, StoreLocation } from '@dooor-ai/cortexdb';
|
|
101
|
+
|
|
102
|
+
// Create collection
|
|
103
|
+
const collection = await client.collections.create('articles', [
|
|
104
|
+
{
|
|
105
|
+
name: 'title',
|
|
106
|
+
type: FieldType.STRING
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'content',
|
|
110
|
+
type: FieldType.STRING,
|
|
111
|
+
vectorize: true // Enable semantic search
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'year',
|
|
115
|
+
type: FieldType.NUMBER,
|
|
116
|
+
store_in: [StoreLocation.POSTGRES, StoreLocation.QDRANT_PAYLOAD]
|
|
117
|
+
}
|
|
118
|
+
]);
|
|
149
119
|
|
|
150
|
-
//
|
|
151
|
-
const
|
|
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
|
-
);
|
|
120
|
+
// List collections
|
|
121
|
+
const collections = await client.collections.list();
|
|
162
122
|
|
|
163
|
-
//
|
|
164
|
-
await client.collections.
|
|
123
|
+
// Get collection
|
|
124
|
+
const schema = await client.collections.get('articles');
|
|
165
125
|
|
|
166
|
-
// Delete
|
|
167
|
-
await client.collections.delete('
|
|
126
|
+
// Delete collection
|
|
127
|
+
await client.collections.delete('articles');
|
|
168
128
|
```
|
|
169
129
|
|
|
170
|
-
### Records
|
|
130
|
+
### Records
|
|
171
131
|
|
|
172
132
|
```typescript
|
|
173
|
-
// Create
|
|
174
|
-
const record = await client.records.create('
|
|
175
|
-
title: '
|
|
176
|
-
content: '
|
|
133
|
+
// Create record
|
|
134
|
+
const record = await client.records.create('articles', {
|
|
135
|
+
title: 'Machine Learning Basics',
|
|
136
|
+
content: 'Introduction to ML concepts...',
|
|
137
|
+
year: 2024
|
|
177
138
|
});
|
|
178
139
|
|
|
179
|
-
// Get
|
|
180
|
-
const
|
|
140
|
+
// Get record by ID
|
|
141
|
+
const fetched = await client.records.get('articles', record.id);
|
|
181
142
|
|
|
182
|
-
//
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
limit: 10,
|
|
186
|
-
offset: 0,
|
|
143
|
+
// Update record
|
|
144
|
+
const updated = await client.records.update('articles', record.id, {
|
|
145
|
+
year: 2025
|
|
187
146
|
});
|
|
188
147
|
|
|
189
|
-
//
|
|
190
|
-
await client.records.
|
|
191
|
-
|
|
148
|
+
// Delete record
|
|
149
|
+
await client.records.delete('articles', record.id);
|
|
150
|
+
|
|
151
|
+
// List records
|
|
152
|
+
const results = await client.records.list('articles', {
|
|
153
|
+
limit: 10,
|
|
154
|
+
offset: 0
|
|
192
155
|
});
|
|
156
|
+
```
|
|
193
157
|
|
|
194
|
-
|
|
195
|
-
await client.records.delete('collection_name', 'record-id');
|
|
158
|
+
### Semantic Search
|
|
196
159
|
|
|
197
|
-
|
|
160
|
+
```typescript
|
|
161
|
+
// Basic search
|
|
198
162
|
const results = await client.records.search(
|
|
199
|
-
'
|
|
200
|
-
'
|
|
201
|
-
|
|
202
|
-
10
|
|
163
|
+
'articles',
|
|
164
|
+
'machine learning fundamentals',
|
|
165
|
+
undefined,
|
|
166
|
+
10
|
|
203
167
|
);
|
|
168
|
+
|
|
169
|
+
// Search with filters
|
|
170
|
+
const filteredResults = await client.records.search(
|
|
171
|
+
'articles',
|
|
172
|
+
'neural networks',
|
|
173
|
+
{
|
|
174
|
+
year: 2024,
|
|
175
|
+
category: 'AI'
|
|
176
|
+
},
|
|
177
|
+
5
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// Process results
|
|
181
|
+
filteredResults.results.forEach(result => {
|
|
182
|
+
console.log(`Score: ${result.score.toFixed(4)}`);
|
|
183
|
+
console.log(`Title: ${result.record.data.title}`);
|
|
184
|
+
console.log(`Year: ${result.record.data.year}`);
|
|
185
|
+
});
|
|
204
186
|
```
|
|
205
187
|
|
|
206
|
-
|
|
188
|
+
### Filter Operators
|
|
207
189
|
|
|
208
190
|
```typescript
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
191
|
+
// Exact match
|
|
192
|
+
const results = await client.records.list('articles', {
|
|
193
|
+
filters: {
|
|
194
|
+
category: 'technology',
|
|
195
|
+
published: true
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// Combine filters
|
|
200
|
+
const filtered = await client.records.list('articles', {
|
|
201
|
+
filters: {
|
|
202
|
+
year: 2024,
|
|
203
|
+
category: 'AI'
|
|
204
|
+
},
|
|
205
|
+
limit: 20
|
|
206
|
+
});
|
|
221
207
|
```
|
|
222
208
|
|
|
223
209
|
## Error Handling
|
|
224
210
|
|
|
225
|
-
The SDK provides specific error types for better error handling:
|
|
226
|
-
|
|
227
211
|
```typescript
|
|
228
212
|
import {
|
|
229
213
|
CortexDBError,
|
|
230
|
-
CortexDBConnectionError,
|
|
231
|
-
CortexDBTimeoutError,
|
|
232
214
|
CortexDBNotFoundError,
|
|
233
215
|
CortexDBValidationError,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
CortexDBServerError,
|
|
237
|
-
} from '@cortexdb/sdk';
|
|
216
|
+
CortexDBConnectionError
|
|
217
|
+
} from '@dooor-ai/cortexdb';
|
|
238
218
|
|
|
239
219
|
try {
|
|
240
|
-
await client.records.get('
|
|
220
|
+
const record = await client.records.get('articles', 'invalid-id');
|
|
241
221
|
} catch (error) {
|
|
242
222
|
if (error instanceof CortexDBNotFoundError) {
|
|
243
223
|
console.log('Record not found');
|
|
224
|
+
} else if (error instanceof CortexDBValidationError) {
|
|
225
|
+
console.log('Validation error:', error.message);
|
|
244
226
|
} else if (error instanceof CortexDBConnectionError) {
|
|
245
|
-
console.log('Connection failed');
|
|
246
|
-
} else if (error instanceof
|
|
247
|
-
console.log('
|
|
248
|
-
} else {
|
|
249
|
-
console.log('Unknown error:', error);
|
|
227
|
+
console.log('Connection failed:', error.message);
|
|
228
|
+
} else if (error instanceof CortexDBError) {
|
|
229
|
+
console.log('General error:', error.message);
|
|
250
230
|
}
|
|
251
231
|
}
|
|
252
232
|
```
|
|
253
233
|
|
|
254
234
|
## Examples
|
|
255
235
|
|
|
256
|
-
Check
|
|
236
|
+
Check the [`examples/`](./examples) directory for more usage examples:
|
|
257
237
|
|
|
258
|
-
- [quickstart.ts](./examples/quickstart.ts) -
|
|
259
|
-
- [search.ts](./examples/search.ts) - Semantic search with filters
|
|
260
|
-
- [basic.ts](./examples/basic.ts) - Basic operations
|
|
238
|
+
- [`quickstart.ts`](./examples/quickstart.ts) - Walkthrough of SDK features
|
|
239
|
+
- [`search.ts`](./examples/search.ts) - Semantic search with filters
|
|
240
|
+
- [`basic.ts`](./examples/basic.ts) - Basic operations
|
|
261
241
|
|
|
262
242
|
Run examples:
|
|
263
243
|
|
|
264
244
|
```bash
|
|
265
|
-
|
|
266
|
-
npx ts-node -O '{"module":"commonjs"}' quickstart.ts
|
|
245
|
+
npx ts-node -O '{"module":"commonjs"}' examples/quickstart.ts
|
|
267
246
|
```
|
|
268
247
|
|
|
269
248
|
## Development
|
|
270
249
|
|
|
250
|
+
### Setup
|
|
251
|
+
|
|
271
252
|
```bash
|
|
253
|
+
# Clone repository
|
|
254
|
+
git clone https://github.com/yourusername/cortexdb
|
|
255
|
+
cd cortexdb/clients/typescript
|
|
256
|
+
|
|
272
257
|
# Install dependencies
|
|
273
258
|
npm install
|
|
274
259
|
|
|
260
|
+
# Build
|
|
261
|
+
npm run build
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Scripts
|
|
265
|
+
|
|
266
|
+
```bash
|
|
275
267
|
# Build
|
|
276
268
|
npm run build
|
|
277
269
|
|
|
@@ -280,23 +272,19 @@ npm run build:watch
|
|
|
280
272
|
|
|
281
273
|
# Clean
|
|
282
274
|
npm run clean
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
## Contributing
|
|
286
|
-
|
|
287
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
288
275
|
|
|
289
|
-
|
|
276
|
+
# Lint
|
|
277
|
+
npm run lint
|
|
290
278
|
|
|
291
|
-
|
|
279
|
+
# Format
|
|
280
|
+
npm run format
|
|
281
|
+
```
|
|
292
282
|
|
|
293
|
-
##
|
|
283
|
+
## Requirements
|
|
294
284
|
|
|
295
|
-
-
|
|
296
|
-
-
|
|
297
|
-
- 💬 [Discussions](https://github.com/cortexdb/cortexdb/discussions)
|
|
285
|
+
- Node.js >= 18.0.0
|
|
286
|
+
- CortexDB gateway running (local or remote)
|
|
298
287
|
|
|
299
|
-
##
|
|
288
|
+
## License
|
|
300
289
|
|
|
301
|
-
- [
|
|
302
|
-
- [CortexDB Gateway](../../gateway) - CortexDB backend service
|
|
290
|
+
MIT License - see [LICENSE](./LICENSE) for details.
|
package/package.json
CHANGED