Skip to content

Commit e3baef3

Browse files
committed
chore: lint and format
1 parent 9c64dfc commit e3baef3

File tree

4 files changed

+112
-100
lines changed

4 files changed

+112
-100
lines changed

src/collections/query/integration.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ describe('Testing of the collection.query methods with a simple collection', ()
134134
expect(ret.objects[0].uuid).toEqual(id);
135135
});
136136

137-
requireAtLeast(1, 31, 0)('bm25 search operator (minimum_should_match)', () => {
137+
requireAtLeast(
138+
1,
139+
31,
140+
0
141+
)('bm25 search operator (minimum_should_match)', () => {
138142
it('should query with bm25 + operator', async () => {
139143
const ret = await collection.query.bm25('carrot', {
140144
limit: 1,

src/collections/query/types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export type Bm25QueryProperty<T> = {
8787
export type Bm25OperatorOptions = {
8888
operator: 'And' | 'Or';
8989
minimumMatch: number;
90-
}
90+
};
9191

9292
export type Bm25SearchOptions<T> = {
9393
/** Which properties of the collection to perform the keyword search on. */
@@ -507,12 +507,12 @@ interface NearVector<T> {
507507
/** All the available methods on the `.query` namespace. */
508508
export interface Query<T>
509509
extends Bm25<T>,
510-
Hybrid<T>,
511-
NearImage<T>,
512-
NearMedia<T>,
513-
NearObject<T>,
514-
NearText<T>,
515-
NearVector<T> {
510+
Hybrid<T>,
511+
NearImage<T>,
512+
NearMedia<T>,
513+
NearObject<T>,
514+
NearText<T>,
515+
NearVector<T> {
516516
/**
517517
* Retrieve an object from the server by its UUID.
518518
*

src/collections/query/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ export class Bm25Operator {
4343
static or(opts: Omit<Bm25OperatorOptions, 'operator'>): Bm25OperatorOptions {
4444
return { ...opts, operator: 'Or' };
4545
}
46-
4746
}

src/collections/serialize/index.ts

Lines changed: 100 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ class Aggregate {
388388
text:
389389
metric.kind === 'text'
390390
? AggregateRequest_Aggregation_Text.fromPartial({
391-
count: metric.count,
392-
topOccurencesLimit: metric.minOccurrences,
393-
topOccurences: metric.topOccurrences != undefined,
394-
})
391+
count: metric.count,
392+
topOccurencesLimit: metric.minOccurrences,
393+
topOccurences: metric.topOccurrences != undefined,
394+
})
395395
: undefined,
396396
})
397397
);
@@ -525,27 +525,27 @@ class Search {
525525
returnAllNonrefProperties: nonRefProperties === undefined,
526526
refProperties: refProperties
527527
? refProperties.map((property) => {
528-
return {
529-
referenceProperty: property.linkOn,
530-
properties: Search.queryProperties(property.returnProperties as any),
531-
metadata: Search.metadata(property.includeVector, property.returnMetadata),
532-
targetCollection: property.targetCollection ? property.targetCollection : '',
533-
};
534-
})
528+
return {
529+
referenceProperty: property.linkOn,
530+
properties: Search.queryProperties(property.returnProperties as any),
531+
metadata: Search.metadata(property.includeVector, property.returnMetadata),
532+
targetCollection: property.targetCollection ? property.targetCollection : '',
533+
};
534+
})
535535
: [],
536536
objectProperties: objectProperties
537537
? objectProperties.map((property) => {
538-
const objProps = property.properties.filter(
539-
(property) => typeof property !== 'string'
540-
) as unknown; // cannot get types to work currently :(
541-
return {
542-
propName: property.name,
543-
primitiveProperties: property.properties.filter(
544-
(property) => typeof property === 'string'
545-
) as string[],
546-
objectProperties: (objProps as QueryNested<T>[]).map(resolveObjectProperty),
547-
};
548-
})
538+
const objProps = property.properties.filter(
539+
(property) => typeof property !== 'string'
540+
) as unknown; // cannot get types to work currently :(
541+
return {
542+
propName: property.name,
543+
primitiveProperties: property.properties.filter(
544+
(property) => typeof property === 'string'
545+
) as string[],
546+
objectProperties: (objProps as QueryNested<T>[]).map(resolveObjectProperty),
547+
};
548+
})
549549
: [],
550550
};
551551
};
@@ -917,30 +917,30 @@ export class Serialize {
917917

918918
return args.supportsSingleGrouped
919919
? GenerativeSearch.fromPartial({
920-
single: opts?.singlePrompt
921-
? GenerativeSearch_Single.fromPartial({
922-
prompt: singlePrompt,
923-
debug: singlePromptDebug,
924-
queries: opts.config ? [await Serialize.generativeQuery(opts.config, singleOpts)] : undefined,
925-
})
926-
: undefined,
927-
grouped: opts?.groupedTask
928-
? GenerativeSearch_Grouped.fromPartial({
929-
task: groupedTask,
930-
queries: opts.config
931-
? [await Serialize.generativeQuery(opts.config, groupedOpts)]
932-
: undefined,
933-
properties: groupedProperties
934-
? TextArray.fromPartial({ values: groupedProperties as string[] })
935-
: undefined,
936-
})
937-
: undefined,
938-
})
920+
single: opts?.singlePrompt
921+
? GenerativeSearch_Single.fromPartial({
922+
prompt: singlePrompt,
923+
debug: singlePromptDebug,
924+
queries: opts.config ? [await Serialize.generativeQuery(opts.config, singleOpts)] : undefined,
925+
})
926+
: undefined,
927+
grouped: opts?.groupedTask
928+
? GenerativeSearch_Grouped.fromPartial({
929+
task: groupedTask,
930+
queries: opts.config
931+
? [await Serialize.generativeQuery(opts.config, groupedOpts)]
932+
: undefined,
933+
properties: groupedProperties
934+
? TextArray.fromPartial({ values: groupedProperties as string[] })
935+
: undefined,
936+
})
937+
: undefined,
938+
})
939939
: GenerativeSearch.fromPartial({
940-
singleResponsePrompt: singlePrompt,
941-
groupedResponseTask: groupedTask,
942-
groupedProperties: groupedProperties as string[],
943-
});
940+
singleResponsePrompt: singlePrompt,
941+
groupedResponseTask: groupedTask,
942+
groupedProperties: groupedProperties as string[],
943+
});
944944
};
945945

946946
public static isSinglePrompt(arg?: string | SinglePrompt): arg is SinglePrompt {
@@ -963,14 +963,19 @@ export class Serialize {
963963
});
964964
};
965965

966-
private static bm25SearchOperator = (searchOperator?: Bm25OperatorOptions): SearchOperatorOptions | undefined => {
966+
private static bm25SearchOperator = (
967+
searchOperator?: Bm25OperatorOptions
968+
): SearchOperatorOptions | undefined => {
967969
if (searchOperator) {
968970
return SearchOperatorOptions.fromPartial({
969971
minimumOrTokensMatch: searchOperator.minimumMatch,
970-
operator: searchOperator.operator === 'And' as const ? SearchOperatorOptions_Operator.OPERATOR_AND : SearchOperatorOptions_Operator.OPERATOR_OR,
972+
operator:
973+
searchOperator.operator === ('And' as const)
974+
? SearchOperatorOptions_Operator.OPERATOR_AND
975+
: SearchOperatorOptions_Operator.OPERATOR_OR,
971976
});
972977
}
973-
}
978+
};
974979

975980
public static bm25Search = <T>(args: { query: string } & Bm25SearchOptions<T>): BM25 => {
976981
return BM25.fromPartial({
@@ -1018,13 +1023,13 @@ export class Serialize {
10181023
return vectorBytes !== undefined
10191024
? { vectorBytes, targetVectors, targets }
10201025
: {
1021-
targetVectors,
1022-
targets,
1023-
nearVector: NearVector.fromPartial({
1024-
vectorForTargets,
1025-
vectorPerTarget,
1026-
}),
1027-
};
1026+
targetVectors,
1027+
targets,
1028+
nearVector: NearVector.fromPartial({
1029+
vectorForTargets,
1030+
vectorPerTarget,
1031+
}),
1032+
};
10281033
} else if (Serialize.isHybridNearTextSearch(vector)) {
10291034
const { targetVectors, targets } = Serialize.targetVector(args);
10301035
return {
@@ -1081,7 +1086,11 @@ export class Serialize {
10811086
};
10821087
const { targets, targetVectors, vectorBytes, nearText, nearVector } = Serialize.hybridVector(args);
10831088

1084-
console.info(`search operator: ${JSON.stringify(SearchOperatorOptions.toJSON(this.bm25SearchOperator(args.bm25Operator)!))}`);
1089+
console.info(
1090+
`search operator: ${JSON.stringify(
1091+
SearchOperatorOptions.toJSON(this.bm25SearchOperator(args.bm25Operator)!)
1092+
)}`
1093+
);
10851094
return Hybrid.fromPartial({
10861095
query: args.query,
10871096
alpha: args.alpha ? args.alpha : 0.5,
@@ -1181,17 +1190,17 @@ export class Serialize {
11811190
targetVectors,
11821191
moveAway: args.moveAway
11831192
? NearTextSearch_Move.fromPartial({
1184-
concepts: args.moveAway.concepts,
1185-
force: args.moveAway.force,
1186-
uuids: args.moveAway.objects,
1187-
})
1193+
concepts: args.moveAway.concepts,
1194+
force: args.moveAway.force,
1195+
uuids: args.moveAway.objects,
1196+
})
11881197
: undefined,
11891198
moveTo: args.moveTo
11901199
? NearTextSearch_Move.fromPartial({
1191-
concepts: args.moveTo.concepts,
1192-
force: args.moveTo.force,
1193-
uuids: args.moveTo.objects,
1194-
})
1200+
concepts: args.moveTo.concepts,
1201+
force: args.moveTo.force,
1202+
uuids: args.moveTo.objects,
1203+
})
11951204
: undefined,
11961205
});
11971206
};
@@ -1247,18 +1256,18 @@ export class Serialize {
12471256
} else if (TargetVectorInputGuards.isSingle(args.targetVector)) {
12481257
return args.supportsTargets
12491258
? {
1250-
targets: Targets.fromPartial({
1251-
targetVectors: [args.targetVector],
1252-
}),
1253-
}
1259+
targets: Targets.fromPartial({
1260+
targetVectors: [args.targetVector],
1261+
}),
1262+
}
12541263
: { targetVectors: [args.targetVector] };
12551264
} else if (TargetVectorInputGuards.isMulti(args.targetVector)) {
12561265
return args.supportsTargets
12571266
? {
1258-
targets: Targets.fromPartial({
1259-
targetVectors: args.targetVector,
1260-
}),
1261-
}
1267+
targets: Targets.fromPartial({
1268+
targetVectors: args.targetVector,
1269+
}),
1270+
}
12621271
: { targetVectors: args.targetVector };
12631272
} else {
12641273
return { targets: Serialize.targets(args.targetVector, args.supportsWeightsForTargets) };
@@ -1303,22 +1312,22 @@ export class Serialize {
13031312
.reduce((acc, { target, vector }) => {
13041313
return ArrayInputGuards.is2DArray(vector)
13051314
? acc.concat(
1306-
vector.map((v) => ({ name: target, vectorBytes: Serialize.vectorToBytes(v), vectors: [] }))
1307-
)
1315+
vector.map((v) => ({ name: target, vectorBytes: Serialize.vectorToBytes(v), vectors: [] }))
1316+
)
13081317
: acc.concat([{ name: target, vectorBytes: Serialize.vectorToBytes(vector), vectors: [] }]);
13091318
}, [] as VectorForTarget[]);
13101319
return args.targetVector !== undefined
13111320
? {
1312-
...Serialize.targetVector(args),
1313-
vectorForTargets,
1314-
}
1321+
...Serialize.targetVector(args),
1322+
vectorForTargets,
1323+
}
13151324
: {
1316-
targetVectors: undefined,
1317-
targets: Targets.fromPartial({
1318-
targetVectors: vectorForTargets.map((v) => v.name),
1319-
}),
1320-
vectorForTargets,
1321-
};
1325+
targetVectors: undefined,
1326+
targets: Targets.fromPartial({
1327+
targetVectors: vectorForTargets.map((v) => v.name),
1328+
}),
1329+
vectorForTargets,
1330+
};
13221331
} else {
13231332
const vectorPerTarget: Record<string, Uint8Array> = {};
13241333
Object.entries(args.vector).forEach(([k, v]) => {
@@ -1337,15 +1346,15 @@ export class Serialize {
13371346
} else {
13381347
return args.supportsTargets
13391348
? {
1340-
targets: Targets.fromPartial({
1341-
targetVectors: Object.keys(vectorPerTarget),
1342-
}),
1343-
vectorPerTarget,
1344-
}
1349+
targets: Targets.fromPartial({
1350+
targetVectors: Object.keys(vectorPerTarget),
1351+
}),
1352+
vectorPerTarget,
1353+
}
13451354
: {
1346-
targetVectors: Object.keys(vectorPerTarget),
1347-
vectorPerTarget,
1348-
};
1355+
targetVectors: Object.keys(vectorPerTarget),
1356+
vectorPerTarget,
1357+
};
13491358
}
13501359
}
13511360
} else {

0 commit comments

Comments
 (0)