@dooor-ai/cortexdb 0.1.1 → 0.2.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/README.md CHANGED
@@ -1,15 +1,29 @@
1
1
  # CortexDB TypeScript SDK
2
2
 
3
- Official TypeScript/JavaScript client for CortexDB - Multi-modal RAG Platform.
3
+ Official TypeScript/JavaScript client for CortexDB.
4
+
5
+ ## What is CortexDB?
6
+
7
+ CortexDB is a multi-modal RAG (Retrieval Augmented Generation) platform that combines traditional database capabilities with vector search and advanced document processing. It enables you to:
8
+
9
+ - Store structured and unstructured data in a unified database
10
+ - Automatically extract text from documents (PDF, DOCX, XLSX) using Docling
11
+ - Generate embeddings for semantic search using various providers (OpenAI, Gemini, etc.)
12
+ - Perform hybrid search combining filters with vector similarity
13
+ - Build RAG applications with automatic chunking and vectorization
14
+
15
+ CortexDB handles the complex infrastructure of vector databases (Qdrant), object storage (MinIO), and traditional databases (PostgreSQL) behind a simple API.
4
16
 
5
17
  ## Features
6
18
 
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
19
+ - **Multi-modal document processing**: Upload PDFs, DOCX, XLSX files and automatically extract text with OCR fallback
20
+ - **Semantic search**: Vector-based search using embeddings from OpenAI, Gemini, or custom providers
21
+ - **Automatic chunking**: Smart text splitting optimized for RAG applications
22
+ - **Flexible schema**: Define collections with typed fields (string, number, boolean, file, array)
23
+ - **Hybrid queries**: Combine exact filters with semantic search
24
+ - **Storage control**: Choose where each field is stored (PostgreSQL, Qdrant, MinIO)
25
+ - **Type-safe**: Full TypeScript support with comprehensive type definitions
26
+ - **Modern API**: Async/await using native fetch (Node.js 18+)
13
27
 
14
28
  ## Installation
15
29
 
@@ -39,28 +53,34 @@ async function main() {
39
53
  baseUrl: 'http://localhost:8000'
40
54
  });
41
55
 
42
- // Create a collection
43
- await client.collections.create('documents', [
44
- { name: 'title', type: FieldType.STRING },
45
- { name: 'content', type: FieldType.STRING, vectorize: true }
46
- ]);
56
+ // Create a collection with vectorization enabled
57
+ await client.collections.create(
58
+ 'documents',
59
+ [
60
+ { name: 'title', type: FieldType.STRING },
61
+ { name: 'content', type: FieldType.STRING, vectorize: true }
62
+ ],
63
+ 'your-embedding-provider-id' // Required when vectorize=true
64
+ );
47
65
 
48
66
  // Create a record
49
67
  const record = await client.records.create('documents', {
50
- title: 'Hello World',
51
- content: 'This is my first document'
68
+ title: 'Introduction to AI',
69
+ content: 'Artificial intelligence is transforming how we build software...'
52
70
  });
53
71
 
54
- // Semantic search
72
+ // Semantic search - finds relevant content by meaning, not just keywords
55
73
  const results = await client.records.search(
56
74
  'documents',
57
- 'hello world',
75
+ 'How is AI changing software development?',
58
76
  undefined,
59
77
  10
60
78
  );
61
79
 
62
80
  results.results.forEach(result => {
63
- console.log(`Score: ${result.score.toFixed(4)} - ${result.record.data.title}`);
81
+ console.log(`Score: ${result.score.toFixed(4)}`);
82
+ console.log(`Title: ${result.record.data.title}`);
83
+ console.log(`Content: ${result.record.data.content}\n`);
64
84
  });
65
85
 
66
86
  await client.close();
@@ -76,64 +96,80 @@ main();
76
96
  ```typescript
77
97
  import { CortexClient } from '@dooor-ai/cortexdb';
78
98
 
79
- // Local development
80
- const client = new CortexClient({
81
- baseUrl: 'http://localhost:8000'
82
- });
99
+ // Using connection string (recommended)
100
+ const client = new CortexClient('cortexdb://localhost:8000');
83
101
 
84
102
  // With API key
85
- const client = new CortexClient({
86
- baseUrl: 'https://api.cortexdb.com',
87
- apiKey: 'your-api-key'
88
- });
103
+ const client = new CortexClient('cortexdb://my-api-key@localhost:8000');
89
104
 
90
- // Custom timeout
105
+ // Production (HTTPS auto-detected)
106
+ const client = new CortexClient('cortexdb://my-key@api.cortexdb.com');
107
+
108
+ // Using options object (alternative)
91
109
  const client = new CortexClient({
92
110
  baseUrl: 'http://localhost:8000',
111
+ apiKey: 'your-api-key',
93
112
  timeout: 60000 // 60 seconds
94
113
  });
95
114
  ```
96
115
 
116
+ **Connection String Format:**
117
+ `cortexdb://[api_key@]host[:port]`
118
+
119
+ Benefits:
120
+ - Single string configuration
121
+ - Easy to store in environment variables
122
+ - Familiar pattern (like PostgreSQL, MongoDB, Redis)
123
+ - Auto-detects HTTP vs HTTPS
124
+
97
125
  ### Collections
98
126
 
127
+ Collections define the schema for your data. Each collection can have multiple fields with different types and storage options.
128
+
99
129
  ```typescript
100
130
  import { FieldType, StoreLocation } from '@dooor-ai/cortexdb';
101
131
 
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
- ]);
132
+ // Create collection with vectorization
133
+ const collection = await client.collections.create(
134
+ 'articles',
135
+ [
136
+ {
137
+ name: 'title',
138
+ type: FieldType.STRING
139
+ },
140
+ {
141
+ name: 'content',
142
+ type: FieldType.STRING,
143
+ vectorize: true // Enable semantic search on this field
144
+ },
145
+ {
146
+ name: 'year',
147
+ type: FieldType.NUMBER,
148
+ store_in: [StoreLocation.POSTGRES, StoreLocation.QDRANT_PAYLOAD]
149
+ }
150
+ ],
151
+ 'embedding-provider-id' // Required when any field has vectorize=true
152
+ );
119
153
 
120
154
  // List collections
121
155
  const collections = await client.collections.list();
122
156
 
123
- // Get collection
157
+ // Get collection schema
124
158
  const schema = await client.collections.get('articles');
125
159
 
126
- // Delete collection
160
+ // Delete collection and all its records
127
161
  await client.collections.delete('articles');
128
162
  ```
129
163
 
130
164
  ### Records
131
165
 
166
+ Records are the actual data stored in collections. They must match the collection schema.
167
+
132
168
  ```typescript
133
169
  // Create record
134
170
  const record = await client.records.create('articles', {
135
171
  title: 'Machine Learning Basics',
136
- content: 'Introduction to ML concepts...',
172
+ content: 'Machine learning is a subset of AI that focuses on learning from data...',
137
173
  year: 2024
138
174
  });
139
175
 
@@ -148,7 +184,7 @@ const updated = await client.records.update('articles', record.id, {
148
184
  // Delete record
149
185
  await client.records.delete('articles', record.id);
150
186
 
151
- // List records
187
+ // List records with pagination
152
188
  const results = await client.records.list('articles', {
153
189
  limit: 10,
154
190
  offset: 0
@@ -157,8 +193,10 @@ const results = await client.records.list('articles', {
157
193
 
158
194
  ### Semantic Search
159
195
 
196
+ Semantic search finds records by meaning, not just exact keyword matches. It uses vector embeddings to understand context.
197
+
160
198
  ```typescript
161
- // Basic search
199
+ // Basic semantic search
162
200
  const results = await client.records.search(
163
201
  'articles',
164
202
  'machine learning fundamentals',
@@ -166,7 +204,7 @@ const results = await client.records.search(
166
204
  10
167
205
  );
168
206
 
169
- // Search with filters
207
+ // Search with filters - combine semantic search with exact matches
170
208
  const filteredResults = await client.records.search(
171
209
  'articles',
172
210
  'neural networks',
@@ -177,30 +215,55 @@ const filteredResults = await client.records.search(
177
215
  5
178
216
  );
179
217
 
180
- // Process results
218
+ // Process results - ordered by relevance score
181
219
  filteredResults.results.forEach(result => {
182
- console.log(`Score: ${result.score.toFixed(4)}`);
220
+ console.log(`Score: ${result.score.toFixed(4)}`); // Higher = more relevant
183
221
  console.log(`Title: ${result.record.data.title}`);
184
222
  console.log(`Year: ${result.record.data.year}`);
185
223
  });
186
224
  ```
187
225
 
226
+ ### Working with Files
227
+
228
+ CortexDB can process documents and automatically extract text for vectorization.
229
+
230
+ ```typescript
231
+ // Create collection with file field
232
+ await client.collections.create(
233
+ 'documents',
234
+ [
235
+ { name: 'title', type: FieldType.STRING },
236
+ {
237
+ name: 'document',
238
+ type: FieldType.FILE,
239
+ vectorize: true // Extract text and create embeddings
240
+ }
241
+ ],
242
+ 'embedding-provider-id'
243
+ );
244
+
245
+ // Note: File upload support is currently available in the REST API
246
+ // TypeScript SDK file upload will be added in a future version
247
+ ```
248
+
188
249
  ### Filter Operators
189
250
 
190
251
  ```typescript
191
- // Exact match
252
+ // Exact match filters
192
253
  const results = await client.records.list('articles', {
193
254
  filters: {
194
255
  category: 'technology',
195
- published: true
256
+ published: true,
257
+ year: 2024
196
258
  }
197
259
  });
198
260
 
199
- // Combine filters
261
+ // Combine multiple filters
200
262
  const filtered = await client.records.list('articles', {
201
263
  filters: {
202
264
  year: 2024,
203
- category: 'AI'
265
+ category: 'AI',
266
+ author: 'John Doe'
204
267
  },
205
268
  limit: 20
206
269
  });
@@ -208,12 +271,15 @@ const filtered = await client.records.list('articles', {
208
271
 
209
272
  ## Error Handling
210
273
 
274
+ The SDK provides specific error types for different failure scenarios.
275
+
211
276
  ```typescript
212
277
  import {
213
278
  CortexDBError,
214
279
  CortexDBNotFoundError,
215
280
  CortexDBValidationError,
216
- CortexDBConnectionError
281
+ CortexDBConnectionError,
282
+ CortexDBTimeoutError
217
283
  } from '@dooor-ai/cortexdb';
218
284
 
219
285
  try {
@@ -222,9 +288,11 @@ try {
222
288
  if (error instanceof CortexDBNotFoundError) {
223
289
  console.log('Record not found');
224
290
  } else if (error instanceof CortexDBValidationError) {
225
- console.log('Validation error:', error.message);
291
+ console.log('Invalid data:', error.message);
226
292
  } else if (error instanceof CortexDBConnectionError) {
227
293
  console.log('Connection failed:', error.message);
294
+ } else if (error instanceof CortexDBTimeoutError) {
295
+ console.log('Request timed out:', error.message);
228
296
  } else if (error instanceof CortexDBError) {
229
297
  console.log('General error:', error.message);
230
298
  }
@@ -233,11 +301,11 @@ try {
233
301
 
234
302
  ## Examples
235
303
 
236
- Check the [`examples/`](./examples) directory for more usage examples:
304
+ Check the [`examples/`](./examples) directory for complete working examples:
237
305
 
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
306
+ - [`quickstart.ts`](./examples/quickstart.ts) - Complete walkthrough of SDK features
307
+ - [`search.ts`](./examples/search.ts) - Semantic search with filters and providers
308
+ - [`basic.ts`](./examples/basic.ts) - Basic CRUD operations
241
309
 
242
310
  Run examples:
243
311
 
@@ -264,27 +332,44 @@ npm run build
264
332
  ### Scripts
265
333
 
266
334
  ```bash
267
- # Build
335
+ # Build TypeScript
268
336
  npm run build
269
337
 
270
- # Watch mode
338
+ # Build in watch mode
271
339
  npm run build:watch
272
340
 
273
- # Clean
341
+ # Clean build artifacts
274
342
  npm run clean
275
343
 
276
- # Lint
344
+ # Lint code
277
345
  npm run lint
278
346
 
279
- # Format
347
+ # Format code
280
348
  npm run format
281
349
  ```
282
350
 
283
351
  ## Requirements
284
352
 
285
- - Node.js >= 18.0.0
286
- - CortexDB gateway running (local or remote)
353
+ - Node.js >= 18.0.0 (for native fetch support)
354
+ - CortexDB gateway running locally or remotely
355
+ - Embedding provider configured (OpenAI, Gemini, etc.) if using vectorization
356
+
357
+ ## Architecture
358
+
359
+ CortexDB integrates multiple technologies:
360
+
361
+ - **PostgreSQL**: Stores structured data and metadata
362
+ - **Qdrant**: Vector database for semantic search
363
+ - **MinIO**: Object storage for files
364
+ - **Docling**: Advanced document processing and text extraction
365
+
366
+ The SDK abstracts this complexity into a simple, unified API.
287
367
 
288
368
  ## License
289
369
 
290
370
  MIT License - see [LICENSE](./LICENSE) for details.
371
+
372
+ ## Related
373
+
374
+ - [CortexDB Python SDK](../python) - Python client for CortexDB
375
+ - [CortexDB Documentation](../../docs) - Complete platform documentation
@@ -10,7 +10,24 @@ export declare class CortexClient {
10
10
  private http;
11
11
  collections: CollectionsAPI;
12
12
  records: RecordsAPI;
13
- constructor(options?: CortexClientOptions);
13
+ /**
14
+ * Create a new CortexDB client
15
+ *
16
+ * @param options - Configuration options or connection string
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Using options object
21
+ * const client = new CortexClient({
22
+ * baseUrl: 'http://localhost:8000',
23
+ * apiKey: 'my-key'
24
+ * });
25
+ *
26
+ * // Using connection string
27
+ * const client = new CortexClient('cortexdb://my-key@localhost:8000');
28
+ * ```
29
+ */
30
+ constructor(options?: CortexClientOptions | string);
14
31
  /**
15
32
  * Check if the connection to CortexDB is working
16
33
  */
@@ -1 +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"}
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;AAG5C,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;IAE3B;;;;;;;;;;;;;;;;OAgBG;gBACS,OAAO,GAAE,mBAAmB,GAAG,MAAW;IAuBtD;;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"}
@@ -5,9 +5,42 @@ exports.CortexClient = void 0;
5
5
  const client_1 = require("../http/client");
6
6
  const api_1 = require("../collections/api");
7
7
  const api_2 = require("../records/api");
8
+ const connection_string_1 = require("../utils/connection-string");
8
9
  class CortexClient {
10
+ /**
11
+ * Create a new CortexDB client
12
+ *
13
+ * @param options - Configuration options or connection string
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Using options object
18
+ * const client = new CortexClient({
19
+ * baseUrl: 'http://localhost:8000',
20
+ * apiKey: 'my-key'
21
+ * });
22
+ *
23
+ * // Using connection string
24
+ * const client = new CortexClient('cortexdb://my-key@localhost:8000');
25
+ * ```
26
+ */
9
27
  constructor(options = {}) {
10
- const { baseUrl = "http://localhost:8000", apiKey, timeout = 30000, } = options;
28
+ let baseUrl;
29
+ let apiKey;
30
+ let timeout;
31
+ // Handle connection string
32
+ if (typeof options === 'string') {
33
+ const parsed = (0, connection_string_1.parseConnectionString)(options);
34
+ baseUrl = parsed.baseUrl;
35
+ apiKey = parsed.apiKey;
36
+ timeout = 30000;
37
+ }
38
+ else {
39
+ // Handle options object
40
+ baseUrl = options.baseUrl || "http://localhost:8000";
41
+ apiKey = options.apiKey;
42
+ timeout = options.timeout || 30000;
43
+ }
11
44
  this.http = new client_1.HTTPClient(baseUrl, apiKey, timeout);
12
45
  this.collections = new api_1.CollectionsAPI(this.http);
13
46
  this.records = new api_2.RecordsAPI(this.http);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.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+ * - cortexdb://localhost:8000
8
+ * - cortexdb://my_key@localhost:8000
9
+ * - cortexdb://my_key@api.cortexdb.com
10
+ */
11
+ export interface ParsedConnection {
12
+ baseUrl: string;
13
+ apiKey?: string;
14
+ }
15
+ /**
16
+ * Parse a CortexDB connection string
17
+ *
18
+ * @param connectionString - Connection string in format cortexdb://[api_key@]host[:port]
19
+ * @returns Parsed connection options
20
+ * @throws Error if connection string is invalid
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * parseConnectionString('cortexdb://localhost:8000')
25
+ * // { baseUrl: 'http://localhost:8000' }
26
+ *
27
+ * parseConnectionString('cortexdb://my_key@localhost:8000')
28
+ * // { baseUrl: 'http://localhost:8000', apiKey: 'my_key' }
29
+ *
30
+ * parseConnectionString('cortexdb://key@api.cortexdb.com:443')
31
+ * // { baseUrl: 'https://api.cortexdb.com:443', apiKey: 'key' }
32
+ * ```
33
+ */
34
+ export declare function parseConnectionString(connectionString: string): ParsedConnection;
35
+ //# sourceMappingURL=connection-string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-string.d.ts","sourceRoot":"","sources":["../../src/utils/connection-string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,GAAG,gBAAgB,CAoDhF"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * Parse CortexDB connection strings
4
+ *
5
+ * Format: cortexdb://[api_key@]host[:port]
6
+ *
7
+ * Examples:
8
+ * - cortexdb://localhost:8000
9
+ * - cortexdb://my_key@localhost:8000
10
+ * - cortexdb://my_key@api.cortexdb.com
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.parseConnectionString = parseConnectionString;
14
+ /**
15
+ * Parse a CortexDB connection string
16
+ *
17
+ * @param connectionString - Connection string in format cortexdb://[api_key@]host[:port]
18
+ * @returns Parsed connection options
19
+ * @throws Error if connection string is invalid
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * parseConnectionString('cortexdb://localhost:8000')
24
+ * // { baseUrl: 'http://localhost:8000' }
25
+ *
26
+ * parseConnectionString('cortexdb://my_key@localhost:8000')
27
+ * // { baseUrl: 'http://localhost:8000', apiKey: 'my_key' }
28
+ *
29
+ * parseConnectionString('cortexdb://key@api.cortexdb.com:443')
30
+ * // { baseUrl: 'https://api.cortexdb.com:443', apiKey: 'key' }
31
+ * ```
32
+ */
33
+ function parseConnectionString(connectionString) {
34
+ // Remove cortexdb:// prefix
35
+ if (!connectionString.startsWith('cortexdb://')) {
36
+ throw new Error('Connection string must start with "cortexdb://"');
37
+ }
38
+ const withoutProtocol = connectionString.slice('cortexdb://'.length);
39
+ // Split by @ to separate api_key from host
40
+ let apiKey;
41
+ let hostPart;
42
+ if (withoutProtocol.includes('@')) {
43
+ const parts = withoutProtocol.split('@');
44
+ if (parts.length !== 2) {
45
+ throw new Error('Invalid connection string format');
46
+ }
47
+ apiKey = parts[0];
48
+ hostPart = parts[1];
49
+ }
50
+ else {
51
+ hostPart = withoutProtocol;
52
+ }
53
+ // Parse host and port
54
+ let host;
55
+ let port;
56
+ if (hostPart.includes(':')) {
57
+ const hostPortParts = hostPart.split(':');
58
+ host = hostPortParts[0];
59
+ port = hostPortParts[1];
60
+ }
61
+ else {
62
+ host = hostPart;
63
+ }
64
+ // Determine protocol (https for port 443 or production domains, http otherwise)
65
+ const isSecure = port === '443' ||
66
+ host.includes('cortexdb.com') ||
67
+ (!host.includes('localhost') && !host.startsWith('127.'));
68
+ const protocol = isSecure ? 'https' : 'http';
69
+ // Build base URL
70
+ let baseUrl = `${protocol}://${host}`;
71
+ if (port && !(port === '443' && isSecure) && !(port === '80' && !isSecure)) {
72
+ baseUrl += `:${port}`;
73
+ }
74
+ return {
75
+ baseUrl,
76
+ apiKey
77
+ };
78
+ }
79
+ //# sourceMappingURL=connection-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-string.js","sourceRoot":"","sources":["../../src/utils/connection-string.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AA0BH,sDAoDC;AAvED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,qBAAqB,CAAC,gBAAwB;IAC5D,4BAA4B;IAC5B,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,eAAe,GAAG,gBAAgB,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAErE,2CAA2C;IAC3C,IAAI,MAA0B,CAAC;IAC/B,IAAI,QAAgB,CAAC;IAErB,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,eAAe,CAAC;IAC7B,CAAC;IAED,sBAAsB;IACtB,IAAI,IAAY,CAAC;IACjB,IAAI,IAAwB,CAAC;IAE7B,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,QAAQ,CAAC;IAClB,CAAC;IAED,gFAAgF;IAChF,MAAM,QAAQ,GAAG,IAAI,KAAK,KAAK;QACd,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;QAC7B,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3E,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAE7C,iBAAiB;IACjB,IAAI,OAAO,GAAG,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC;IACtC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3E,OAAO,IAAI,IAAI,IAAI,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACL,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooor-ai/cortexdb",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Official TypeScript/JavaScript SDK for CortexDB - Multi-modal RAG Platform with advanced document processing",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",