@functional-systems/lambdadb 0.5.1 → 0.7.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/CHANGELOG.md +57 -0
- package/README.md +44 -1
- package/dist/commonjs/compat/qdrant/conversions.d.ts.map +1 -1
- package/dist/commonjs/compat/qdrant/conversions.js +4 -0
- package/dist/commonjs/compat/qdrant/conversions.js.map +1 -1
- package/dist/commonjs/lib/config.d.ts +2 -2
- package/dist/commonjs/lib/config.js +2 -2
- package/dist/commonjs/models/index.d.ts +1 -0
- package/dist/commonjs/models/index.d.ts.map +1 -1
- package/dist/commonjs/models/index.js +1 -0
- package/dist/commonjs/models/index.js.map +1 -1
- package/dist/commonjs/models/indexconfigsunion.d.ts +49 -2
- package/dist/commonjs/models/indexconfigsunion.d.ts.map +1 -1
- package/dist/commonjs/models/indexconfigsunion.js +49 -2
- package/dist/commonjs/models/indexconfigsunion.js.map +1 -1
- package/dist/commonjs/models/operations/querycollection.d.ts +28 -6
- package/dist/commonjs/models/operations/querycollection.d.ts.map +1 -1
- package/dist/commonjs/models/operations/querycollection.js +46 -2
- package/dist/commonjs/models/operations/querycollection.js.map +1 -1
- package/dist/commonjs/models/rerank.d.ts +37 -0
- package/dist/commonjs/models/rerank.d.ts.map +1 -0
- package/dist/commonjs/models/rerank.js +86 -0
- package/dist/commonjs/models/rerank.js.map +1 -0
- package/dist/commonjs/types/public.d.ts +2 -0
- package/dist/commonjs/types/public.d.ts.map +1 -1
- package/dist/esm/compat/qdrant/conversions.d.ts.map +1 -1
- package/dist/esm/compat/qdrant/conversions.js +4 -0
- package/dist/esm/compat/qdrant/conversions.js.map +1 -1
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/config.js +2 -2
- package/dist/esm/models/index.d.ts +1 -0
- package/dist/esm/models/index.d.ts.map +1 -1
- package/dist/esm/models/index.js +1 -0
- package/dist/esm/models/index.js.map +1 -1
- package/dist/esm/models/indexconfigsunion.d.ts +49 -2
- package/dist/esm/models/indexconfigsunion.d.ts.map +1 -1
- package/dist/esm/models/indexconfigsunion.js +49 -2
- package/dist/esm/models/indexconfigsunion.js.map +1 -1
- package/dist/esm/models/operations/querycollection.d.ts +28 -6
- package/dist/esm/models/operations/querycollection.d.ts.map +1 -1
- package/dist/esm/models/operations/querycollection.js +46 -2
- package/dist/esm/models/operations/querycollection.js.map +1 -1
- package/dist/esm/models/rerank.d.ts +37 -0
- package/dist/esm/models/rerank.d.ts.map +1 -0
- package/dist/esm/models/rerank.js +49 -0
- package/dist/esm/models/rerank.js.map +1 -0
- package/dist/esm/types/public.d.ts +2 -0
- package/dist/esm/types/public.d.ts.map +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/compat/qdrant/conversions.ts +6 -0
- package/src/lib/config.ts +2 -2
- package/src/models/index.ts +1 -0
- package/src/models/indexconfigsunion.ts +52 -3
- package/src/models/operations/querycollection.ts +68 -6
- package/src/models/rerank.ts +89 -0
- package/src/types/public.ts +4 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
2
|
+
* Maintained manually following docs/OPENAPI_UPDATE.md.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as z from "zod/v3";
|
|
@@ -8,6 +8,14 @@ import { nullToUndefined, safeParse } from "../../lib/schemas.js";
|
|
|
8
8
|
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
9
9
|
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
10
10
|
import * as models from "../index.js";
|
|
11
|
+
import { hasRerankScoringQuery } from "../rerank.js";
|
|
12
|
+
|
|
13
|
+
export type FacetRequest = {
|
|
14
|
+
/** Maximum buckets to return (1–100). Omitted or null uses the server default of 10. */
|
|
15
|
+
size?: number | null | undefined;
|
|
16
|
+
};
|
|
17
|
+
export type FacetBucket = { value: string; count: number };
|
|
18
|
+
export type FacetResult = { buckets: Array<FacetBucket> };
|
|
11
19
|
|
|
12
20
|
export type QueryCollectionRequestBody = {
|
|
13
21
|
/**
|
|
@@ -17,7 +25,10 @@ export type QueryCollectionRequestBody = {
|
|
|
17
25
|
/**
|
|
18
26
|
* Query object. For managed embedding vector fields, use knn.queryText. For unmanaged vector fields, use knn.queryVector.
|
|
19
27
|
*/
|
|
20
|
-
query
|
|
28
|
+
query?: { [k: string]: any } | undefined;
|
|
29
|
+
facets?: Record<string, FacetRequest> | undefined;
|
|
30
|
+
/** Optional per-query managed reranking. Omitted or null preserves retrieval behavior. */
|
|
31
|
+
rerank?: models.RerankConfig | null | undefined;
|
|
21
32
|
/**
|
|
22
33
|
* Overlay eligible pending writes on a directly selected Branch. Tag and Alias reads reject true, pending bulk imports are excluded, and an oversized pending overlay can return HTTP 429.
|
|
23
34
|
*/
|
|
@@ -53,9 +64,11 @@ export type QueryCollectionDoc = {
|
|
|
53
64
|
*/
|
|
54
65
|
collection: string;
|
|
55
66
|
/**
|
|
56
|
-
*
|
|
67
|
+
* Final ranking score: evaluation score in [0,1] when rerank is applied, otherwise retrieval score.
|
|
57
68
|
*/
|
|
58
69
|
score?: number | undefined;
|
|
70
|
+
/** Original retrieval/fusion score, outside doc; present only when rerank is applied. */
|
|
71
|
+
retrievalScore?: number | undefined;
|
|
59
72
|
doc: { [k: string]: any };
|
|
60
73
|
};
|
|
61
74
|
|
|
@@ -63,12 +76,15 @@ export type QueryCollectionDoc = {
|
|
|
63
76
|
* Documents selected by query.
|
|
64
77
|
*/
|
|
65
78
|
export type QueryCollectionResponse = {
|
|
79
|
+
/** Present only for requests using reranking. */
|
|
80
|
+
rerank?: models.RerankResponse | undefined;
|
|
81
|
+
facets?: Record<string, FacetResult> | undefined;
|
|
66
82
|
/**
|
|
67
83
|
* Elapsed time in milliseconds.
|
|
68
84
|
*/
|
|
69
85
|
took: number;
|
|
70
86
|
/**
|
|
71
|
-
* Maximum score.
|
|
87
|
+
* Maximum final returned score, including zero; omitted for empty rerank results.
|
|
72
88
|
*/
|
|
73
89
|
maxScore?: number | undefined;
|
|
74
90
|
/**
|
|
@@ -92,7 +108,10 @@ export type QueryCollectionResponse = {
|
|
|
92
108
|
/** @internal */
|
|
93
109
|
export type QueryCollectionRequestBody$Outbound = {
|
|
94
110
|
size?: number | undefined;
|
|
95
|
-
query
|
|
111
|
+
query?: { [k: string]: any } | undefined;
|
|
112
|
+
facets?: Record<string, FacetRequest> | undefined;
|
|
113
|
+
/** Optional per-query managed reranking. Omitted or null preserves retrieval behavior. */
|
|
114
|
+
rerank?: models.RerankConfig | null | undefined;
|
|
96
115
|
consistentRead: boolean;
|
|
97
116
|
includeVectors: boolean;
|
|
98
117
|
sort?: Array<{ [k: string]: any }> | undefined;
|
|
@@ -108,7 +127,13 @@ export const QueryCollectionRequestBody$outboundSchema: z.ZodType<
|
|
|
108
127
|
QueryCollectionRequestBody
|
|
109
128
|
> = z.object({
|
|
110
129
|
size: z.number().int().optional(),
|
|
111
|
-
query: z.record(z.any()),
|
|
130
|
+
query: z.record(z.any()).optional(),
|
|
131
|
+
facets: z.record(z.object({
|
|
132
|
+
size: z.number().int().min(1).max(100).nullable().optional(),
|
|
133
|
+
}).strict()).refine((facets) => Object.keys(facets).length <= 5, {
|
|
134
|
+
message: "At most five facet fields may be requested",
|
|
135
|
+
}).optional(),
|
|
136
|
+
rerank: models.RerankConfig$outboundSchema.nullable().optional(),
|
|
112
137
|
consistentRead: z.boolean().default(false),
|
|
113
138
|
includeVectors: z.boolean().default(false),
|
|
114
139
|
sort: z.array(z.record(z.any())).optional(),
|
|
@@ -116,6 +141,38 @@ export const QueryCollectionRequestBody$outboundSchema: z.ZodType<
|
|
|
116
141
|
partitionFilter: models.PartitionFilter$outboundSchema.optional(),
|
|
117
142
|
ref: models.ReadRef$schema.optional(),
|
|
118
143
|
}).strict().superRefine((value, context) => {
|
|
144
|
+
if (value.rerank != null) {
|
|
145
|
+
const size = value.size ?? 10;
|
|
146
|
+
const candidateSize = value.rerank.candidateSize ?? Math.max(50, size);
|
|
147
|
+
if (size < 1 || size > 100 || candidateSize < size) {
|
|
148
|
+
context.addIssue({
|
|
149
|
+
code: z.ZodIssueCode.custom,
|
|
150
|
+
message: "rerank requires 1 <= size <= candidateSize <= 100",
|
|
151
|
+
path: ["rerank", "candidateSize"],
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (value.sort !== undefined) {
|
|
155
|
+
context.addIssue({
|
|
156
|
+
code: z.ZodIssueCode.custom,
|
|
157
|
+
message: "rerank cannot be combined with sort",
|
|
158
|
+
path: ["sort"],
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (!hasRerankScoringQuery(value.query)) {
|
|
162
|
+
context.addIssue({
|
|
163
|
+
code: z.ZodIssueCode.custom,
|
|
164
|
+
message: "rerank requires a scoring retrieval query",
|
|
165
|
+
path: ["query"],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (value.size === 0 && Object.keys(value.facets ?? {}).length === 0) {
|
|
170
|
+
context.addIssue({
|
|
171
|
+
code: z.ZodIssueCode.custom,
|
|
172
|
+
message: "size: 0 requires at least one facet",
|
|
173
|
+
path: ["facets"],
|
|
174
|
+
});
|
|
175
|
+
}
|
|
119
176
|
if (value.consistentRead && value.ref != null && value.ref.kind !== "branch") {
|
|
120
177
|
context.addIssue({
|
|
121
178
|
code: z.ZodIssueCode.custom,
|
|
@@ -169,6 +226,7 @@ export const QueryCollectionDoc$inboundSchema: z.ZodType<
|
|
|
169
226
|
> = z.object({
|
|
170
227
|
collection: z.string(),
|
|
171
228
|
score: nullToUndefined(z.number().optional()),
|
|
229
|
+
retrievalScore: nullToUndefined(z.number().optional()),
|
|
172
230
|
doc: z.record(z.any()),
|
|
173
231
|
});
|
|
174
232
|
|
|
@@ -188,12 +246,16 @@ export const QueryCollectionResponse$inboundSchema: z.ZodType<
|
|
|
188
246
|
z.ZodTypeDef,
|
|
189
247
|
unknown
|
|
190
248
|
> = z.object({
|
|
249
|
+
rerank: nullToUndefined(models.RerankResponse$inboundSchema.optional()),
|
|
191
250
|
took: z.number().int(),
|
|
192
251
|
maxScore: nullToUndefined(z.number().optional()),
|
|
193
252
|
total: z.number().int(),
|
|
194
253
|
docs: z.array(z.lazy(() => QueryCollectionDoc$inboundSchema)),
|
|
195
254
|
isDocsInline: z.boolean(),
|
|
196
255
|
docsUrl: nullToUndefined(z.string().optional()),
|
|
256
|
+
facets: nullToUndefined(z.record(z.object({
|
|
257
|
+
buckets: z.array(z.object({ value: z.string(), count: z.number().int() })),
|
|
258
|
+
})).optional()),
|
|
197
259
|
});
|
|
198
260
|
|
|
199
261
|
export function queryCollectionResponseFromJSON(
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Managed reranking DTOs, maintained manually following docs/OPENAPI_UPDATE.md. */
|
|
2
|
+
import * as z from "zod/v3";
|
|
3
|
+
import { nullToUndefined } from "../lib/schemas.js";
|
|
4
|
+
|
|
5
|
+
/** Per-query fixed managed model; credentials are managed by the server. */
|
|
6
|
+
export type RerankConfig = {
|
|
7
|
+
provider: "typesafe";
|
|
8
|
+
model: "jev-1.13.0";
|
|
9
|
+
/** Nonblank text, at most 8 KiB UTF-8; sent unchanged. */
|
|
10
|
+
queryText: string;
|
|
11
|
+
/** 1–8 unique stored scalar text paths, in model input order. */
|
|
12
|
+
fields: string[];
|
|
13
|
+
/** Defaults on the server to max(50, size); does not change knn.k. */
|
|
14
|
+
candidateSize?: number | null | undefined;
|
|
15
|
+
/** Server default: error. Only eligible provider failures can returnOriginal. */
|
|
16
|
+
onFailure?: "error" | "returnOriginal" | null | undefined;
|
|
17
|
+
/** 2–10 distinct nonblank descriptions, lowest to highest relevance; null uses defaults. */
|
|
18
|
+
criteria?: string[] | null | undefined;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type RerankResponse = {
|
|
22
|
+
status: "applied" | "skipped" | "fallback";
|
|
23
|
+
provider: string;
|
|
24
|
+
model: string;
|
|
25
|
+
resolvedModel?: string | undefined;
|
|
26
|
+
candidateCount: number;
|
|
27
|
+
scoredCount: number;
|
|
28
|
+
/** Rerank stage duration in milliseconds. */
|
|
29
|
+
took: number;
|
|
30
|
+
/** Only applied results report this marker; custom is not a content identity. */
|
|
31
|
+
criteriaVersion?: "default-relevance-v1" | "custom" | undefined;
|
|
32
|
+
reason?: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Match Java String.isBlank; do not trim or normalize caller text.
|
|
36
|
+
// eslint-disable-next-line no-control-regex -- Java whitespace includes these control characters.
|
|
37
|
+
const blank = /^[\u0009-\u000d\u001c-\u0020\u1680\u2000-\u2006\u2008-\u200a\u2028\u2029\u205f\u3000]*$/u;
|
|
38
|
+
const nonblank = z.string().refine((text) => !blank.test(text), "Must be nonblank");
|
|
39
|
+
const bytes = (text: string) => new TextEncoder().encode(text).length;
|
|
40
|
+
|
|
41
|
+
/** @internal */
|
|
42
|
+
export const RerankConfig$outboundSchema: z.ZodType<RerankConfig> = z.object({
|
|
43
|
+
provider: z.literal("typesafe"),
|
|
44
|
+
model: z.literal("jev-1.13.0"),
|
|
45
|
+
queryText: nonblank.refine((text) => bytes(text) <= 8192, "queryText exceeds 8 KiB UTF-8"),
|
|
46
|
+
fields: z.array(nonblank.refine(
|
|
47
|
+
(path) => path.split(".").every((part) => !blank.test(part)), "Invalid field path",
|
|
48
|
+
)).min(1).max(8).refine((paths) => new Set(paths).size === paths.length, "Fields must be unique"),
|
|
49
|
+
candidateSize: z.number().int().min(1).max(100).nullable().optional(),
|
|
50
|
+
onFailure: z.enum(["error", "returnOriginal"]).nullable().optional(),
|
|
51
|
+
criteria: z.array(nonblank.refine(
|
|
52
|
+
(text) => bytes(text) <= 2048, "Criterion exceeds 2 KiB UTF-8",
|
|
53
|
+
)).min(2).max(10).refine(
|
|
54
|
+
(texts) => new Set(texts).size === texts.length, "Criteria must be distinct",
|
|
55
|
+
).refine(
|
|
56
|
+
(texts) => texts.reduce((total, text) => total + bytes(text), 0) <= 8192,
|
|
57
|
+
"Criteria exceed 8 KiB total UTF-8",
|
|
58
|
+
).nullable().optional(),
|
|
59
|
+
}).strict();
|
|
60
|
+
|
|
61
|
+
/** @internal */
|
|
62
|
+
export const RerankResponse$inboundSchema: z.ZodType<RerankResponse, z.ZodTypeDef, unknown> = z.object({
|
|
63
|
+
status: z.enum(["applied", "skipped", "fallback"]),
|
|
64
|
+
provider: z.string(),
|
|
65
|
+
model: z.string(),
|
|
66
|
+
resolvedModel: nullToUndefined(z.string().optional()),
|
|
67
|
+
candidateCount: z.number().int().nonnegative(),
|
|
68
|
+
scoredCount: z.number().int().nonnegative(),
|
|
69
|
+
took: z.number().int().nonnegative(),
|
|
70
|
+
criteriaVersion: nullToUndefined(z.enum(["default-relevance-v1", "custom"]).optional()),
|
|
71
|
+
reason: nullToUndefined(z.string().optional()),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/** @internal: mirrors ManagedRerankService.hasScoringQuery for the existing wire DSL. */
|
|
75
|
+
export function hasRerankScoringQuery(query: unknown): boolean {
|
|
76
|
+
if (query == null || typeof query !== "object" || Array.isArray(query)) return false;
|
|
77
|
+
const node = query as Record<string, unknown>;
|
|
78
|
+
const occur = typeof node["occur"] === "string" ? node["occur"].toUpperCase() : undefined;
|
|
79
|
+
if (occur === "FILTER" || occur === "MUST_NOT") return false;
|
|
80
|
+
// Follow backend parser precedence for composite queries.
|
|
81
|
+
for (const key of ["bool", "rrf", "mm", "l2"]) {
|
|
82
|
+
// Undefined members are omitted by JSON serialization.
|
|
83
|
+
if (node[key] !== undefined) {
|
|
84
|
+
const children = node[key];
|
|
85
|
+
return Array.isArray(children) && children.some(hasRerankScoringQuery);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return ["queryString", "sparseVector", "knn"].some((key) => node[key] != null);
|
|
89
|
+
}
|
package/src/types/public.ts
CHANGED
|
@@ -273,3 +273,7 @@ export function tagDetailsWithDates(details: TagDetailsModel): TagDetails {
|
|
|
273
273
|
export function aliasDetailsWithDate(details: AliasDetailsModel): AliasDetails {
|
|
274
274
|
return { ...details, createdAt: new Date(details.createdAt) };
|
|
275
275
|
}
|
|
276
|
+
|
|
277
|
+
export type { FacetRequest, FacetBucket, FacetResult } from "../models/operations/querycollection.js";
|
|
278
|
+
|
|
279
|
+
export type { RerankConfig, RerankResponse } from "../models/rerank.js";
|