@dakera-ai/dakera 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 +21 -0
- package/README.md +313 -0
- package/dist/index.d.mts +1528 -0
- package/dist/index.d.ts +1528 -0
- package/dist/index.js +1210 -0
- package/dist/index.mjs +1175 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dakera AI
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Dakera TypeScript SDK
|
|
2
|
+
|
|
3
|
+
[](https://github.com/dakera-ai/dakera-js/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/dakera)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
Official TypeScript/JavaScript client for [Dakera](https://github.com/dakera/dakera) - a high-performance vector database.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install dakera
|
|
14
|
+
# or
|
|
15
|
+
yarn add dakera
|
|
16
|
+
# or
|
|
17
|
+
pnpm add dakera
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { DakeraClient } from 'dakera';
|
|
24
|
+
|
|
25
|
+
// Connect to Dakera
|
|
26
|
+
const client = new DakeraClient('http://localhost:3000');
|
|
27
|
+
|
|
28
|
+
// Upsert vectors
|
|
29
|
+
await client.upsert('my-namespace', [
|
|
30
|
+
{ id: 'vec1', values: [0.1, 0.2, 0.3], metadata: { label: 'a' } },
|
|
31
|
+
{ id: 'vec2', values: [0.4, 0.5, 0.6], metadata: { label: 'b' } },
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
// Query similar vectors
|
|
35
|
+
const results = await client.query('my-namespace', [0.1, 0.2, 0.3], {
|
|
36
|
+
topK: 10,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
for (const result of results.results) {
|
|
40
|
+
console.log(`${result.id}: ${result.score}`);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **Full TypeScript Support**: Complete type definitions for all operations
|
|
47
|
+
- **Vector Operations**: Upsert, query, delete, fetch vectors
|
|
48
|
+
- **Full-Text Search**: Index documents and perform BM25 search
|
|
49
|
+
- **Hybrid Search**: Combine vector and text search with configurable weights
|
|
50
|
+
- **Namespace Management**: Create, list, delete namespaces
|
|
51
|
+
- **Metadata Filtering**: Filter queries by metadata fields
|
|
52
|
+
- **Automatic Retries**: Built-in retry logic with exponential backoff
|
|
53
|
+
- **Error Handling**: Typed exceptions for different error scenarios
|
|
54
|
+
|
|
55
|
+
## Usage Examples
|
|
56
|
+
|
|
57
|
+
### Vector Operations
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { DakeraClient } from 'dakera';
|
|
61
|
+
|
|
62
|
+
const client = new DakeraClient({
|
|
63
|
+
baseUrl: 'http://localhost:3000',
|
|
64
|
+
apiKey: 'your-api-key', // optional
|
|
65
|
+
timeout: 30000,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Upsert vectors
|
|
69
|
+
await client.upsert('my-namespace', [
|
|
70
|
+
{ id: 'vec1', values: [0.1, 0.2, 0.3], metadata: { category: 'A' } },
|
|
71
|
+
{ id: 'vec2', values: [0.4, 0.5, 0.6], metadata: { category: 'B' } },
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
// Query with metadata filter
|
|
75
|
+
const results = await client.query('my-namespace', [0.1, 0.2, 0.3], {
|
|
76
|
+
topK: 5,
|
|
77
|
+
filter: { category: { $eq: 'A' } },
|
|
78
|
+
includeMetadata: true,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Batch query
|
|
82
|
+
const batchResults = await client.batchQuery('my-namespace', [
|
|
83
|
+
{ vector: [0.1, 0.2, 0.3], topK: 5 },
|
|
84
|
+
{ vector: [0.4, 0.5, 0.6], topK: 3 },
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
// Fetch vectors by ID
|
|
88
|
+
const vectors = await client.fetch('my-namespace', ['vec1', 'vec2']);
|
|
89
|
+
|
|
90
|
+
// Delete vectors
|
|
91
|
+
await client.delete('my-namespace', { ids: ['vec1', 'vec2'] });
|
|
92
|
+
await client.delete('my-namespace', { filter: { category: { $eq: 'obsolete' } } });
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Full-Text Search
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Index documents
|
|
99
|
+
await client.indexDocuments('my-namespace', [
|
|
100
|
+
{ id: 'doc1', content: 'Machine learning is transforming industries' },
|
|
101
|
+
{ id: 'doc2', content: 'Vector databases enable semantic search' },
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
// Search
|
|
105
|
+
const results = await client.fulltextSearch('my-namespace', 'machine learning', {
|
|
106
|
+
topK: 10,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
for (const result of results) {
|
|
110
|
+
console.log(`${result.id}: ${result.score}`);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Hybrid Search
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// Combine vector and text search
|
|
118
|
+
const results = await client.hybridSearch(
|
|
119
|
+
'my-namespace',
|
|
120
|
+
[0.1, 0.2, 0.3], // Query vector
|
|
121
|
+
'machine learning', // Text query
|
|
122
|
+
{
|
|
123
|
+
topK: 10,
|
|
124
|
+
alpha: 0.7, // 0 = pure vector, 1 = pure text
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
for (const result of results) {
|
|
129
|
+
console.log(`${result.id}: score=${result.score}, vector=${result.vectorScore}, text=${result.textScore}`);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Namespace Management
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Create namespace
|
|
137
|
+
await client.createNamespace('embeddings', {
|
|
138
|
+
dimensions: 384,
|
|
139
|
+
indexType: 'hnsw',
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// List namespaces
|
|
143
|
+
const namespaces = await client.listNamespaces();
|
|
144
|
+
for (const ns of namespaces) {
|
|
145
|
+
console.log(`${ns.name}: ${ns.vectorCount} vectors`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Get namespace info
|
|
149
|
+
const info = await client.getNamespace('embeddings');
|
|
150
|
+
console.log(`Dimensions: ${info.dimensions}, Index: ${info.indexType}`);
|
|
151
|
+
|
|
152
|
+
// Delete namespace
|
|
153
|
+
await client.deleteNamespace('old-namespace');
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Metadata Filtering
|
|
157
|
+
|
|
158
|
+
Dakera supports rich metadata filtering:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Equality
|
|
162
|
+
const filter1 = { status: { $eq: 'active' } };
|
|
163
|
+
|
|
164
|
+
// Comparison
|
|
165
|
+
const filter2 = { price: { $gt: 100, $lt: 500 } };
|
|
166
|
+
|
|
167
|
+
// In list
|
|
168
|
+
const filter3 = { category: { $in: ['electronics', 'books'] } };
|
|
169
|
+
|
|
170
|
+
// Logical operators
|
|
171
|
+
const filter4 = {
|
|
172
|
+
$and: [
|
|
173
|
+
{ status: { $eq: 'active' } },
|
|
174
|
+
{ price: { $lt: 1000 } },
|
|
175
|
+
],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const results = await client.query('products', queryVector, {
|
|
179
|
+
filter: filter4,
|
|
180
|
+
topK: 20,
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Error Handling
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import {
|
|
188
|
+
DakeraClient,
|
|
189
|
+
NotFoundError,
|
|
190
|
+
ValidationError,
|
|
191
|
+
RateLimitError,
|
|
192
|
+
ServerError,
|
|
193
|
+
} from 'dakera';
|
|
194
|
+
|
|
195
|
+
const client = new DakeraClient('http://localhost:3000');
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
const results = await client.query('nonexistent', [0.1, 0.2]);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (error instanceof NotFoundError) {
|
|
201
|
+
console.log(`Namespace not found: ${error.message}`);
|
|
202
|
+
} else if (error instanceof ValidationError) {
|
|
203
|
+
console.log(`Invalid request: ${error.message}`);
|
|
204
|
+
} else if (error instanceof RateLimitError) {
|
|
205
|
+
console.log(`Rate limited, retry after ${error.retryAfter} seconds`);
|
|
206
|
+
} else if (error instanceof ServerError) {
|
|
207
|
+
console.log(`Server error: ${error.message}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Configuration
|
|
213
|
+
|
|
214
|
+
| Option | Type | Default | Description |
|
|
215
|
+
|--------|------|---------|-------------|
|
|
216
|
+
| `baseUrl` | string | required | Dakera server URL |
|
|
217
|
+
| `apiKey` | string | undefined | API key for authentication |
|
|
218
|
+
| `timeout` | number | 30000 | Request timeout in milliseconds |
|
|
219
|
+
| `maxRetries` | number | 3 | Max retries for failed requests |
|
|
220
|
+
| `headers` | object | undefined | Additional HTTP headers |
|
|
221
|
+
|
|
222
|
+
## API Reference
|
|
223
|
+
|
|
224
|
+
### DakeraClient
|
|
225
|
+
|
|
226
|
+
#### Vector Operations
|
|
227
|
+
- `upsert(namespace, vectors)` - Insert or update vectors
|
|
228
|
+
- `query(namespace, vector, options?)` - Query similar vectors
|
|
229
|
+
- `delete(namespace, options)` - Delete vectors
|
|
230
|
+
- `fetch(namespace, ids, options?)` - Fetch vectors by ID
|
|
231
|
+
- `batchQuery(namespace, queries)` - Execute multiple queries
|
|
232
|
+
|
|
233
|
+
#### Full-Text Operations
|
|
234
|
+
- `indexDocuments(namespace, documents)` - Index documents
|
|
235
|
+
- `fulltextSearch(namespace, query, options?)` - Text search
|
|
236
|
+
- `hybridSearch(namespace, vector, query, options?)` - Hybrid search
|
|
237
|
+
|
|
238
|
+
#### Namespace Operations
|
|
239
|
+
- `listNamespaces()` - List all namespaces
|
|
240
|
+
- `getNamespace(namespace)` - Get namespace info
|
|
241
|
+
- `createNamespace(namespace, options?)` - Create namespace
|
|
242
|
+
- `deleteNamespace(namespace)` - Delete namespace
|
|
243
|
+
|
|
244
|
+
#### Admin Operations
|
|
245
|
+
- `health()` - Check server health
|
|
246
|
+
- `getIndexStats(namespace)` - Get index statistics
|
|
247
|
+
- `compact(namespace)` - Trigger compaction
|
|
248
|
+
- `flush(namespace)` - Flush pending writes
|
|
249
|
+
|
|
250
|
+
## TypeScript Types
|
|
251
|
+
|
|
252
|
+
All types are exported for use in your application:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import type {
|
|
256
|
+
Vector,
|
|
257
|
+
VectorInput,
|
|
258
|
+
QueryResult,
|
|
259
|
+
SearchResult,
|
|
260
|
+
NamespaceInfo,
|
|
261
|
+
IndexStats,
|
|
262
|
+
Document,
|
|
263
|
+
FilterExpression,
|
|
264
|
+
QueryOptions,
|
|
265
|
+
ClientOptions,
|
|
266
|
+
} from 'dakera';
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Browser Support
|
|
270
|
+
|
|
271
|
+
This SDK uses the Fetch API and works in:
|
|
272
|
+
- Node.js 18+
|
|
273
|
+
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
|
274
|
+
- Deno
|
|
275
|
+
- Bun
|
|
276
|
+
|
|
277
|
+
## Development
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
# Install dependencies
|
|
281
|
+
npm install
|
|
282
|
+
|
|
283
|
+
# Build
|
|
284
|
+
npm run build
|
|
285
|
+
|
|
286
|
+
# Run tests
|
|
287
|
+
npm test
|
|
288
|
+
|
|
289
|
+
# Type check
|
|
290
|
+
npm run typecheck
|
|
291
|
+
|
|
292
|
+
# Lint
|
|
293
|
+
npm run lint
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Related Repositories
|
|
297
|
+
|
|
298
|
+
| Repository | Description |
|
|
299
|
+
|------------|-------------|
|
|
300
|
+
| [dakera](https://github.com/dakera-ai/dakera) | Core vector database engine (Rust) |
|
|
301
|
+
| [dakera-py](https://github.com/dakera-ai/dakera-py) | Python SDK |
|
|
302
|
+
| [dakera-go](https://github.com/dakera-ai/dakera-go) | Go SDK |
|
|
303
|
+
| [dakera-rs](https://github.com/dakera-ai/dakera-rs) | Rust SDK |
|
|
304
|
+
| [dakera-cli](https://github.com/dakera-ai/dakera-cli) | Command-line interface |
|
|
305
|
+
| [dakera-mcp](https://github.com/dakera-ai/dakera-mcp) | MCP Server for AI agent memory |
|
|
306
|
+
| [dakera-dashboard](https://github.com/dakera-ai/dakera-dashboard) | Admin dashboard (Leptos/WASM) |
|
|
307
|
+
| [dakera-docs](https://github.com/dakera-ai/dakera-docs) | Documentation |
|
|
308
|
+
| [dakera-deploy](https://github.com/dakera-ai/dakera-deploy) | Deployment configs and Docker Compose |
|
|
309
|
+
| [dakera-cortex](https://github.com/dakera-ai/dakera-cortex) | Flagship demo with AI agents |
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
MIT License - see [LICENSE](LICENSE) for details.
|