@kernl-sdk/turbopuffer 0.1.6 → 0.1.7
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 +6 -0
- package/README.md +1 -1
- package/dist/__tests__/convert.test.js +6 -6
- package/dist/__tests__/integration/filters.integration.test.js +3 -3
- package/dist/__tests__/integration/integration.test.js +11 -11
- package/dist/__tests__/integration/lifecycle.integration.test.js +9 -9
- package/dist/__tests__/integration/memory.integration.test.js +1 -1
- package/dist/__tests__/integration/query.integration.test.d.ts +1 -1
- package/dist/__tests__/integration/query.integration.test.js +29 -29
- package/dist/__tests__/query.test.js +10 -10
- package/dist/convert/query.js +3 -3
- package/dist/search.d.ts +1 -1
- package/dist/search.js +1 -1
- package/package.json +6 -6
- package/src/__tests__/convert.test.ts +6 -6
- package/src/__tests__/integration/filters.integration.test.ts +3 -3
- package/src/__tests__/integration/integration.test.ts +11 -11
- package/src/__tests__/integration/lifecycle.integration.test.ts +9 -9
- package/src/__tests__/integration/memory.integration.test.ts +1 -1
- package/src/__tests__/integration/query.integration.test.ts +29 -29
- package/src/__tests__/query.test.ts +10 -10
- package/src/convert/query.ts +3 -3
- package/src/search.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ await docs.upsert({
|
|
|
44
44
|
// query with vector search
|
|
45
45
|
const hits = await docs.query({
|
|
46
46
|
query: [{ vector: [0.1, 0.2, ...] }],
|
|
47
|
-
|
|
47
|
+
limit: 10,
|
|
48
48
|
filter: { category: "greeting" },
|
|
49
49
|
include: ["content", "category"], // fields to include in the response
|
|
50
50
|
});
|
|
@@ -248,7 +248,7 @@ describe("convert", () => {
|
|
|
248
248
|
it("encodes vector search query", () => {
|
|
249
249
|
const result = QUERY.encode({
|
|
250
250
|
query: [{ vector: [0.1, 0.2, 0.3] }],
|
|
251
|
-
|
|
251
|
+
limit: 10,
|
|
252
252
|
});
|
|
253
253
|
expect(result.rank_by).toEqual(["vector", "ANN", [0.1, 0.2, 0.3]]);
|
|
254
254
|
expect(result.top_k).toBe(10);
|
|
@@ -256,7 +256,7 @@ describe("convert", () => {
|
|
|
256
256
|
it("encodes text search query", () => {
|
|
257
257
|
const result = QUERY.encode({
|
|
258
258
|
query: [{ content: "hello world" }],
|
|
259
|
-
|
|
259
|
+
limit: 5,
|
|
260
260
|
});
|
|
261
261
|
expect(result.rank_by).toEqual(["content", "BM25", "hello world"]);
|
|
262
262
|
expect(result.top_k).toBe(5);
|
|
@@ -264,7 +264,7 @@ describe("convert", () => {
|
|
|
264
264
|
it("encodes multi-field text search as Sum", () => {
|
|
265
265
|
const result = QUERY.encode({
|
|
266
266
|
query: [{ title: "search term" }, { body: "search term" }],
|
|
267
|
-
|
|
267
|
+
limit: 10,
|
|
268
268
|
});
|
|
269
269
|
expect(result.rank_by).toEqual([
|
|
270
270
|
"Sum",
|
|
@@ -277,7 +277,7 @@ describe("convert", () => {
|
|
|
277
277
|
it("encodes filter", () => {
|
|
278
278
|
const result = QUERY.encode({
|
|
279
279
|
query: [{ vector: [0.1] }],
|
|
280
|
-
|
|
280
|
+
limit: 5,
|
|
281
281
|
filter: { category: { $eq: "news" } },
|
|
282
282
|
});
|
|
283
283
|
expect(result.filters).toEqual(["category", "Eq", "news"]);
|
|
@@ -285,7 +285,7 @@ describe("convert", () => {
|
|
|
285
285
|
it("encodes include fields array", () => {
|
|
286
286
|
const result = QUERY.encode({
|
|
287
287
|
query: [{ vector: [0.1] }],
|
|
288
|
-
|
|
288
|
+
limit: 5,
|
|
289
289
|
include: ["title", "content"],
|
|
290
290
|
});
|
|
291
291
|
expect(result.include_attributes).toEqual(["title", "content"]);
|
|
@@ -293,7 +293,7 @@ describe("convert", () => {
|
|
|
293
293
|
it("encodes include as boolean", () => {
|
|
294
294
|
const result = QUERY.encode({
|
|
295
295
|
query: [{ vector: [0.1] }],
|
|
296
|
-
|
|
296
|
+
limit: 5,
|
|
297
297
|
include: true,
|
|
298
298
|
});
|
|
299
299
|
expect(result.include_attributes).toBe(true);
|
|
@@ -162,7 +162,7 @@ describe("Filter integration tests", () => {
|
|
|
162
162
|
async function queryIds(filter) {
|
|
163
163
|
const hits = await ns.query({
|
|
164
164
|
query: [{ vector: QUERY_VECTOR }],
|
|
165
|
-
|
|
165
|
+
limit: 100,
|
|
166
166
|
filter,
|
|
167
167
|
});
|
|
168
168
|
return hits.map((h) => h.id).sort();
|
|
@@ -440,7 +440,7 @@ describe("Filter integration tests", () => {
|
|
|
440
440
|
it("filtered results have correct field values", async () => {
|
|
441
441
|
const hits = await ns.query({
|
|
442
442
|
query: [{ vector: QUERY_VECTOR }],
|
|
443
|
-
|
|
443
|
+
limit: 100,
|
|
444
444
|
filter: { status: "pending" },
|
|
445
445
|
include: ["status", "flag", "num"],
|
|
446
446
|
});
|
|
@@ -456,7 +456,7 @@ describe("Filter integration tests", () => {
|
|
|
456
456
|
it("complex filter returns expected documents with correct data", async () => {
|
|
457
457
|
const hits = await ns.query({
|
|
458
458
|
query: [{ vector: QUERY_VECTOR }],
|
|
459
|
-
|
|
459
|
+
limit: 100,
|
|
460
460
|
filter: {
|
|
461
461
|
$and: [{ num: { $gte: 20, $lte: 50 } }, { flag: true }],
|
|
462
462
|
},
|
|
@@ -139,7 +139,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
139
139
|
// Verify via query
|
|
140
140
|
const hits = await index.query({
|
|
141
141
|
query: [{ vector: vec }],
|
|
142
|
-
|
|
142
|
+
limit: 10,
|
|
143
143
|
include: ["category"],
|
|
144
144
|
});
|
|
145
145
|
expect(hits.length).toBeGreaterThanOrEqual(1);
|
|
@@ -160,7 +160,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
160
160
|
// Verify via query
|
|
161
161
|
const hits = await index.query({
|
|
162
162
|
query: [{ vector: vec }],
|
|
163
|
-
|
|
163
|
+
limit: 10,
|
|
164
164
|
include: ["category"],
|
|
165
165
|
});
|
|
166
166
|
const doc = hits.find((h) => h.id === "doc-1");
|
|
@@ -188,7 +188,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
188
188
|
// Verify via query with filter
|
|
189
189
|
const hits = await index.query({
|
|
190
190
|
query: [{ vector: new Array(384).fill(0.3) }],
|
|
191
|
-
|
|
191
|
+
limit: 10,
|
|
192
192
|
filter: { category: "test" },
|
|
193
193
|
include: true,
|
|
194
194
|
});
|
|
@@ -208,7 +208,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
208
208
|
const index = tpuf.index(testIndexId);
|
|
209
209
|
const hits = await index.query({
|
|
210
210
|
query: [{ vector: new Array(384).fill(0.1) }],
|
|
211
|
-
|
|
211
|
+
limit: 5,
|
|
212
212
|
});
|
|
213
213
|
expect(hits.length).toBeGreaterThan(0);
|
|
214
214
|
expect(hits[0]).toHaveProperty("id");
|
|
@@ -219,7 +219,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
219
219
|
const index = tpuf.index(testIndexId);
|
|
220
220
|
const hits = await index.query({
|
|
221
221
|
query: [{ vector: new Array(384).fill(0.1) }],
|
|
222
|
-
|
|
222
|
+
limit: 5,
|
|
223
223
|
include: ["content", "category"],
|
|
224
224
|
});
|
|
225
225
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -231,7 +231,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
231
231
|
const index = tpuf.index(testIndexId);
|
|
232
232
|
const hits = await index.query({
|
|
233
233
|
query: [{ vector: new Array(384).fill(0.3) }],
|
|
234
|
-
|
|
234
|
+
limit: 10,
|
|
235
235
|
filter: { category: "test" },
|
|
236
236
|
include: ["category"],
|
|
237
237
|
});
|
|
@@ -244,7 +244,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
244
244
|
const index = tpuf.index(testIndexId);
|
|
245
245
|
const hits = await index.query({
|
|
246
246
|
query: [{ vector: new Array(384).fill(0.3) }],
|
|
247
|
-
|
|
247
|
+
limit: 10,
|
|
248
248
|
filter: {
|
|
249
249
|
$and: [
|
|
250
250
|
{ category: "test" },
|
|
@@ -273,7 +273,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
273
273
|
// Verify it exists
|
|
274
274
|
let hits = await index.query({
|
|
275
275
|
query: [{ vector: vec }],
|
|
276
|
-
|
|
276
|
+
limit: 10,
|
|
277
277
|
filter: { id: "doc-to-delete" },
|
|
278
278
|
});
|
|
279
279
|
expect(hits.some((h) => h.id === "doc-to-delete")).toBe(true);
|
|
@@ -282,7 +282,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
282
282
|
// Verify it's gone
|
|
283
283
|
hits = await index.query({
|
|
284
284
|
query: [{ vector: vec }],
|
|
285
|
-
|
|
285
|
+
limit: 10,
|
|
286
286
|
filter: { id: "doc-to-delete" },
|
|
287
287
|
});
|
|
288
288
|
expect(hits.some((h) => h.id === "doc-to-delete")).toBe(false);
|
|
@@ -310,7 +310,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
310
310
|
// Verify they exist
|
|
311
311
|
let hits = await index.query({
|
|
312
312
|
query: [{ vector: vec }],
|
|
313
|
-
|
|
313
|
+
limit: 10,
|
|
314
314
|
filter: { category: "bulk-delete" },
|
|
315
315
|
});
|
|
316
316
|
expect(hits.length).toBeGreaterThanOrEqual(2);
|
|
@@ -319,7 +319,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
319
319
|
// Verify they're gone
|
|
320
320
|
hits = await index.query({
|
|
321
321
|
query: [{ vector: vec }],
|
|
322
|
-
|
|
322
|
+
limit: 10,
|
|
323
323
|
filter: { category: "bulk-delete" },
|
|
324
324
|
});
|
|
325
325
|
expect(hits.some((h) => h.id === "bulk-del-1")).toBe(false);
|
|
@@ -149,7 +149,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
149
149
|
// Query and verify final state
|
|
150
150
|
const hits = await index.query({
|
|
151
151
|
query: [{ vector: [0.3, 0.3, 0.3, 0.3] }],
|
|
152
|
-
|
|
152
|
+
limit: 10,
|
|
153
153
|
filter: { id: "overwrite-test" },
|
|
154
154
|
include: ["content", "count"],
|
|
155
155
|
});
|
|
@@ -167,7 +167,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
167
167
|
await new Promise((r) => setTimeout(r, 500));
|
|
168
168
|
const hits = await index.query({
|
|
169
169
|
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
170
|
-
|
|
170
|
+
limit: 10,
|
|
171
171
|
filter: { id: "minimal-doc" },
|
|
172
172
|
});
|
|
173
173
|
expect(hits.some((h) => h.id === "minimal-doc")).toBe(true);
|
|
@@ -252,7 +252,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
252
252
|
// Verify exists
|
|
253
253
|
let hits = await index.query({
|
|
254
254
|
query: [{ vector: [0.9, 0.9, 0.9, 0.9] }],
|
|
255
|
-
|
|
255
|
+
limit: 10,
|
|
256
256
|
filter: { id: "to-delete" },
|
|
257
257
|
});
|
|
258
258
|
expect(hits.length).toBe(1);
|
|
@@ -262,7 +262,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
262
262
|
// Verify gone
|
|
263
263
|
hits = await index.query({
|
|
264
264
|
query: [{ vector: [0.9, 0.9, 0.9, 0.9] }],
|
|
265
|
-
|
|
265
|
+
limit: 10,
|
|
266
266
|
filter: { id: "to-delete" },
|
|
267
267
|
});
|
|
268
268
|
expect(hits.length).toBe(0);
|
|
@@ -294,7 +294,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
294
294
|
const index = tpuf.index(indexId);
|
|
295
295
|
const hits = await index.query({
|
|
296
296
|
query: [{ vector: [0.1, 0.2, 0.3, 0.4] }],
|
|
297
|
-
|
|
297
|
+
limit: 10,
|
|
298
298
|
});
|
|
299
299
|
expect(hits).toEqual([]);
|
|
300
300
|
});
|
|
@@ -310,16 +310,16 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
310
310
|
// Query with filter that matches nothing
|
|
311
311
|
const hits = await index.query({
|
|
312
312
|
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
313
|
-
|
|
313
|
+
limit: 10,
|
|
314
314
|
filter: { id: "nonexistent-id" },
|
|
315
315
|
});
|
|
316
316
|
expect(hits).toEqual([]);
|
|
317
317
|
});
|
|
318
|
-
it("
|
|
318
|
+
it("limit of 0 throws", async () => {
|
|
319
319
|
const index = tpuf.index(indexId);
|
|
320
320
|
await expect(index.query({
|
|
321
321
|
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
322
|
-
|
|
322
|
+
limit: 0,
|
|
323
323
|
})).rejects.toThrow();
|
|
324
324
|
});
|
|
325
325
|
});
|
|
@@ -361,7 +361,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
361
361
|
// Query with wrong dimension
|
|
362
362
|
await expect(index.query({
|
|
363
363
|
query: [{ vector: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8] }], // 8 dims
|
|
364
|
-
|
|
364
|
+
limit: 10,
|
|
365
365
|
})).rejects.toThrow();
|
|
366
366
|
await tpuf.deleteIndex(indexId);
|
|
367
367
|
});
|
|
@@ -183,7 +183,7 @@ describe.sequential("Memory Integration with Turbopuffer", { timeout: 60000 }, (
|
|
|
183
183
|
expect(results.length).toBe(1);
|
|
184
184
|
expect(results[0].document?.id).toBe(id1);
|
|
185
185
|
});
|
|
186
|
-
it("respects
|
|
186
|
+
it("respects limit", async () => {
|
|
187
187
|
const ns = uid("ns");
|
|
188
188
|
await agent.memories.create({
|
|
189
189
|
namespace: ns,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Comprehensive query modes integration tests.
|
|
3
3
|
*
|
|
4
4
|
* Tests vector search, BM25 text search, hybrid queries, fusion modes,
|
|
5
|
-
*
|
|
5
|
+
* limit behavior, include semantics, and rank ordering against real Turbopuffer API.
|
|
6
6
|
*/
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=query.integration.test.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Comprehensive query modes integration tests.
|
|
3
3
|
*
|
|
4
4
|
* Tests vector search, BM25 text search, hybrid queries, fusion modes,
|
|
5
|
-
*
|
|
5
|
+
* limit behavior, include semantics, and rank ordering against real Turbopuffer API.
|
|
6
6
|
*/
|
|
7
7
|
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
8
8
|
import { TurbopufferSearchIndex } from "../../search.js";
|
|
@@ -111,7 +111,7 @@ describe("Query modes integration tests", () => {
|
|
|
111
111
|
// Query with basis vector 1 - should match vec-1 best
|
|
112
112
|
const hits = await index.query({
|
|
113
113
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
114
|
-
|
|
114
|
+
limit: 10,
|
|
115
115
|
});
|
|
116
116
|
expect(hits.length).toBeGreaterThan(0);
|
|
117
117
|
expect(hits[0].id).toBe("vec-1");
|
|
@@ -120,7 +120,7 @@ describe("Query modes integration tests", () => {
|
|
|
120
120
|
// Query with basis vector 2
|
|
121
121
|
const hits = await index.query({
|
|
122
122
|
query: [{ vector: [0.0, 1.0, 0.0, 0.0] }],
|
|
123
|
-
|
|
123
|
+
limit: 10,
|
|
124
124
|
});
|
|
125
125
|
expect(hits.length).toBeGreaterThan(0);
|
|
126
126
|
expect(hits[0].id).toBe("vec-2");
|
|
@@ -133,35 +133,35 @@ describe("Query modes integration tests", () => {
|
|
|
133
133
|
// Query with mix of basis 1 and 2 - should prefer vec-5 which has [0.5, 0.5, 0, 0]
|
|
134
134
|
const hits = await index.query({
|
|
135
135
|
query: [{ vector: [0.5, 0.5, 0.0, 0.0] }],
|
|
136
|
-
|
|
136
|
+
limit: 10,
|
|
137
137
|
});
|
|
138
138
|
expect(hits.length).toBeGreaterThan(0);
|
|
139
139
|
expect(hits[0].id).toBe("vec-5");
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
142
|
// ============================================================
|
|
143
|
-
//
|
|
143
|
+
// LIMIT BEHAVIOR
|
|
144
144
|
// ============================================================
|
|
145
|
-
describe("
|
|
146
|
-
it("
|
|
145
|
+
describe("limit behavior", () => {
|
|
146
|
+
it("limit smaller than doc count returns exactly limit", async () => {
|
|
147
147
|
const hits = await index.query({
|
|
148
148
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
149
|
-
|
|
149
|
+
limit: 3,
|
|
150
150
|
});
|
|
151
151
|
expect(hits.length).toBe(3);
|
|
152
152
|
});
|
|
153
|
-
it("
|
|
153
|
+
it("limit larger than doc count returns all docs", async () => {
|
|
154
154
|
const hits = await index.query({
|
|
155
155
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
156
|
-
|
|
156
|
+
limit: 100,
|
|
157
157
|
});
|
|
158
158
|
// We have 6 docs
|
|
159
159
|
expect(hits.length).toBe(6);
|
|
160
160
|
});
|
|
161
|
-
it("
|
|
161
|
+
it("limit of 1 returns single best match", async () => {
|
|
162
162
|
const hits = await index.query({
|
|
163
163
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
164
|
-
|
|
164
|
+
limit: 1,
|
|
165
165
|
});
|
|
166
166
|
expect(hits.length).toBe(1);
|
|
167
167
|
expect(hits[0].id).toBe("vec-1");
|
|
@@ -174,7 +174,7 @@ describe("Query modes integration tests", () => {
|
|
|
174
174
|
it("single field text query finds matching docs", async () => {
|
|
175
175
|
const hits = await index.query({
|
|
176
176
|
query: [{ title: "neural" }],
|
|
177
|
-
|
|
177
|
+
limit: 10,
|
|
178
178
|
include: ["title"],
|
|
179
179
|
});
|
|
180
180
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -185,7 +185,7 @@ describe("Query modes integration tests", () => {
|
|
|
185
185
|
it("content field text query finds matching docs", async () => {
|
|
186
186
|
const hits = await index.query({
|
|
187
187
|
query: [{ content: "transformer" }],
|
|
188
|
-
|
|
188
|
+
limit: 10,
|
|
189
189
|
include: ["content"],
|
|
190
190
|
});
|
|
191
191
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -195,7 +195,7 @@ describe("Query modes integration tests", () => {
|
|
|
195
195
|
it("multi-field text query searches both fields", async () => {
|
|
196
196
|
const hits = await index.query({
|
|
197
197
|
query: [{ title: "database" }, { content: "database" }],
|
|
198
|
-
|
|
198
|
+
limit: 10,
|
|
199
199
|
include: ["title", "content"],
|
|
200
200
|
});
|
|
201
201
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -206,7 +206,7 @@ describe("Query modes integration tests", () => {
|
|
|
206
206
|
it("text query with no matches returns empty", async () => {
|
|
207
207
|
const hits = await index.query({
|
|
208
208
|
query: [{ content: "xyznonexistentkeyword123" }],
|
|
209
|
-
|
|
209
|
+
limit: 10,
|
|
210
210
|
});
|
|
211
211
|
expect(hits.length).toBe(0);
|
|
212
212
|
});
|
|
@@ -218,7 +218,7 @@ describe("Query modes integration tests", () => {
|
|
|
218
218
|
it("throws error for vector + text hybrid fusion", async () => {
|
|
219
219
|
await expect(index.query({
|
|
220
220
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }, { content: "search" }],
|
|
221
|
-
|
|
221
|
+
limit: 10,
|
|
222
222
|
})).rejects.toThrow(/does not support hybrid/);
|
|
223
223
|
});
|
|
224
224
|
it("throws error for multi-vector fusion", async () => {
|
|
@@ -227,7 +227,7 @@ describe("Query modes integration tests", () => {
|
|
|
227
227
|
{ vector: [1.0, 0.0, 0.0, 0.0] },
|
|
228
228
|
{ vector: [0.0, 1.0, 0.0, 0.0] },
|
|
229
229
|
],
|
|
230
|
-
|
|
230
|
+
limit: 10,
|
|
231
231
|
})).rejects.toThrow(/does not support multi-vector/);
|
|
232
232
|
});
|
|
233
233
|
});
|
|
@@ -238,7 +238,7 @@ describe("Query modes integration tests", () => {
|
|
|
238
238
|
it("Sum fusion combines multiple BM25 signals", async () => {
|
|
239
239
|
const hits = await index.query({
|
|
240
240
|
query: [{ title: "database" }, { content: "database" }],
|
|
241
|
-
|
|
241
|
+
limit: 10,
|
|
242
242
|
include: ["title", "content"],
|
|
243
243
|
});
|
|
244
244
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -249,7 +249,7 @@ describe("Query modes integration tests", () => {
|
|
|
249
249
|
it("Max fusion takes best BM25 signal per doc", async () => {
|
|
250
250
|
const hits = await index.query({
|
|
251
251
|
max: [{ title: "neural" }, { content: "neural" }],
|
|
252
|
-
|
|
252
|
+
limit: 10,
|
|
253
253
|
include: ["title", "content"],
|
|
254
254
|
});
|
|
255
255
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -265,7 +265,7 @@ describe("Query modes integration tests", () => {
|
|
|
265
265
|
it("include: true returns all attributes", async () => {
|
|
266
266
|
const hits = await index.query({
|
|
267
267
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
268
|
-
|
|
268
|
+
limit: 1,
|
|
269
269
|
include: true,
|
|
270
270
|
});
|
|
271
271
|
expect(hits.length).toBe(1);
|
|
@@ -278,7 +278,7 @@ describe("Query modes integration tests", () => {
|
|
|
278
278
|
it("include: false returns only id", async () => {
|
|
279
279
|
const hits = await index.query({
|
|
280
280
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
281
|
-
|
|
281
|
+
limit: 1,
|
|
282
282
|
include: false,
|
|
283
283
|
});
|
|
284
284
|
expect(hits.length).toBe(1);
|
|
@@ -289,7 +289,7 @@ describe("Query modes integration tests", () => {
|
|
|
289
289
|
it("include: [fields] returns only specified fields", async () => {
|
|
290
290
|
const hits = await index.query({
|
|
291
291
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
292
|
-
|
|
292
|
+
limit: 1,
|
|
293
293
|
include: ["title", "category"],
|
|
294
294
|
});
|
|
295
295
|
expect(hits.length).toBe(1);
|
|
@@ -303,7 +303,7 @@ describe("Query modes integration tests", () => {
|
|
|
303
303
|
it("include: [] returns only id", async () => {
|
|
304
304
|
const hits = await index.query({
|
|
305
305
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
306
|
-
|
|
306
|
+
limit: 1,
|
|
307
307
|
include: [],
|
|
308
308
|
});
|
|
309
309
|
expect(hits.length).toBe(1);
|
|
@@ -319,7 +319,7 @@ describe("Query modes integration tests", () => {
|
|
|
319
319
|
it("filter by category", async () => {
|
|
320
320
|
const hits = await index.query({
|
|
321
321
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
322
|
-
|
|
322
|
+
limit: 10,
|
|
323
323
|
filter: { category: "ml" },
|
|
324
324
|
include: ["category"],
|
|
325
325
|
});
|
|
@@ -331,7 +331,7 @@ describe("Query modes integration tests", () => {
|
|
|
331
331
|
it("filter by priority range", async () => {
|
|
332
332
|
const hits = await index.query({
|
|
333
333
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
334
|
-
|
|
334
|
+
limit: 10,
|
|
335
335
|
filter: { priority: { $gte: 3, $lte: 5 } },
|
|
336
336
|
include: ["priority"],
|
|
337
337
|
});
|
|
@@ -344,7 +344,7 @@ describe("Query modes integration tests", () => {
|
|
|
344
344
|
it("filter with $or", async () => {
|
|
345
345
|
const hits = await index.query({
|
|
346
346
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
347
|
-
|
|
347
|
+
limit: 10,
|
|
348
348
|
filter: {
|
|
349
349
|
$or: [{ category: "ml" }, { category: "search" }],
|
|
350
350
|
},
|
|
@@ -363,7 +363,7 @@ describe("Query modes integration tests", () => {
|
|
|
363
363
|
it("results have required fields", async () => {
|
|
364
364
|
const hits = await index.query({
|
|
365
365
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
366
|
-
|
|
366
|
+
limit: 1,
|
|
367
367
|
});
|
|
368
368
|
expect(hits.length).toBe(1);
|
|
369
369
|
expect(hits[0]).toHaveProperty("id");
|
|
@@ -375,7 +375,7 @@ describe("Query modes integration tests", () => {
|
|
|
375
375
|
it("score is a valid number", async () => {
|
|
376
376
|
const hits = await index.query({
|
|
377
377
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
378
|
-
|
|
378
|
+
limit: 5,
|
|
379
379
|
});
|
|
380
380
|
for (const hit of hits) {
|
|
381
381
|
expect(typeof hit.score).toBe("number");
|
|
@@ -161,25 +161,25 @@ describe("QUERY", () => {
|
|
|
161
161
|
// QUERY OPTIONS
|
|
162
162
|
// ============================================================
|
|
163
163
|
describe("query options", () => {
|
|
164
|
-
describe("
|
|
165
|
-
it("encodes
|
|
164
|
+
describe("limit", () => {
|
|
165
|
+
it("encodes limit as top_k", () => {
|
|
166
166
|
const result = QUERY.encode({
|
|
167
167
|
query: [{ vector: [0.1] }],
|
|
168
|
-
|
|
168
|
+
limit: 10,
|
|
169
169
|
});
|
|
170
170
|
expect(result.top_k).toBe(10);
|
|
171
171
|
});
|
|
172
|
-
it("encodes
|
|
172
|
+
it("encodes limit of 1", () => {
|
|
173
173
|
const result = QUERY.encode({
|
|
174
174
|
query: [{ vector: [0.1] }],
|
|
175
|
-
|
|
175
|
+
limit: 1,
|
|
176
176
|
});
|
|
177
177
|
expect(result.top_k).toBe(1);
|
|
178
178
|
});
|
|
179
|
-
it("encodes large
|
|
179
|
+
it("encodes large limit", () => {
|
|
180
180
|
const result = QUERY.encode({
|
|
181
181
|
query: [{ vector: [0.1] }],
|
|
182
|
-
|
|
182
|
+
limit: 10000,
|
|
183
183
|
});
|
|
184
184
|
expect(result.top_k).toBe(10000);
|
|
185
185
|
});
|
|
@@ -267,7 +267,7 @@ describe("QUERY", () => {
|
|
|
267
267
|
it("encodes all options together", () => {
|
|
268
268
|
const result = QUERY.encode({
|
|
269
269
|
query: [{ vector: [0.1, 0.2] }],
|
|
270
|
-
|
|
270
|
+
limit: 20,
|
|
271
271
|
filter: { category: "news" },
|
|
272
272
|
include: ["title", "summary"],
|
|
273
273
|
});
|
|
@@ -315,14 +315,14 @@ describe("QUERY", () => {
|
|
|
315
315
|
// Direct codec call with empty array returns params without rank_by.
|
|
316
316
|
const result = QUERY.encode({
|
|
317
317
|
query: [],
|
|
318
|
-
|
|
318
|
+
limit: 10,
|
|
319
319
|
});
|
|
320
320
|
expect(result.rank_by).toBeUndefined();
|
|
321
321
|
expect(result.top_k).toBe(10);
|
|
322
322
|
});
|
|
323
323
|
it("returns params without rank_by when no query or max", () => {
|
|
324
324
|
const result = QUERY.encode({
|
|
325
|
-
|
|
325
|
+
limit: 10,
|
|
326
326
|
filter: { status: "active" },
|
|
327
327
|
});
|
|
328
328
|
expect(result.rank_by).toBeUndefined();
|
package/dist/convert/query.js
CHANGED
|
@@ -15,9 +15,9 @@ export const QUERY = {
|
|
|
15
15
|
if (signals && signals.length > 0) {
|
|
16
16
|
params.rank_by = buildRankBy(signals, query.max !== undefined);
|
|
17
17
|
}
|
|
18
|
-
//
|
|
19
|
-
if (query.
|
|
20
|
-
params.top_k = query.
|
|
18
|
+
// limit
|
|
19
|
+
if (query.limit !== undefined) {
|
|
20
|
+
params.top_k = query.limit;
|
|
21
21
|
}
|
|
22
22
|
// filters
|
|
23
23
|
if (query.filter) {
|
package/dist/search.d.ts
CHANGED
package/dist/search.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kernl-sdk/turbopuffer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Turbopuffer search index adapter for kernl",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kernl",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@turbopuffer/turbopuffer": "^0.10.0",
|
|
34
|
-
"@kernl-sdk/retrieval": "0.1.
|
|
34
|
+
"@kernl-sdk/retrieval": "0.1.6",
|
|
35
35
|
"@kernl-sdk/shared": "0.3.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"tsc-alias": "^1.8.10",
|
|
42
42
|
"typescript": "5.9.2",
|
|
43
43
|
"vitest": "^4.0.8",
|
|
44
|
-
"@kernl-sdk/ai": "0.3.
|
|
45
|
-
"@kernl-sdk/
|
|
46
|
-
"@kernl-sdk/
|
|
47
|
-
"kernl": "0.
|
|
44
|
+
"@kernl-sdk/ai": "0.3.3",
|
|
45
|
+
"@kernl-sdk/protocol": "0.4.0",
|
|
46
|
+
"@kernl-sdk/pg": "0.1.26",
|
|
47
|
+
"kernl": "0.10.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc && tsc-alias --resolve-full-paths",
|
|
@@ -296,7 +296,7 @@ describe("convert", () => {
|
|
|
296
296
|
it("encodes vector search query", () => {
|
|
297
297
|
const result = QUERY.encode({
|
|
298
298
|
query: [{ vector: [0.1, 0.2, 0.3] }],
|
|
299
|
-
|
|
299
|
+
limit: 10,
|
|
300
300
|
});
|
|
301
301
|
|
|
302
302
|
expect(result.rank_by).toEqual(["vector", "ANN", [0.1, 0.2, 0.3]]);
|
|
@@ -306,7 +306,7 @@ describe("convert", () => {
|
|
|
306
306
|
it("encodes text search query", () => {
|
|
307
307
|
const result = QUERY.encode({
|
|
308
308
|
query: [{ content: "hello world" }],
|
|
309
|
-
|
|
309
|
+
limit: 5,
|
|
310
310
|
});
|
|
311
311
|
|
|
312
312
|
expect(result.rank_by).toEqual(["content", "BM25", "hello world"]);
|
|
@@ -316,7 +316,7 @@ describe("convert", () => {
|
|
|
316
316
|
it("encodes multi-field text search as Sum", () => {
|
|
317
317
|
const result = QUERY.encode({
|
|
318
318
|
query: [{ title: "search term" }, { body: "search term" }],
|
|
319
|
-
|
|
319
|
+
limit: 10,
|
|
320
320
|
});
|
|
321
321
|
|
|
322
322
|
expect(result.rank_by).toEqual([
|
|
@@ -331,7 +331,7 @@ describe("convert", () => {
|
|
|
331
331
|
it("encodes filter", () => {
|
|
332
332
|
const result = QUERY.encode({
|
|
333
333
|
query: [{ vector: [0.1] }],
|
|
334
|
-
|
|
334
|
+
limit: 5,
|
|
335
335
|
filter: { category: { $eq: "news" } },
|
|
336
336
|
});
|
|
337
337
|
|
|
@@ -341,7 +341,7 @@ describe("convert", () => {
|
|
|
341
341
|
it("encodes include fields array", () => {
|
|
342
342
|
const result = QUERY.encode({
|
|
343
343
|
query: [{ vector: [0.1] }],
|
|
344
|
-
|
|
344
|
+
limit: 5,
|
|
345
345
|
include: ["title", "content"],
|
|
346
346
|
});
|
|
347
347
|
|
|
@@ -351,7 +351,7 @@ describe("convert", () => {
|
|
|
351
351
|
it("encodes include as boolean", () => {
|
|
352
352
|
const result = QUERY.encode({
|
|
353
353
|
query: [{ vector: [0.1] }],
|
|
354
|
-
|
|
354
|
+
limit: 5,
|
|
355
355
|
include: true,
|
|
356
356
|
});
|
|
357
357
|
|
|
@@ -191,7 +191,7 @@ describe("Filter integration tests", () => {
|
|
|
191
191
|
async function queryIds(filter: Filter): Promise<string[]> {
|
|
192
192
|
const hits = await ns.query({
|
|
193
193
|
query: [{ vector: QUERY_VECTOR }],
|
|
194
|
-
|
|
194
|
+
limit: 100,
|
|
195
195
|
filter,
|
|
196
196
|
});
|
|
197
197
|
return hits.map((h) => h.id).sort();
|
|
@@ -518,7 +518,7 @@ describe("Filter integration tests", () => {
|
|
|
518
518
|
it("filtered results have correct field values", async () => {
|
|
519
519
|
const hits = await ns.query({
|
|
520
520
|
query: [{ vector: QUERY_VECTOR }],
|
|
521
|
-
|
|
521
|
+
limit: 100,
|
|
522
522
|
filter: { status: "pending" },
|
|
523
523
|
include: ["status", "flag", "num"],
|
|
524
524
|
});
|
|
@@ -537,7 +537,7 @@ describe("Filter integration tests", () => {
|
|
|
537
537
|
it("complex filter returns expected documents with correct data", async () => {
|
|
538
538
|
const hits = await ns.query({
|
|
539
539
|
query: [{ vector: QUERY_VECTOR }],
|
|
540
|
-
|
|
540
|
+
limit: 100,
|
|
541
541
|
filter: {
|
|
542
542
|
$and: [{ num: { $gte: 20, $lte: 50 } }, { flag: true }],
|
|
543
543
|
},
|
|
@@ -176,7 +176,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
176
176
|
// Verify via query
|
|
177
177
|
const hits = await index.query({
|
|
178
178
|
query: [{ vector: vec }],
|
|
179
|
-
|
|
179
|
+
limit: 10,
|
|
180
180
|
include: ["category"],
|
|
181
181
|
});
|
|
182
182
|
|
|
@@ -201,7 +201,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
201
201
|
// Verify via query
|
|
202
202
|
const hits = await index.query({
|
|
203
203
|
query: [{ vector: vec }],
|
|
204
|
-
|
|
204
|
+
limit: 10,
|
|
205
205
|
include: ["category"],
|
|
206
206
|
});
|
|
207
207
|
|
|
@@ -233,7 +233,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
233
233
|
// Verify via query with filter
|
|
234
234
|
const hits = await index.query({
|
|
235
235
|
query: [{ vector: new Array(384).fill(0.3) }],
|
|
236
|
-
|
|
236
|
+
limit: 10,
|
|
237
237
|
filter: { category: "test" },
|
|
238
238
|
include: true,
|
|
239
239
|
});
|
|
@@ -257,7 +257,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
257
257
|
|
|
258
258
|
const hits = await index.query({
|
|
259
259
|
query: [{ vector: new Array(384).fill(0.1) }],
|
|
260
|
-
|
|
260
|
+
limit: 5,
|
|
261
261
|
});
|
|
262
262
|
|
|
263
263
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -271,7 +271,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
271
271
|
|
|
272
272
|
const hits = await index.query({
|
|
273
273
|
query: [{ vector: new Array(384).fill(0.1) }],
|
|
274
|
-
|
|
274
|
+
limit: 5,
|
|
275
275
|
include: ["content", "category"],
|
|
276
276
|
});
|
|
277
277
|
|
|
@@ -286,7 +286,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
286
286
|
|
|
287
287
|
const hits = await index.query({
|
|
288
288
|
query: [{ vector: new Array(384).fill(0.3) }],
|
|
289
|
-
|
|
289
|
+
limit: 10,
|
|
290
290
|
filter: { category: "test" },
|
|
291
291
|
include: ["category"],
|
|
292
292
|
});
|
|
@@ -302,7 +302,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
302
302
|
|
|
303
303
|
const hits = await index.query({
|
|
304
304
|
query: [{ vector: new Array(384).fill(0.3) }],
|
|
305
|
-
|
|
305
|
+
limit: 10,
|
|
306
306
|
filter: {
|
|
307
307
|
$and: [
|
|
308
308
|
{ category: "test" },
|
|
@@ -335,7 +335,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
335
335
|
// Verify it exists
|
|
336
336
|
let hits = await index.query({
|
|
337
337
|
query: [{ vector: vec }],
|
|
338
|
-
|
|
338
|
+
limit: 10,
|
|
339
339
|
filter: { id: "doc-to-delete" },
|
|
340
340
|
});
|
|
341
341
|
expect(hits.some((h) => h.id === "doc-to-delete")).toBe(true);
|
|
@@ -346,7 +346,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
346
346
|
// Verify it's gone
|
|
347
347
|
hits = await index.query({
|
|
348
348
|
query: [{ vector: vec }],
|
|
349
|
-
|
|
349
|
+
limit: 10,
|
|
350
350
|
filter: { id: "doc-to-delete" },
|
|
351
351
|
});
|
|
352
352
|
expect(hits.some((h) => h.id === "doc-to-delete")).toBe(false);
|
|
@@ -377,7 +377,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
377
377
|
// Verify they exist
|
|
378
378
|
let hits = await index.query({
|
|
379
379
|
query: [{ vector: vec }],
|
|
380
|
-
|
|
380
|
+
limit: 10,
|
|
381
381
|
filter: { category: "bulk-delete" },
|
|
382
382
|
});
|
|
383
383
|
expect(hits.length).toBeGreaterThanOrEqual(2);
|
|
@@ -388,7 +388,7 @@ describe("TurbopufferSearchIndex integration", () => {
|
|
|
388
388
|
// Verify they're gone
|
|
389
389
|
hits = await index.query({
|
|
390
390
|
query: [{ vector: vec }],
|
|
391
|
-
|
|
391
|
+
limit: 10,
|
|
392
392
|
filter: { category: "bulk-delete" },
|
|
393
393
|
});
|
|
394
394
|
expect(hits.some((h) => h.id === "bulk-del-1")).toBe(false);
|
|
@@ -182,7 +182,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
182
182
|
// Query and verify final state
|
|
183
183
|
const hits = await index.query({
|
|
184
184
|
query: [{ vector: [0.3, 0.3, 0.3, 0.3] }],
|
|
185
|
-
|
|
185
|
+
limit: 10,
|
|
186
186
|
filter: { id: "overwrite-test" },
|
|
187
187
|
include: ["content", "count"],
|
|
188
188
|
});
|
|
@@ -205,7 +205,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
205
205
|
|
|
206
206
|
const hits = await index.query({
|
|
207
207
|
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
208
|
-
|
|
208
|
+
limit: 10,
|
|
209
209
|
filter: { id: "minimal-doc" },
|
|
210
210
|
});
|
|
211
211
|
|
|
@@ -311,7 +311,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
311
311
|
// Verify exists
|
|
312
312
|
let hits = await index.query({
|
|
313
313
|
query: [{ vector: [0.9, 0.9, 0.9, 0.9] }],
|
|
314
|
-
|
|
314
|
+
limit: 10,
|
|
315
315
|
filter: { id: "to-delete" },
|
|
316
316
|
});
|
|
317
317
|
expect(hits.length).toBe(1);
|
|
@@ -324,7 +324,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
324
324
|
// Verify gone
|
|
325
325
|
hits = await index.query({
|
|
326
326
|
query: [{ vector: [0.9, 0.9, 0.9, 0.9] }],
|
|
327
|
-
|
|
327
|
+
limit: 10,
|
|
328
328
|
filter: { id: "to-delete" },
|
|
329
329
|
});
|
|
330
330
|
expect(hits.length).toBe(0);
|
|
@@ -361,7 +361,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
361
361
|
|
|
362
362
|
const hits = await index.query({
|
|
363
363
|
query: [{ vector: [0.1, 0.2, 0.3, 0.4] }],
|
|
364
|
-
|
|
364
|
+
limit: 10,
|
|
365
365
|
});
|
|
366
366
|
|
|
367
367
|
expect(hits).toEqual([]);
|
|
@@ -382,20 +382,20 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
382
382
|
// Query with filter that matches nothing
|
|
383
383
|
const hits = await index.query({
|
|
384
384
|
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
385
|
-
|
|
385
|
+
limit: 10,
|
|
386
386
|
filter: { id: "nonexistent-id" },
|
|
387
387
|
});
|
|
388
388
|
|
|
389
389
|
expect(hits).toEqual([]);
|
|
390
390
|
});
|
|
391
391
|
|
|
392
|
-
it("
|
|
392
|
+
it("limit of 0 throws", async () => {
|
|
393
393
|
const index = tpuf.index(indexId);
|
|
394
394
|
|
|
395
395
|
await expect(
|
|
396
396
|
index.query({
|
|
397
397
|
query: [{ vector: [0.1, 0.1, 0.1, 0.1] }],
|
|
398
|
-
|
|
398
|
+
limit: 0,
|
|
399
399
|
}),
|
|
400
400
|
).rejects.toThrow();
|
|
401
401
|
});
|
|
@@ -453,7 +453,7 @@ describe("Lifecycle edge cases integration tests", () => {
|
|
|
453
453
|
await expect(
|
|
454
454
|
index.query({
|
|
455
455
|
query: [{ vector: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8] }], // 8 dims
|
|
456
|
-
|
|
456
|
+
limit: 10,
|
|
457
457
|
}),
|
|
458
458
|
).rejects.toThrow();
|
|
459
459
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Comprehensive query modes integration tests.
|
|
3
3
|
*
|
|
4
4
|
* Tests vector search, BM25 text search, hybrid queries, fusion modes,
|
|
5
|
-
*
|
|
5
|
+
* limit behavior, include semantics, and rank ordering against real Turbopuffer API.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
@@ -138,7 +138,7 @@ describe("Query modes integration tests", () => {
|
|
|
138
138
|
// Query with basis vector 1 - should match vec-1 best
|
|
139
139
|
const hits = await index.query({
|
|
140
140
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
141
|
-
|
|
141
|
+
limit: 10,
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -149,7 +149,7 @@ describe("Query modes integration tests", () => {
|
|
|
149
149
|
// Query with basis vector 2
|
|
150
150
|
const hits = await index.query({
|
|
151
151
|
query: [{ vector: [0.0, 1.0, 0.0, 0.0] }],
|
|
152
|
-
|
|
152
|
+
limit: 10,
|
|
153
153
|
});
|
|
154
154
|
|
|
155
155
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -165,7 +165,7 @@ describe("Query modes integration tests", () => {
|
|
|
165
165
|
// Query with mix of basis 1 and 2 - should prefer vec-5 which has [0.5, 0.5, 0, 0]
|
|
166
166
|
const hits = await index.query({
|
|
167
167
|
query: [{ vector: [0.5, 0.5, 0.0, 0.0] }],
|
|
168
|
-
|
|
168
|
+
limit: 10,
|
|
169
169
|
});
|
|
170
170
|
|
|
171
171
|
expect(hits.length).toBeGreaterThan(0);
|
|
@@ -174,33 +174,33 @@ describe("Query modes integration tests", () => {
|
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
// ============================================================
|
|
177
|
-
//
|
|
177
|
+
// LIMIT BEHAVIOR
|
|
178
178
|
// ============================================================
|
|
179
179
|
|
|
180
|
-
describe("
|
|
181
|
-
it("
|
|
180
|
+
describe("limit behavior", () => {
|
|
181
|
+
it("limit smaller than doc count returns exactly limit", async () => {
|
|
182
182
|
const hits = await index.query({
|
|
183
183
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
184
|
-
|
|
184
|
+
limit: 3,
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
expect(hits.length).toBe(3);
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
-
it("
|
|
190
|
+
it("limit larger than doc count returns all docs", async () => {
|
|
191
191
|
const hits = await index.query({
|
|
192
192
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
193
|
-
|
|
193
|
+
limit: 100,
|
|
194
194
|
});
|
|
195
195
|
|
|
196
196
|
// We have 6 docs
|
|
197
197
|
expect(hits.length).toBe(6);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
it("
|
|
200
|
+
it("limit of 1 returns single best match", async () => {
|
|
201
201
|
const hits = await index.query({
|
|
202
202
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
203
|
-
|
|
203
|
+
limit: 1,
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
expect(hits.length).toBe(1);
|
|
@@ -216,7 +216,7 @@ describe("Query modes integration tests", () => {
|
|
|
216
216
|
it("single field text query finds matching docs", async () => {
|
|
217
217
|
const hits = await index.query({
|
|
218
218
|
query: [{ title: "neural" }],
|
|
219
|
-
|
|
219
|
+
limit: 10,
|
|
220
220
|
include: ["title"],
|
|
221
221
|
});
|
|
222
222
|
|
|
@@ -231,7 +231,7 @@ describe("Query modes integration tests", () => {
|
|
|
231
231
|
it("content field text query finds matching docs", async () => {
|
|
232
232
|
const hits = await index.query({
|
|
233
233
|
query: [{ content: "transformer" }],
|
|
234
|
-
|
|
234
|
+
limit: 10,
|
|
235
235
|
include: ["content"],
|
|
236
236
|
});
|
|
237
237
|
|
|
@@ -243,7 +243,7 @@ describe("Query modes integration tests", () => {
|
|
|
243
243
|
it("multi-field text query searches both fields", async () => {
|
|
244
244
|
const hits = await index.query({
|
|
245
245
|
query: [{ title: "database" }, { content: "database" }],
|
|
246
|
-
|
|
246
|
+
limit: 10,
|
|
247
247
|
include: ["title", "content"],
|
|
248
248
|
});
|
|
249
249
|
|
|
@@ -256,7 +256,7 @@ describe("Query modes integration tests", () => {
|
|
|
256
256
|
it("text query with no matches returns empty", async () => {
|
|
257
257
|
const hits = await index.query({
|
|
258
258
|
query: [{ content: "xyznonexistentkeyword123" }],
|
|
259
|
-
|
|
259
|
+
limit: 10,
|
|
260
260
|
});
|
|
261
261
|
|
|
262
262
|
expect(hits.length).toBe(0);
|
|
@@ -272,7 +272,7 @@ describe("Query modes integration tests", () => {
|
|
|
272
272
|
await expect(
|
|
273
273
|
index.query({
|
|
274
274
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }, { content: "search" }],
|
|
275
|
-
|
|
275
|
+
limit: 10,
|
|
276
276
|
}),
|
|
277
277
|
).rejects.toThrow(/does not support hybrid/);
|
|
278
278
|
});
|
|
@@ -284,7 +284,7 @@ describe("Query modes integration tests", () => {
|
|
|
284
284
|
{ vector: [1.0, 0.0, 0.0, 0.0] },
|
|
285
285
|
{ vector: [0.0, 1.0, 0.0, 0.0] },
|
|
286
286
|
],
|
|
287
|
-
|
|
287
|
+
limit: 10,
|
|
288
288
|
}),
|
|
289
289
|
).rejects.toThrow(/does not support multi-vector/);
|
|
290
290
|
});
|
|
@@ -298,7 +298,7 @@ describe("Query modes integration tests", () => {
|
|
|
298
298
|
it("Sum fusion combines multiple BM25 signals", async () => {
|
|
299
299
|
const hits = await index.query({
|
|
300
300
|
query: [{ title: "database" }, { content: "database" }],
|
|
301
|
-
|
|
301
|
+
limit: 10,
|
|
302
302
|
include: ["title", "content"],
|
|
303
303
|
});
|
|
304
304
|
|
|
@@ -311,7 +311,7 @@ describe("Query modes integration tests", () => {
|
|
|
311
311
|
it("Max fusion takes best BM25 signal per doc", async () => {
|
|
312
312
|
const hits = await index.query({
|
|
313
313
|
max: [{ title: "neural" }, { content: "neural" }],
|
|
314
|
-
|
|
314
|
+
limit: 10,
|
|
315
315
|
include: ["title", "content"],
|
|
316
316
|
});
|
|
317
317
|
|
|
@@ -330,7 +330,7 @@ describe("Query modes integration tests", () => {
|
|
|
330
330
|
it("include: true returns all attributes", async () => {
|
|
331
331
|
const hits = await index.query({
|
|
332
332
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
333
|
-
|
|
333
|
+
limit: 1,
|
|
334
334
|
include: true,
|
|
335
335
|
});
|
|
336
336
|
|
|
@@ -345,7 +345,7 @@ describe("Query modes integration tests", () => {
|
|
|
345
345
|
it("include: false returns only id", async () => {
|
|
346
346
|
const hits = await index.query({
|
|
347
347
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
348
|
-
|
|
348
|
+
limit: 1,
|
|
349
349
|
include: false,
|
|
350
350
|
});
|
|
351
351
|
|
|
@@ -358,7 +358,7 @@ describe("Query modes integration tests", () => {
|
|
|
358
358
|
it("include: [fields] returns only specified fields", async () => {
|
|
359
359
|
const hits = await index.query({
|
|
360
360
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
361
|
-
|
|
361
|
+
limit: 1,
|
|
362
362
|
include: ["title", "category"],
|
|
363
363
|
});
|
|
364
364
|
|
|
@@ -374,7 +374,7 @@ describe("Query modes integration tests", () => {
|
|
|
374
374
|
it("include: [] returns only id", async () => {
|
|
375
375
|
const hits = await index.query({
|
|
376
376
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
377
|
-
|
|
377
|
+
limit: 1,
|
|
378
378
|
include: [],
|
|
379
379
|
});
|
|
380
380
|
|
|
@@ -393,7 +393,7 @@ describe("Query modes integration tests", () => {
|
|
|
393
393
|
it("filter by category", async () => {
|
|
394
394
|
const hits = await index.query({
|
|
395
395
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
396
|
-
|
|
396
|
+
limit: 10,
|
|
397
397
|
filter: { category: "ml" },
|
|
398
398
|
include: ["category"],
|
|
399
399
|
});
|
|
@@ -407,7 +407,7 @@ describe("Query modes integration tests", () => {
|
|
|
407
407
|
it("filter by priority range", async () => {
|
|
408
408
|
const hits = await index.query({
|
|
409
409
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
410
|
-
|
|
410
|
+
limit: 10,
|
|
411
411
|
filter: { priority: { $gte: 3, $lte: 5 } },
|
|
412
412
|
include: ["priority"],
|
|
413
413
|
});
|
|
@@ -422,7 +422,7 @@ describe("Query modes integration tests", () => {
|
|
|
422
422
|
it("filter with $or", async () => {
|
|
423
423
|
const hits = await index.query({
|
|
424
424
|
query: [{ vector: [0.5, 0.5, 0.5, 0.5] }],
|
|
425
|
-
|
|
425
|
+
limit: 10,
|
|
426
426
|
filter: {
|
|
427
427
|
$or: [{ category: "ml" }, { category: "search" }],
|
|
428
428
|
},
|
|
@@ -444,7 +444,7 @@ describe("Query modes integration tests", () => {
|
|
|
444
444
|
it("results have required fields", async () => {
|
|
445
445
|
const hits = await index.query({
|
|
446
446
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
447
|
-
|
|
447
|
+
limit: 1,
|
|
448
448
|
});
|
|
449
449
|
|
|
450
450
|
expect(hits.length).toBe(1);
|
|
@@ -458,7 +458,7 @@ describe("Query modes integration tests", () => {
|
|
|
458
458
|
it("score is a valid number", async () => {
|
|
459
459
|
const hits = await index.query({
|
|
460
460
|
query: [{ vector: [1.0, 0.0, 0.0, 0.0] }],
|
|
461
|
-
|
|
461
|
+
limit: 5,
|
|
462
462
|
});
|
|
463
463
|
|
|
464
464
|
for (const hit of hits) {
|
|
@@ -210,29 +210,29 @@ describe("QUERY", () => {
|
|
|
210
210
|
// ============================================================
|
|
211
211
|
|
|
212
212
|
describe("query options", () => {
|
|
213
|
-
describe("
|
|
214
|
-
it("encodes
|
|
213
|
+
describe("limit", () => {
|
|
214
|
+
it("encodes limit as top_k", () => {
|
|
215
215
|
const result = QUERY.encode({
|
|
216
216
|
query: [{ vector: [0.1] }],
|
|
217
|
-
|
|
217
|
+
limit: 10,
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
expect(result.top_k).toBe(10);
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
-
it("encodes
|
|
223
|
+
it("encodes limit of 1", () => {
|
|
224
224
|
const result = QUERY.encode({
|
|
225
225
|
query: [{ vector: [0.1] }],
|
|
226
|
-
|
|
226
|
+
limit: 1,
|
|
227
227
|
});
|
|
228
228
|
|
|
229
229
|
expect(result.top_k).toBe(1);
|
|
230
230
|
});
|
|
231
231
|
|
|
232
|
-
it("encodes large
|
|
232
|
+
it("encodes large limit", () => {
|
|
233
233
|
const result = QUERY.encode({
|
|
234
234
|
query: [{ vector: [0.1] }],
|
|
235
|
-
|
|
235
|
+
limit: 10000,
|
|
236
236
|
});
|
|
237
237
|
|
|
238
238
|
expect(result.top_k).toBe(10000);
|
|
@@ -342,7 +342,7 @@ describe("QUERY", () => {
|
|
|
342
342
|
it("encodes all options together", () => {
|
|
343
343
|
const result = QUERY.encode({
|
|
344
344
|
query: [{ vector: [0.1, 0.2] }],
|
|
345
|
-
|
|
345
|
+
limit: 20,
|
|
346
346
|
filter: { category: "news" },
|
|
347
347
|
include: ["title", "summary"],
|
|
348
348
|
});
|
|
@@ -405,7 +405,7 @@ describe("QUERY", () => {
|
|
|
405
405
|
// Direct codec call with empty array returns params without rank_by.
|
|
406
406
|
const result = QUERY.encode({
|
|
407
407
|
query: [],
|
|
408
|
-
|
|
408
|
+
limit: 10,
|
|
409
409
|
});
|
|
410
410
|
|
|
411
411
|
expect(result.rank_by).toBeUndefined();
|
|
@@ -414,7 +414,7 @@ describe("QUERY", () => {
|
|
|
414
414
|
|
|
415
415
|
it("returns params without rank_by when no query or max", () => {
|
|
416
416
|
const result = QUERY.encode({
|
|
417
|
-
|
|
417
|
+
limit: 10,
|
|
418
418
|
filter: { status: "active" },
|
|
419
419
|
});
|
|
420
420
|
|
package/src/convert/query.ts
CHANGED
|
@@ -31,9 +31,9 @@ export const QUERY = {
|
|
|
31
31
|
params.rank_by = buildRankBy(signals, query.max !== undefined);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
if (query.
|
|
36
|
-
params.top_k = query.
|
|
34
|
+
// limit
|
|
35
|
+
if (query.limit !== undefined) {
|
|
36
|
+
params.top_k = query.limit;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// filters
|