-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathutils.ts
More file actions
46 lines (38 loc) · 1.53 KB
/
utils.ts
File metadata and controls
46 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { MultiTargetVectorJoin } from '../index.js';
import { Bm25OperatorOptions, Bm25OperatorOr, NearVectorInputType, TargetVectorInputType } from './types.js';
export class NearVectorInputGuards {
public static is1DArray(input: NearVectorInputType): input is number[] {
return Array.isArray(input) && input.length > 0 && !Array.isArray(input[0]);
}
public static isObject(input: NearVectorInputType): input is Record<string, number[] | number[][]> {
return !Array.isArray(input);
}
}
export class ArrayInputGuards {
public static is1DArray<U, T extends U[]>(input: U | T): input is T {
return Array.isArray(input) && input.length > 0 && !Array.isArray(input[0]);
}
public static is2DArray<U, T extends U[]>(input: U | T): input is T {
return Array.isArray(input) && input.length > 0 && Array.isArray(input[0]);
}
}
export class TargetVectorInputGuards {
public static isSingle(input: TargetVectorInputType): input is string {
return typeof input === 'string';
}
public static isMulti(input: TargetVectorInputType): input is string[] {
return Array.isArray(input);
}
public static isMultiJoin(input: TargetVectorInputType): input is MultiTargetVectorJoin {
const i = input as MultiTargetVectorJoin;
return i.combination !== undefined && i.targetVectors !== undefined;
}
}
export class Bm25Operator {
static and(): Bm25OperatorOptions {
return { operator: 'And' };
}
static or(opts: Omit<Bm25OperatorOr, 'operator'>): Bm25OperatorOptions {
return { ...opts, operator: 'Or' };
}
}