@samesake/core 1.0.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 +9 -0
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/index.cjs +243 -0
- package/dist/index.d.cts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +206 -0
- package/dist/schemas.cjs +80 -0
- package/dist/schemas.d.cts +77 -0
- package/dist/schemas.d.ts +77 -0
- package/dist/schemas.js +50 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +316 -0
- package/dist/types.d.ts +316 -0
- package/dist/types.js +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 octalpixel
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @samesake/core
|
|
2
|
+
|
|
3
|
+
Config-as-code DSL for commerce search and entity resolution. Declare `collection()` and `entity()` with compile-time validation.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun add @samesake/core
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
See the [samesake README](https://github.com/asyncdotengineering/samesake#readme) for setup, examples, and docs.
|
|
File without changes
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Channels: () => Channels,
|
|
24
|
+
IdentError: () => IdentError,
|
|
25
|
+
Scorers: () => Scorers,
|
|
26
|
+
assertIdent: () => assertIdent,
|
|
27
|
+
assertNoIdentCollisions: () => assertNoIdentCollisions,
|
|
28
|
+
collection: () => collection,
|
|
29
|
+
entity: () => entity,
|
|
30
|
+
f: () => f,
|
|
31
|
+
fields: () => fields,
|
|
32
|
+
pipeline: () => pipeline,
|
|
33
|
+
s: () => s,
|
|
34
|
+
sources: () => sources,
|
|
35
|
+
stage: () => stage
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/ident.ts
|
|
40
|
+
var IDENT_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
41
|
+
var IDENT_MAX = 63;
|
|
42
|
+
var IdentError = class extends Error {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = "IdentError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
function assertIdent(name, kind) {
|
|
49
|
+
if (name.length > IDENT_MAX) {
|
|
50
|
+
throw new IdentError(
|
|
51
|
+
`${kind} name "${name}" exceeds max length ${IDENT_MAX}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (!IDENT_RE.test(name)) {
|
|
55
|
+
throw new IdentError(
|
|
56
|
+
`${kind} name "${name}" is invalid: use letters, digits, underscores; must start with a letter (no hyphens)`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function assertNoIdentCollisions(names, kind) {
|
|
61
|
+
const seen = /* @__PURE__ */ new Map();
|
|
62
|
+
for (const name of names) {
|
|
63
|
+
const key = name.toLowerCase();
|
|
64
|
+
const prev = seen.get(key);
|
|
65
|
+
if (prev && prev !== name) {
|
|
66
|
+
throw new IdentError(
|
|
67
|
+
`${kind} names "${prev}" and "${name}" collide (case-insensitive)`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
seen.set(key, name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/index.ts
|
|
75
|
+
var fields = {
|
|
76
|
+
text(opts = {}) {
|
|
77
|
+
return { type: "text", ...opts };
|
|
78
|
+
},
|
|
79
|
+
number(opts = {}) {
|
|
80
|
+
return { type: "number", ...opts };
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var Scorers = {
|
|
84
|
+
cosine(opts) {
|
|
85
|
+
return { kind: "cosine", ...opts };
|
|
86
|
+
},
|
|
87
|
+
trigram(opts) {
|
|
88
|
+
return { kind: "trigram", ...opts };
|
|
89
|
+
},
|
|
90
|
+
phoneticEq(opts) {
|
|
91
|
+
return { kind: "phoneticEq", ...opts };
|
|
92
|
+
},
|
|
93
|
+
phoneExact(opts) {
|
|
94
|
+
return { kind: "phoneExact", ...opts };
|
|
95
|
+
},
|
|
96
|
+
aliasHit(opts) {
|
|
97
|
+
return { kind: "aliasHit", ...opts };
|
|
98
|
+
},
|
|
99
|
+
internalCodeExact(opts) {
|
|
100
|
+
return { kind: "internalCodeExact", ...opts };
|
|
101
|
+
},
|
|
102
|
+
sizeUnitGate(opts) {
|
|
103
|
+
return { kind: "sizeUnitGate", ...opts };
|
|
104
|
+
},
|
|
105
|
+
brandGate(opts) {
|
|
106
|
+
return { kind: "brandGate", ...opts };
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function entity(name, def) {
|
|
110
|
+
assertIdent(name, "entity");
|
|
111
|
+
for (const s2 of def.scopes ?? []) assertIdent(s2, "scope");
|
|
112
|
+
assertNoIdentCollisions(Object.keys(def.fields ?? {}), "field");
|
|
113
|
+
return { ...def, name };
|
|
114
|
+
}
|
|
115
|
+
var f = {
|
|
116
|
+
text(opts = {}) {
|
|
117
|
+
return { type: "text", ...opts };
|
|
118
|
+
},
|
|
119
|
+
number(opts = {}) {
|
|
120
|
+
return { type: "number", ...opts };
|
|
121
|
+
},
|
|
122
|
+
boolean(opts = {}) {
|
|
123
|
+
return { type: "boolean", ...opts };
|
|
124
|
+
},
|
|
125
|
+
enum(values, opts = {}) {
|
|
126
|
+
return { type: "enum", values, ...opts };
|
|
127
|
+
},
|
|
128
|
+
array(item, opts = {}) {
|
|
129
|
+
if (item.type === "enum") {
|
|
130
|
+
return { type: "array", itemType: "enum", values: item.values, ...opts };
|
|
131
|
+
}
|
|
132
|
+
return { type: "array", itemType: "text", ...opts };
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var Channels = {
|
|
136
|
+
fts(opts) {
|
|
137
|
+
return { kind: "fts", ...opts };
|
|
138
|
+
},
|
|
139
|
+
cosine(opts) {
|
|
140
|
+
return { kind: "cosine", ...opts };
|
|
141
|
+
},
|
|
142
|
+
recency(opts) {
|
|
143
|
+
return { kind: "recency", ...opts };
|
|
144
|
+
},
|
|
145
|
+
spaces(opts) {
|
|
146
|
+
return { kind: "spaces", ...opts };
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var PGVECTOR_HNSW_MAX_DIMS = 2e3;
|
|
150
|
+
function spaceDim(def) {
|
|
151
|
+
return def.kind === "text" || def.kind === "image" ? def.dim : def.dims;
|
|
152
|
+
}
|
|
153
|
+
function validateSpaceDims(spaces) {
|
|
154
|
+
let total = 0;
|
|
155
|
+
for (const def of Object.values(spaces)) {
|
|
156
|
+
total += spaceDim(def);
|
|
157
|
+
}
|
|
158
|
+
if (total > PGVECTOR_HNSW_MAX_DIMS) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`spaces total dimension ${total} exceeds pgvector HNSW limit of ${PGVECTOR_HNSW_MAX_DIMS} for vector columns. Reduce space dims or split spaces across collections. Future escape hatch: halfvec (up to 4000 dims).`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
var s = {
|
|
165
|
+
text(opts) {
|
|
166
|
+
return { kind: "text", ...opts };
|
|
167
|
+
},
|
|
168
|
+
image(opts) {
|
|
169
|
+
return { kind: "image", ...opts };
|
|
170
|
+
},
|
|
171
|
+
number(opts) {
|
|
172
|
+
return { kind: "number", ...opts };
|
|
173
|
+
},
|
|
174
|
+
recency(opts) {
|
|
175
|
+
return { kind: "recency", ...opts };
|
|
176
|
+
},
|
|
177
|
+
categorical(opts) {
|
|
178
|
+
return { kind: "categorical", ...opts };
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
function collection(name, def) {
|
|
182
|
+
assertIdent(name, "collection");
|
|
183
|
+
assertNoIdentCollisions(Object.keys(def.fields ?? {}), "field");
|
|
184
|
+
if (def.spaces) assertNoIdentCollisions(Object.keys(def.spaces), "space");
|
|
185
|
+
if (def.embeddings) assertNoIdentCollisions(Object.keys(def.embeddings), "embedding");
|
|
186
|
+
if (def.spaces && Object.keys(def.spaces).length > 0) {
|
|
187
|
+
validateSpaceDims(def.spaces);
|
|
188
|
+
}
|
|
189
|
+
return { ...def, name };
|
|
190
|
+
}
|
|
191
|
+
function stage(name, def) {
|
|
192
|
+
return { name, ...def };
|
|
193
|
+
}
|
|
194
|
+
function pipeline(...stages) {
|
|
195
|
+
return { stages };
|
|
196
|
+
}
|
|
197
|
+
var sources = {
|
|
198
|
+
shopifyFeed(opts) {
|
|
199
|
+
return {
|
|
200
|
+
name: opts.name ?? `shopify:${opts.domain}`,
|
|
201
|
+
kind: "shopify",
|
|
202
|
+
options: {
|
|
203
|
+
domain: opts.domain,
|
|
204
|
+
currency: opts.currency ?? "LKR",
|
|
205
|
+
maxPages: opts.maxPages ?? 8
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
wooStoreFeed(opts) {
|
|
210
|
+
return {
|
|
211
|
+
name: opts.name ?? `woo:${opts.domain}`,
|
|
212
|
+
kind: "woocommerce",
|
|
213
|
+
options: {
|
|
214
|
+
domain: opts.domain,
|
|
215
|
+
currency: opts.currency ?? "LKR",
|
|
216
|
+
maxPages: opts.maxPages ?? 8
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
jsonl(opts) {
|
|
221
|
+
return {
|
|
222
|
+
name: opts.name ?? `jsonl:${opts.path}`,
|
|
223
|
+
kind: "jsonl",
|
|
224
|
+
options: { path: opts.path }
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
+
0 && (module.exports = {
|
|
230
|
+
Channels,
|
|
231
|
+
IdentError,
|
|
232
|
+
Scorers,
|
|
233
|
+
assertIdent,
|
|
234
|
+
assertNoIdentCollisions,
|
|
235
|
+
collection,
|
|
236
|
+
entity,
|
|
237
|
+
f,
|
|
238
|
+
fields,
|
|
239
|
+
pipeline,
|
|
240
|
+
s,
|
|
241
|
+
sources,
|
|
242
|
+
stage
|
|
243
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { FtsChannel, CosineChannel, RecencyChannel, SpacesChannel, CosineScorer, TrigramScorer, PhoneticEqScorer, PhoneExactScorer, AliasHitScorer, InternalCodeExactScorer, SizeUnitGateScorer, BrandGateScorer, CollectionFieldDef, CollectionEmbeddingDef, SpaceDef, PipelineDef, ConnectorDef, TypedSearchChannel, CollectionDef, FieldDef, EmbeddingDef, PhoneticDef, ParseDef, TypedScorer, EntityDef, CollectionTextFieldDef, CollectionNumberFieldDef, CollectionBooleanFieldDef, CollectionEnumFieldDef, CollectionArrayFieldDef, StageDef, TextSpaceDef, ImageSpaceDef, NumberSpaceDef, RecencySpaceDef, CategoricalSpaceDef } from './types.cjs';
|
|
2
|
+
export { CollectionSearchDef, ProjectConfig, ScorerDef, ScoringDef, SearchChannelDef, SearchWeightsInput, StageContext } from './types.cjs';
|
|
3
|
+
export { MatchCandidate, MatchComponents, MatchResult, ResolvedMatch } from './schemas.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
declare class IdentError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
declare function assertIdent(name: string, kind: string): void;
|
|
10
|
+
declare function assertNoIdentCollisions(names: readonly string[], kind: string): void;
|
|
11
|
+
|
|
12
|
+
declare const fields: {
|
|
13
|
+
readonly text: (opts?: {
|
|
14
|
+
required?: boolean;
|
|
15
|
+
optional?: boolean;
|
|
16
|
+
maxLength?: number;
|
|
17
|
+
}) => FieldDef;
|
|
18
|
+
readonly number: (opts?: {
|
|
19
|
+
required?: boolean;
|
|
20
|
+
optional?: boolean;
|
|
21
|
+
}) => FieldDef;
|
|
22
|
+
};
|
|
23
|
+
declare const Scorers: {
|
|
24
|
+
readonly cosine: <const E extends string>(opts: {
|
|
25
|
+
embedding: E;
|
|
26
|
+
weight: number;
|
|
27
|
+
}) => CosineScorer<E>;
|
|
28
|
+
readonly trigram: <const F extends string>(opts: {
|
|
29
|
+
field: F;
|
|
30
|
+
weight: number;
|
|
31
|
+
latinOnlyPartial?: boolean;
|
|
32
|
+
}) => TrigramScorer<F>;
|
|
33
|
+
readonly phoneticEq: <const P extends string>(opts: {
|
|
34
|
+
phonetic: P;
|
|
35
|
+
weight: number;
|
|
36
|
+
}) => PhoneticEqScorer<P>;
|
|
37
|
+
readonly phoneExact: <const F extends string>(opts: {
|
|
38
|
+
field: F;
|
|
39
|
+
weight: number;
|
|
40
|
+
}) => PhoneExactScorer<F>;
|
|
41
|
+
readonly aliasHit: (opts: {
|
|
42
|
+
weight: number;
|
|
43
|
+
}) => AliasHitScorer;
|
|
44
|
+
readonly internalCodeExact: (opts: {
|
|
45
|
+
field: string;
|
|
46
|
+
shortCircuit?: boolean;
|
|
47
|
+
}) => InternalCodeExactScorer;
|
|
48
|
+
readonly sizeUnitGate: (opts: {
|
|
49
|
+
value: string;
|
|
50
|
+
unit: string;
|
|
51
|
+
}) => SizeUnitGateScorer;
|
|
52
|
+
readonly brandGate: (opts: {
|
|
53
|
+
field: string;
|
|
54
|
+
matchBoost?: number;
|
|
55
|
+
mismatchFactor?: number;
|
|
56
|
+
}) => BrandGateScorer;
|
|
57
|
+
};
|
|
58
|
+
type EntityInput<TFields extends Record<string, FieldDef>, TScopes extends readonly string[], TEmbeddings extends Record<string, EmbeddingDef>, TPhonetic extends Record<string, PhoneticDef>> = {
|
|
59
|
+
fields: TFields;
|
|
60
|
+
scopes: TScopes;
|
|
61
|
+
embeddings?: TEmbeddings;
|
|
62
|
+
phonetic?: TPhonetic;
|
|
63
|
+
parse?: ParseDef;
|
|
64
|
+
scoring?: {
|
|
65
|
+
channels: ReadonlyArray<TypedScorer<NoInfer<keyof TFields & string>, NoInfer<keyof TEmbeddings & string>, NoInfer<keyof TPhonetic & string>>>;
|
|
66
|
+
combiner?: "probabilistic-or" | "rrf" | "fellegi-sunter";
|
|
67
|
+
thresholds?: {
|
|
68
|
+
autoLink?: number;
|
|
69
|
+
suggest?: number;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
declare function entity<const TFields extends Record<string, FieldDef>, const TScopes extends readonly string[], const TEmbeddings extends Record<string, EmbeddingDef> = Record<string, never>, const TPhonetic extends Record<string, PhoneticDef> = Record<string, never>>(name: string, def: EntityInput<TFields, TScopes, TEmbeddings, TPhonetic>): EntityDef & {
|
|
74
|
+
name: string;
|
|
75
|
+
};
|
|
76
|
+
declare const f: {
|
|
77
|
+
readonly text: (opts?: Omit<CollectionTextFieldDef, "type">) => CollectionTextFieldDef;
|
|
78
|
+
readonly number: (opts?: Omit<CollectionNumberFieldDef, "type">) => CollectionNumberFieldDef;
|
|
79
|
+
readonly boolean: (opts?: Omit<CollectionBooleanFieldDef, "type">) => CollectionBooleanFieldDef;
|
|
80
|
+
readonly enum: <const T extends readonly string[]>(values: T, opts?: Omit<CollectionEnumFieldDef, "type" | "values">) => CollectionEnumFieldDef;
|
|
81
|
+
readonly array: (item: CollectionEnumFieldDef | {
|
|
82
|
+
type: "text";
|
|
83
|
+
}, opts?: Omit<CollectionArrayFieldDef, "type" | "itemType" | "values">) => CollectionArrayFieldDef;
|
|
84
|
+
};
|
|
85
|
+
declare const Channels: {
|
|
86
|
+
readonly fts: <const F extends string>(opts: {
|
|
87
|
+
fields: readonly F[];
|
|
88
|
+
weight: number;
|
|
89
|
+
}) => FtsChannel<F>;
|
|
90
|
+
readonly cosine: <const E extends string>(opts: {
|
|
91
|
+
embedding: E;
|
|
92
|
+
weight: number;
|
|
93
|
+
}) => CosineChannel<E>;
|
|
94
|
+
readonly recency: <const F extends string>(opts: {
|
|
95
|
+
field: F;
|
|
96
|
+
halfLifeDays: number;
|
|
97
|
+
weight: number;
|
|
98
|
+
}) => RecencyChannel<F>;
|
|
99
|
+
readonly spaces: (opts: {
|
|
100
|
+
weight: number;
|
|
101
|
+
}) => SpacesChannel;
|
|
102
|
+
};
|
|
103
|
+
declare const s: {
|
|
104
|
+
readonly text: (opts: Omit<TextSpaceDef, "kind">) => TextSpaceDef;
|
|
105
|
+
readonly image: (opts: Omit<ImageSpaceDef, "kind">) => ImageSpaceDef;
|
|
106
|
+
readonly number: (opts: Omit<NumberSpaceDef, "kind">) => NumberSpaceDef;
|
|
107
|
+
readonly recency: (opts: Omit<RecencySpaceDef, "kind">) => RecencySpaceDef;
|
|
108
|
+
readonly categorical: (opts: Omit<CategoricalSpaceDef, "kind">) => CategoricalSpaceDef;
|
|
109
|
+
};
|
|
110
|
+
type CollectionInput<TFields extends Record<string, CollectionFieldDef>, TEmbeddings extends Record<string, CollectionEmbeddingDef>, TSpaces extends Record<string, SpaceDef> = Record<string, never>> = {
|
|
111
|
+
fields: TFields;
|
|
112
|
+
enrich?: PipelineDef;
|
|
113
|
+
sources?: ConnectorDef[];
|
|
114
|
+
embeddings?: TEmbeddings;
|
|
115
|
+
spaces?: TSpaces;
|
|
116
|
+
search?: {
|
|
117
|
+
channels: ReadonlyArray<TypedSearchChannel<NoInfer<keyof TFields & string>, NoInfer<keyof TEmbeddings & string>>>;
|
|
118
|
+
combiner?: "rrf";
|
|
119
|
+
defaultSpaceWeights?: Partial<Record<NoInfer<keyof TSpaces & string>, number>>;
|
|
120
|
+
nlq?: {
|
|
121
|
+
instructions?: string;
|
|
122
|
+
semanticRewrite?: boolean;
|
|
123
|
+
enable?: boolean;
|
|
124
|
+
schema?: Record<string, unknown>;
|
|
125
|
+
model?: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
declare function collection<const TFields extends Record<string, CollectionFieldDef>, const TEmbeddings extends Record<string, CollectionEmbeddingDef> = Record<string, never>, const TSpaces extends Record<string, SpaceDef> = Record<string, never>>(name: string, def: CollectionInput<TFields, TEmbeddings, TSpaces>): CollectionDef & {
|
|
130
|
+
name: string;
|
|
131
|
+
};
|
|
132
|
+
declare function stage(name: string, def: Omit<StageDef, "name">): StageDef;
|
|
133
|
+
declare function pipeline(...stages: StageDef[]): PipelineDef;
|
|
134
|
+
declare const sources: {
|
|
135
|
+
readonly shopifyFeed: (opts: {
|
|
136
|
+
domain: string;
|
|
137
|
+
currency?: string;
|
|
138
|
+
maxPages?: number;
|
|
139
|
+
name?: string;
|
|
140
|
+
}) => ConnectorDef;
|
|
141
|
+
readonly wooStoreFeed: (opts: {
|
|
142
|
+
domain: string;
|
|
143
|
+
currency?: string;
|
|
144
|
+
maxPages?: number;
|
|
145
|
+
name?: string;
|
|
146
|
+
}) => ConnectorDef;
|
|
147
|
+
readonly jsonl: (opts: {
|
|
148
|
+
path: string;
|
|
149
|
+
name?: string;
|
|
150
|
+
}) => ConnectorDef;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export { AliasHitScorer, BrandGateScorer, CategoricalSpaceDef, Channels, CollectionArrayFieldDef, CollectionBooleanFieldDef, CollectionDef, CollectionEmbeddingDef, CollectionEnumFieldDef, CollectionFieldDef, CollectionNumberFieldDef, CollectionTextFieldDef, ConnectorDef, CosineChannel, CosineScorer, EmbeddingDef, EntityDef, FieldDef, FtsChannel, IdentError, ImageSpaceDef, InternalCodeExactScorer, NumberSpaceDef, ParseDef, PhoneExactScorer, PhoneticDef, PhoneticEqScorer, PipelineDef, RecencyChannel, RecencySpaceDef, Scorers, SizeUnitGateScorer, SpaceDef, SpacesChannel, StageDef, TextSpaceDef, TrigramScorer, TypedScorer, TypedSearchChannel, assertIdent, assertNoIdentCollisions, collection, entity, f, fields, pipeline, s, sources, stage };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { FtsChannel, CosineChannel, RecencyChannel, SpacesChannel, CosineScorer, TrigramScorer, PhoneticEqScorer, PhoneExactScorer, AliasHitScorer, InternalCodeExactScorer, SizeUnitGateScorer, BrandGateScorer, CollectionFieldDef, CollectionEmbeddingDef, SpaceDef, PipelineDef, ConnectorDef, TypedSearchChannel, CollectionDef, FieldDef, EmbeddingDef, PhoneticDef, ParseDef, TypedScorer, EntityDef, CollectionTextFieldDef, CollectionNumberFieldDef, CollectionBooleanFieldDef, CollectionEnumFieldDef, CollectionArrayFieldDef, StageDef, TextSpaceDef, ImageSpaceDef, NumberSpaceDef, RecencySpaceDef, CategoricalSpaceDef } from './types.js';
|
|
2
|
+
export { CollectionSearchDef, ProjectConfig, ScorerDef, ScoringDef, SearchChannelDef, SearchWeightsInput, StageContext } from './types.js';
|
|
3
|
+
export { MatchCandidate, MatchComponents, MatchResult, ResolvedMatch } from './schemas.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
declare class IdentError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
declare function assertIdent(name: string, kind: string): void;
|
|
10
|
+
declare function assertNoIdentCollisions(names: readonly string[], kind: string): void;
|
|
11
|
+
|
|
12
|
+
declare const fields: {
|
|
13
|
+
readonly text: (opts?: {
|
|
14
|
+
required?: boolean;
|
|
15
|
+
optional?: boolean;
|
|
16
|
+
maxLength?: number;
|
|
17
|
+
}) => FieldDef;
|
|
18
|
+
readonly number: (opts?: {
|
|
19
|
+
required?: boolean;
|
|
20
|
+
optional?: boolean;
|
|
21
|
+
}) => FieldDef;
|
|
22
|
+
};
|
|
23
|
+
declare const Scorers: {
|
|
24
|
+
readonly cosine: <const E extends string>(opts: {
|
|
25
|
+
embedding: E;
|
|
26
|
+
weight: number;
|
|
27
|
+
}) => CosineScorer<E>;
|
|
28
|
+
readonly trigram: <const F extends string>(opts: {
|
|
29
|
+
field: F;
|
|
30
|
+
weight: number;
|
|
31
|
+
latinOnlyPartial?: boolean;
|
|
32
|
+
}) => TrigramScorer<F>;
|
|
33
|
+
readonly phoneticEq: <const P extends string>(opts: {
|
|
34
|
+
phonetic: P;
|
|
35
|
+
weight: number;
|
|
36
|
+
}) => PhoneticEqScorer<P>;
|
|
37
|
+
readonly phoneExact: <const F extends string>(opts: {
|
|
38
|
+
field: F;
|
|
39
|
+
weight: number;
|
|
40
|
+
}) => PhoneExactScorer<F>;
|
|
41
|
+
readonly aliasHit: (opts: {
|
|
42
|
+
weight: number;
|
|
43
|
+
}) => AliasHitScorer;
|
|
44
|
+
readonly internalCodeExact: (opts: {
|
|
45
|
+
field: string;
|
|
46
|
+
shortCircuit?: boolean;
|
|
47
|
+
}) => InternalCodeExactScorer;
|
|
48
|
+
readonly sizeUnitGate: (opts: {
|
|
49
|
+
value: string;
|
|
50
|
+
unit: string;
|
|
51
|
+
}) => SizeUnitGateScorer;
|
|
52
|
+
readonly brandGate: (opts: {
|
|
53
|
+
field: string;
|
|
54
|
+
matchBoost?: number;
|
|
55
|
+
mismatchFactor?: number;
|
|
56
|
+
}) => BrandGateScorer;
|
|
57
|
+
};
|
|
58
|
+
type EntityInput<TFields extends Record<string, FieldDef>, TScopes extends readonly string[], TEmbeddings extends Record<string, EmbeddingDef>, TPhonetic extends Record<string, PhoneticDef>> = {
|
|
59
|
+
fields: TFields;
|
|
60
|
+
scopes: TScopes;
|
|
61
|
+
embeddings?: TEmbeddings;
|
|
62
|
+
phonetic?: TPhonetic;
|
|
63
|
+
parse?: ParseDef;
|
|
64
|
+
scoring?: {
|
|
65
|
+
channels: ReadonlyArray<TypedScorer<NoInfer<keyof TFields & string>, NoInfer<keyof TEmbeddings & string>, NoInfer<keyof TPhonetic & string>>>;
|
|
66
|
+
combiner?: "probabilistic-or" | "rrf" | "fellegi-sunter";
|
|
67
|
+
thresholds?: {
|
|
68
|
+
autoLink?: number;
|
|
69
|
+
suggest?: number;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
declare function entity<const TFields extends Record<string, FieldDef>, const TScopes extends readonly string[], const TEmbeddings extends Record<string, EmbeddingDef> = Record<string, never>, const TPhonetic extends Record<string, PhoneticDef> = Record<string, never>>(name: string, def: EntityInput<TFields, TScopes, TEmbeddings, TPhonetic>): EntityDef & {
|
|
74
|
+
name: string;
|
|
75
|
+
};
|
|
76
|
+
declare const f: {
|
|
77
|
+
readonly text: (opts?: Omit<CollectionTextFieldDef, "type">) => CollectionTextFieldDef;
|
|
78
|
+
readonly number: (opts?: Omit<CollectionNumberFieldDef, "type">) => CollectionNumberFieldDef;
|
|
79
|
+
readonly boolean: (opts?: Omit<CollectionBooleanFieldDef, "type">) => CollectionBooleanFieldDef;
|
|
80
|
+
readonly enum: <const T extends readonly string[]>(values: T, opts?: Omit<CollectionEnumFieldDef, "type" | "values">) => CollectionEnumFieldDef;
|
|
81
|
+
readonly array: (item: CollectionEnumFieldDef | {
|
|
82
|
+
type: "text";
|
|
83
|
+
}, opts?: Omit<CollectionArrayFieldDef, "type" | "itemType" | "values">) => CollectionArrayFieldDef;
|
|
84
|
+
};
|
|
85
|
+
declare const Channels: {
|
|
86
|
+
readonly fts: <const F extends string>(opts: {
|
|
87
|
+
fields: readonly F[];
|
|
88
|
+
weight: number;
|
|
89
|
+
}) => FtsChannel<F>;
|
|
90
|
+
readonly cosine: <const E extends string>(opts: {
|
|
91
|
+
embedding: E;
|
|
92
|
+
weight: number;
|
|
93
|
+
}) => CosineChannel<E>;
|
|
94
|
+
readonly recency: <const F extends string>(opts: {
|
|
95
|
+
field: F;
|
|
96
|
+
halfLifeDays: number;
|
|
97
|
+
weight: number;
|
|
98
|
+
}) => RecencyChannel<F>;
|
|
99
|
+
readonly spaces: (opts: {
|
|
100
|
+
weight: number;
|
|
101
|
+
}) => SpacesChannel;
|
|
102
|
+
};
|
|
103
|
+
declare const s: {
|
|
104
|
+
readonly text: (opts: Omit<TextSpaceDef, "kind">) => TextSpaceDef;
|
|
105
|
+
readonly image: (opts: Omit<ImageSpaceDef, "kind">) => ImageSpaceDef;
|
|
106
|
+
readonly number: (opts: Omit<NumberSpaceDef, "kind">) => NumberSpaceDef;
|
|
107
|
+
readonly recency: (opts: Omit<RecencySpaceDef, "kind">) => RecencySpaceDef;
|
|
108
|
+
readonly categorical: (opts: Omit<CategoricalSpaceDef, "kind">) => CategoricalSpaceDef;
|
|
109
|
+
};
|
|
110
|
+
type CollectionInput<TFields extends Record<string, CollectionFieldDef>, TEmbeddings extends Record<string, CollectionEmbeddingDef>, TSpaces extends Record<string, SpaceDef> = Record<string, never>> = {
|
|
111
|
+
fields: TFields;
|
|
112
|
+
enrich?: PipelineDef;
|
|
113
|
+
sources?: ConnectorDef[];
|
|
114
|
+
embeddings?: TEmbeddings;
|
|
115
|
+
spaces?: TSpaces;
|
|
116
|
+
search?: {
|
|
117
|
+
channels: ReadonlyArray<TypedSearchChannel<NoInfer<keyof TFields & string>, NoInfer<keyof TEmbeddings & string>>>;
|
|
118
|
+
combiner?: "rrf";
|
|
119
|
+
defaultSpaceWeights?: Partial<Record<NoInfer<keyof TSpaces & string>, number>>;
|
|
120
|
+
nlq?: {
|
|
121
|
+
instructions?: string;
|
|
122
|
+
semanticRewrite?: boolean;
|
|
123
|
+
enable?: boolean;
|
|
124
|
+
schema?: Record<string, unknown>;
|
|
125
|
+
model?: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
declare function collection<const TFields extends Record<string, CollectionFieldDef>, const TEmbeddings extends Record<string, CollectionEmbeddingDef> = Record<string, never>, const TSpaces extends Record<string, SpaceDef> = Record<string, never>>(name: string, def: CollectionInput<TFields, TEmbeddings, TSpaces>): CollectionDef & {
|
|
130
|
+
name: string;
|
|
131
|
+
};
|
|
132
|
+
declare function stage(name: string, def: Omit<StageDef, "name">): StageDef;
|
|
133
|
+
declare function pipeline(...stages: StageDef[]): PipelineDef;
|
|
134
|
+
declare const sources: {
|
|
135
|
+
readonly shopifyFeed: (opts: {
|
|
136
|
+
domain: string;
|
|
137
|
+
currency?: string;
|
|
138
|
+
maxPages?: number;
|
|
139
|
+
name?: string;
|
|
140
|
+
}) => ConnectorDef;
|
|
141
|
+
readonly wooStoreFeed: (opts: {
|
|
142
|
+
domain: string;
|
|
143
|
+
currency?: string;
|
|
144
|
+
maxPages?: number;
|
|
145
|
+
name?: string;
|
|
146
|
+
}) => ConnectorDef;
|
|
147
|
+
readonly jsonl: (opts: {
|
|
148
|
+
path: string;
|
|
149
|
+
name?: string;
|
|
150
|
+
}) => ConnectorDef;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export { AliasHitScorer, BrandGateScorer, CategoricalSpaceDef, Channels, CollectionArrayFieldDef, CollectionBooleanFieldDef, CollectionDef, CollectionEmbeddingDef, CollectionEnumFieldDef, CollectionFieldDef, CollectionNumberFieldDef, CollectionTextFieldDef, ConnectorDef, CosineChannel, CosineScorer, EmbeddingDef, EntityDef, FieldDef, FtsChannel, IdentError, ImageSpaceDef, InternalCodeExactScorer, NumberSpaceDef, ParseDef, PhoneExactScorer, PhoneticDef, PhoneticEqScorer, PipelineDef, RecencyChannel, RecencySpaceDef, Scorers, SizeUnitGateScorer, SpaceDef, SpacesChannel, StageDef, TextSpaceDef, TrigramScorer, TypedScorer, TypedSearchChannel, assertIdent, assertNoIdentCollisions, collection, entity, f, fields, pipeline, s, sources, stage };
|