@kernl-sdk/turbopuffer 0.1.2 → 0.1.4
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/handle.js +1 -1
- package/dist/search.js +1 -1
- package/package.json +7 -7
- package/dist/__tests__/filters.integration.test.d.ts +0 -8
- package/dist/__tests__/filters.integration.test.d.ts.map +0 -1
- package/dist/__tests__/filters.integration.test.js +0 -502
- package/dist/__tests__/integration.test.d.ts +0 -2
- package/dist/__tests__/integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration.test.js +0 -343
- package/dist/__tests__/lifecycle.integration.test.d.ts +0 -8
- package/dist/__tests__/lifecycle.integration.test.d.ts.map +0 -1
- package/dist/__tests__/lifecycle.integration.test.js +0 -385
- package/dist/__tests__/query.integration.test.d.ts +0 -8
- package/dist/__tests__/query.integration.test.d.ts.map +0 -1
- package/dist/__tests__/query.integration.test.js +0 -423
- package/dist/convert.d.ts +0 -68
- package/dist/convert.d.ts.map +0 -1
- package/dist/convert.js +0 -333
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Index and handle lifecycle edge case integration tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests edge cases for index lifecycle operations and document handling
|
|
5
|
-
* against real Turbopuffer API.
|
|
6
|
-
*/
|
|
7
|
-
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
8
|
-
import { TurbopufferSearchIndex } from "../search.js";
|
|
9
|
-
const TURBOPUFFER_API_KEY = process.env.TURBOPUFFER_API_KEY;
|
|
10
|
-
const TURBOPUFFER_REGION = process.env.TURBOPUFFER_REGION ?? "api";
|
|
11
|
-
/**
|
|
12
|
-
* Helper to create a DenseVector.
|
|
13
|
-
*/
|
|
14
|
-
function vec(dim, fill = 0.1) {
|
|
15
|
-
return { kind: "vector", values: new Array(dim).fill(fill) };
|
|
16
|
-
}
|
|
17
|
-
describe("Lifecycle edge cases integration tests", () => {
|
|
18
|
-
if (!TURBOPUFFER_API_KEY) {
|
|
19
|
-
it.skip("requires TURBOPUFFER_API_KEY to be set", () => { });
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
let tpuf;
|
|
23
|
-
const testPrefix = `kernl-lifecycle-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
24
|
-
beforeAll(() => {
|
|
25
|
-
tpuf = new TurbopufferSearchIndex({
|
|
26
|
-
apiKey: TURBOPUFFER_API_KEY,
|
|
27
|
-
region: TURBOPUFFER_REGION,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
afterAll(async () => {
|
|
31
|
-
// Clean up any test indexes that might have been created
|
|
32
|
-
try {
|
|
33
|
-
const page = await tpuf.listIndexes({ prefix: testPrefix });
|
|
34
|
-
for (const idx of page.items) {
|
|
35
|
-
try {
|
|
36
|
-
await tpuf.deleteIndex(idx.id);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
// Ignore individual cleanup errors
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// Ignore cleanup errors
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
// ============================================================
|
|
48
|
-
// INDEX LIFECYCLE EDGE CASES
|
|
49
|
-
// ============================================================
|
|
50
|
-
describe("index lifecycle edge cases", () => {
|
|
51
|
-
it("describes index immediately after creation", async () => {
|
|
52
|
-
const indexId = `${testPrefix}-describe-after-create`;
|
|
53
|
-
await tpuf.createIndex({
|
|
54
|
-
id: indexId,
|
|
55
|
-
schema: {
|
|
56
|
-
text: { type: "string" },
|
|
57
|
-
vector: { type: "vector", dimensions: 4 },
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
const stats = await tpuf.describeIndex(indexId);
|
|
61
|
-
expect(stats.id).toBe(indexId);
|
|
62
|
-
expect(stats.count).toBe(0);
|
|
63
|
-
await tpuf.deleteIndex(indexId);
|
|
64
|
-
});
|
|
65
|
-
it("describe after delete throws", async () => {
|
|
66
|
-
const indexId = `${testPrefix}-describe-after-delete`;
|
|
67
|
-
await tpuf.createIndex({
|
|
68
|
-
id: indexId,
|
|
69
|
-
schema: { text: { type: "string" } },
|
|
70
|
-
});
|
|
71
|
-
await tpuf.deleteIndex(indexId);
|
|
72
|
-
await expect(tpuf.describeIndex(indexId)).rejects.toThrow();
|
|
73
|
-
});
|
|
74
|
-
it("delete non-existent index throws", async () => {
|
|
75
|
-
const indexId = `${testPrefix}-nonexistent-${Date.now()}`;
|
|
76
|
-
await expect(tpuf.deleteIndex(indexId)).rejects.toThrow();
|
|
77
|
-
});
|
|
78
|
-
it("create index with same id twice throws", async () => {
|
|
79
|
-
const indexId = `${testPrefix}-duplicate`;
|
|
80
|
-
await tpuf.createIndex({
|
|
81
|
-
id: indexId,
|
|
82
|
-
schema: { text: { type: "string" } },
|
|
83
|
-
});
|
|
84
|
-
// Second create should fail
|
|
85
|
-
await expect(tpuf.createIndex({
|
|
86
|
-
id: indexId,
|
|
87
|
-
schema: { text: { type: "string" } },
|
|
88
|
-
})).rejects.toThrow();
|
|
89
|
-
await tpuf.deleteIndex(indexId);
|
|
90
|
-
});
|
|
91
|
-
it("listIndexes returns empty page for non-matching prefix", async () => {
|
|
92
|
-
const page = await tpuf.listIndexes({
|
|
93
|
-
prefix: `nonexistent-prefix-${Date.now()}`,
|
|
94
|
-
});
|
|
95
|
-
expect(page.items).toEqual([]);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
// ============================================================
|
|
99
|
-
// DOCUMENT UPSERT EDGE CASES
|
|
100
|
-
// ============================================================
|
|
101
|
-
describe("document upsert edge cases", () => {
|
|
102
|
-
const indexId = `${testPrefix}-upsert-edge`;
|
|
103
|
-
beforeAll(async () => {
|
|
104
|
-
await tpuf.createIndex({
|
|
105
|
-
id: indexId,
|
|
106
|
-
schema: {
|
|
107
|
-
content: { type: "string" },
|
|
108
|
-
count: { type: "int" },
|
|
109
|
-
vector: { type: "vector", dimensions: 4 },
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
afterAll(async () => {
|
|
114
|
-
try {
|
|
115
|
-
await tpuf.deleteIndex(indexId);
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
// Ignore
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
it("multiple upserts same id keeps last write", async () => {
|
|
122
|
-
const index = tpuf.index(indexId);
|
|
123
|
-
// First write
|
|
124
|
-
await index.upsert({
|
|
125
|
-
id: "overwrite-test",
|
|
126
|
-
fields: {
|
|
127
|
-
content: "First version",
|
|
128
|
-
count: 1,
|
|
129
|
-
vector: vec(4, 0.1),
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
// Second write
|
|
133
|
-
await index.upsert({
|
|
134
|
-
id: "overwrite-test",
|
|
135
|
-
fields: {
|
|
136
|
-
content: "Second version",
|
|
137
|
-
count: 2,
|
|
138
|
-
vector: vec(4, 0.2),
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
// Third write
|
|
142
|
-
await index.upsert({
|
|
143
|
-
id: "overwrite-test",
|
|
144
|
-
fields: {
|
|
145
|
-
content: "Final version",
|
|
146
|
-
count: 3,
|
|
147
|
-
vector: vec(4, 0.3),
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
// Wait for indexing
|
|
151
|
-
await new Promise((r) => setTimeout(r, 1000));
|
|
152
|
-
// Query and verify final state
|
|
153
|
-
const hits = await index.query({
|
|
154
|
-
query: [{ vector: [0.3, 0.3, 0.3, 0.3] }],
|
|
155
|
-
topK: 10,
|
|
156
|
-
filter: { id: "overwrite-test" },
|
|
157
|
-
include: ["content", "count"],
|
|
158
|
-
});
|
|
159
|
-
expect(hits.length).toBe(1);
|
|
160
|
-
expect(hits[0].document?.content).toBe("Final version");
|
|
161
|
-
expect(hits[0].document?.count).toBe(3);
|
|
162
|
-
});
|
|
163
|
-
it("upsert with empty fields object", async () => {
|
|
164
|
-
const index = tpuf.index(indexId);
|
|
165
|
-
// This should work - document with just id and vector
|
|
166
|
-
await index.upsert({
|
|
167
|
-
id: "minimal-doc",
|
|
168
|
-
fields: {
|
|
169
|
-
vector: vec(4),
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
173
|
-
const hits = await index.query({
|
|
174
|
-
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
175
|
-
topK: 10,
|
|
176
|
-
filter: { id: "minimal-doc" },
|
|
177
|
-
});
|
|
178
|
-
expect(hits.some((h) => h.id === "minimal-doc")).toBe(true);
|
|
179
|
-
});
|
|
180
|
-
it("batch upsert with same id in batch uses last occurrence", async () => {
|
|
181
|
-
const index = tpuf.index(indexId);
|
|
182
|
-
// Batch with duplicate id - last one should win
|
|
183
|
-
await index.upsert([
|
|
184
|
-
{
|
|
185
|
-
id: "batch-dup",
|
|
186
|
-
fields: { content: "First", count: 1, vector: vec(4, 0.1) },
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
id: "batch-dup",
|
|
190
|
-
fields: { content: "Second", count: 2, vector: vec(4, 0.2) },
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
id: "batch-dup",
|
|
194
|
-
fields: { content: "Third", count: 3, vector: vec(4, 0.3) },
|
|
195
|
-
},
|
|
196
|
-
]);
|
|
197
|
-
await new Promise((r) => setTimeout(r, 1000));
|
|
198
|
-
const hits = await index.query({
|
|
199
|
-
query: [{ vector: [0.3, 0.3, 0.3, 0.3] }],
|
|
200
|
-
topK: 10,
|
|
201
|
-
filter: { id: "batch-dup" },
|
|
202
|
-
include: ["content", "count"],
|
|
203
|
-
});
|
|
204
|
-
expect(hits.length).toBe(1);
|
|
205
|
-
expect(hits[0].document?.content).toBe("Third");
|
|
206
|
-
expect(hits[0].document?.count).toBe(3);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
// ============================================================
|
|
210
|
-
// DOCUMENT DELETE EDGE CASES
|
|
211
|
-
// ============================================================
|
|
212
|
-
describe("document delete edge cases", () => {
|
|
213
|
-
const indexId = `${testPrefix}-delete-edge`;
|
|
214
|
-
beforeAll(async () => {
|
|
215
|
-
await tpuf.createIndex({
|
|
216
|
-
id: indexId,
|
|
217
|
-
schema: {
|
|
218
|
-
content: { type: "string" },
|
|
219
|
-
vector: { type: "vector", dimensions: 4 },
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
afterAll(async () => {
|
|
224
|
-
try {
|
|
225
|
-
await tpuf.deleteIndex(indexId);
|
|
226
|
-
}
|
|
227
|
-
catch {
|
|
228
|
-
// Ignore
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
it("delete non-existent id does not throw", async () => {
|
|
232
|
-
const index = tpuf.index(indexId);
|
|
233
|
-
// Should not throw - just a no-op
|
|
234
|
-
const result = await index.delete("nonexistent-doc-id-12345");
|
|
235
|
-
// count reflects input, not actual deletions
|
|
236
|
-
expect(result.count).toBe(1);
|
|
237
|
-
});
|
|
238
|
-
it("batch delete with non-existent ids does not throw", async () => {
|
|
239
|
-
const index = tpuf.index(indexId);
|
|
240
|
-
const result = await index.delete([
|
|
241
|
-
"nonexistent-1",
|
|
242
|
-
"nonexistent-2",
|
|
243
|
-
"nonexistent-3",
|
|
244
|
-
]);
|
|
245
|
-
expect(result.count).toBe(3);
|
|
246
|
-
});
|
|
247
|
-
it("delete empty array returns count 0", async () => {
|
|
248
|
-
const index = tpuf.index(indexId);
|
|
249
|
-
const result = await index.delete([]);
|
|
250
|
-
expect(result.count).toBe(0);
|
|
251
|
-
});
|
|
252
|
-
it("delete then query returns empty", async () => {
|
|
253
|
-
const index = tpuf.index(indexId);
|
|
254
|
-
// Insert
|
|
255
|
-
await index.upsert({
|
|
256
|
-
id: "to-delete",
|
|
257
|
-
fields: {
|
|
258
|
-
content: "Will be deleted",
|
|
259
|
-
vector: vec(4, 0.9),
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
263
|
-
// Verify exists
|
|
264
|
-
let hits = await index.query({
|
|
265
|
-
query: [{ vector: [0.9, 0.9, 0.9, 0.9] }],
|
|
266
|
-
topK: 10,
|
|
267
|
-
filter: { id: "to-delete" },
|
|
268
|
-
});
|
|
269
|
-
expect(hits.length).toBe(1);
|
|
270
|
-
// Delete
|
|
271
|
-
await index.delete("to-delete");
|
|
272
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
273
|
-
// Verify gone
|
|
274
|
-
hits = await index.query({
|
|
275
|
-
query: [{ vector: [0.9, 0.9, 0.9, 0.9] }],
|
|
276
|
-
topK: 10,
|
|
277
|
-
filter: { id: "to-delete" },
|
|
278
|
-
});
|
|
279
|
-
expect(hits.length).toBe(0);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
// ============================================================
|
|
283
|
-
// QUERY EDGE CASES
|
|
284
|
-
// ============================================================
|
|
285
|
-
describe("query edge cases", () => {
|
|
286
|
-
const indexId = `${testPrefix}-query-edge`;
|
|
287
|
-
beforeAll(async () => {
|
|
288
|
-
await tpuf.createIndex({
|
|
289
|
-
id: indexId,
|
|
290
|
-
schema: {
|
|
291
|
-
content: { type: "string", fts: true },
|
|
292
|
-
vector: { type: "vector", dimensions: 4 },
|
|
293
|
-
},
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
afterAll(async () => {
|
|
297
|
-
try {
|
|
298
|
-
await tpuf.deleteIndex(indexId);
|
|
299
|
-
}
|
|
300
|
-
catch {
|
|
301
|
-
// Ignore
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
it("query on empty index returns empty array", async () => {
|
|
305
|
-
const index = tpuf.index(indexId);
|
|
306
|
-
const hits = await index.query({
|
|
307
|
-
query: [{ vector: [0.1, 0.2, 0.3, 0.4] }],
|
|
308
|
-
topK: 10,
|
|
309
|
-
});
|
|
310
|
-
expect(hits).toEqual([]);
|
|
311
|
-
});
|
|
312
|
-
it("query with filter matching nothing returns empty", async () => {
|
|
313
|
-
const index = tpuf.index(indexId);
|
|
314
|
-
// Add a doc first
|
|
315
|
-
await index.upsert({
|
|
316
|
-
id: "query-edge-doc",
|
|
317
|
-
fields: {
|
|
318
|
-
content: "Test content",
|
|
319
|
-
vector: vec(4),
|
|
320
|
-
},
|
|
321
|
-
});
|
|
322
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
323
|
-
// Query with filter that matches nothing
|
|
324
|
-
const hits = await index.query({
|
|
325
|
-
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
326
|
-
topK: 10,
|
|
327
|
-
filter: { id: "nonexistent-id" },
|
|
328
|
-
});
|
|
329
|
-
expect(hits).toEqual([]);
|
|
330
|
-
});
|
|
331
|
-
it("topK of 0 returns empty array", async () => {
|
|
332
|
-
const index = tpuf.index(indexId);
|
|
333
|
-
const hits = await index.query({
|
|
334
|
-
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
335
|
-
topK: 0,
|
|
336
|
-
});
|
|
337
|
-
expect(hits).toEqual([]);
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
// ============================================================
|
|
341
|
-
// VECTOR DIMENSION EDGE CASES
|
|
342
|
-
// ============================================================
|
|
343
|
-
describe("vector dimension edge cases", () => {
|
|
344
|
-
it("upsert with wrong vector dimension throws", async () => {
|
|
345
|
-
const indexId = `${testPrefix}-wrong-dim`;
|
|
346
|
-
await tpuf.createIndex({
|
|
347
|
-
id: indexId,
|
|
348
|
-
schema: {
|
|
349
|
-
vector: { type: "vector", dimensions: 4 },
|
|
350
|
-
},
|
|
351
|
-
});
|
|
352
|
-
const index = tpuf.index(indexId);
|
|
353
|
-
// Try to upsert with wrong dimension (8 instead of 4)
|
|
354
|
-
await expect(index.upsert({
|
|
355
|
-
id: "wrong-dim-doc",
|
|
356
|
-
fields: {
|
|
357
|
-
vector: vec(8), // Wrong dimension!
|
|
358
|
-
},
|
|
359
|
-
})).rejects.toThrow();
|
|
360
|
-
await tpuf.deleteIndex(indexId);
|
|
361
|
-
});
|
|
362
|
-
it("query with wrong vector dimension throws", async () => {
|
|
363
|
-
const indexId = `${testPrefix}-wrong-query-dim`;
|
|
364
|
-
await tpuf.createIndex({
|
|
365
|
-
id: indexId,
|
|
366
|
-
schema: {
|
|
367
|
-
vector: { type: "vector", dimensions: 4 },
|
|
368
|
-
},
|
|
369
|
-
});
|
|
370
|
-
const index = tpuf.index(indexId);
|
|
371
|
-
// Insert valid doc
|
|
372
|
-
await index.upsert({
|
|
373
|
-
id: "valid-doc",
|
|
374
|
-
fields: { vector: vec(4) },
|
|
375
|
-
});
|
|
376
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
377
|
-
// Query with wrong dimension
|
|
378
|
-
await expect(index.query({
|
|
379
|
-
query: [{ vector: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8] }], // 8 dims
|
|
380
|
-
topK: 10,
|
|
381
|
-
})).rejects.toThrow();
|
|
382
|
-
await tpuf.deleteIndex(indexId);
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comprehensive query modes integration tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests vector search, BM25 text search, hybrid queries, fusion modes,
|
|
5
|
-
* topK behavior, include semantics, and rank ordering against real Turbopuffer API.
|
|
6
|
-
*/
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=query.integration.test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.integration.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/query.integration.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|