Skip to content

Commit d0b7f2b

Browse files
committed
Merge branch 'main' of https://github.com/weaviate/typescript-client into feat/backup-restore-rbac
2 parents 9a77ec6 + 6e4bcc5 commit d0b7f2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2630
-1058
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"abort-controller-x": "^0.4.3",
5555
"graphql": "^16.11.0",
5656
"graphql-request": "^6.1.0",
57-
"long": "^5.3.1",
57+
"long": "^5.3.2",
5858
"nice-grpc": "^2.1.12",
5959
"nice-grpc-client-middleware-retry": "^3.1.11",
6060
"nice-grpc-common": "^2.0.2",
@@ -100,7 +100,8 @@
100100
"lint-staged": {
101101
"*.{ts,js}": [
102102
"npm run format:check",
103-
"npm run lint -- --cache"
103+
"npm run lint -- --cache",
104+
"npm run prepack"
104105
]
105106
}
106107
}

src/collections/aggregate/index.ts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { WeaviateInvalidInputError, WeaviateQueryError } from '../../errors.js';
99
import { Aggregator } from '../../graphql/index.js';
1010
import { PrimitiveKeys, toBase64FromMedia } from '../../index.js';
1111
import { Deserialize } from '../deserialize/index.js';
12-
import { Bm25QueryProperty, NearVectorInputType } from '../query/types.js';
12+
import { Bm25QueryProperty, NearVectorInputType, TargetVector } from '../query/types.js';
1313
import { NearVectorInputGuards } from '../query/utils.js';
1414
import { Serialize } from '../serialize/index.js';
1515

@@ -31,27 +31,27 @@ export type GroupByAggregate<T> = {
3131

3232
export type AggregateOverAllOptions<M> = AggregateBaseOptions<M>;
3333

34-
export type AggregateNearOptions<M> = AggregateBaseOptions<M> & {
34+
export type AggregateNearOptions<M, V> = AggregateBaseOptions<M> & {
3535
certainty?: number;
3636
distance?: number;
3737
objectLimit?: number;
38-
targetVector?: string;
38+
targetVector?: TargetVector<V>;
3939
};
4040

41-
export type AggregateHybridOptions<T, M> = AggregateBaseOptions<M> & {
41+
export type AggregateHybridOptions<T, M, V> = AggregateBaseOptions<M> & {
4242
alpha?: number;
4343
maxVectorDistance?: number;
4444
objectLimit?: number;
4545
queryProperties?: (PrimitiveKeys<T> | Bm25QueryProperty<T>)[];
46-
targetVector?: string;
46+
targetVector?: TargetVector<V>;
4747
vector?: number[];
4848
};
4949

50-
export type AggregateGroupByHybridOptions<T, M> = AggregateHybridOptions<T, M> & {
50+
export type AggregateGroupByHybridOptions<T, M, V> = AggregateHybridOptions<T, M, V> & {
5151
groupBy: PropertyOf<T> | GroupByAggregate<T>;
5252
};
5353

54-
export type AggregateGroupByNearOptions<T, M> = AggregateNearOptions<M> & {
54+
export type AggregateGroupByNearOptions<T, M, V> = AggregateNearOptions<M, V> & {
5555
groupBy: PropertyOf<T> | GroupByAggregate<T>;
5656
};
5757

@@ -346,9 +346,9 @@ export type AggregateGroupByResult<
346346
};
347347
};
348348

349-
class AggregateManager<T> implements Aggregate<T> {
349+
class AggregateManager<T, V> implements Aggregate<T, V> {
350350
connection: Connection;
351-
groupBy: AggregateGroupBy<T>;
351+
groupBy: AggregateGroupBy<T, V>;
352352
name: string;
353353
dbVersionSupport: DbVersionSupport;
354354
consistencyLevel?: ConsistencyLevel;
@@ -373,14 +373,14 @@ class AggregateManager<T> implements Aggregate<T> {
373373
this.groupBy = {
374374
hybrid: async <M extends PropertiesMetrics<T>>(
375375
query: string,
376-
opts: AggregateGroupByHybridOptions<T, M>
376+
opts: AggregateGroupByHybridOptions<T, M, V>
377377
): Promise<AggregateGroupByResult<T, M>[]> => {
378378
if (await this.grpcChecker) {
379379
const group = typeof opts.groupBy === 'string' ? { property: opts.groupBy } : opts.groupBy;
380380
return this.grpc()
381-
.then((aggregate) =>
381+
.then(async (aggregate) =>
382382
aggregate.withHybrid({
383-
...Serialize.aggregate.hybrid(query, opts),
383+
...(await Serialize.aggregate.hybrid(query, opts)),
384384
groupBy: Serialize.aggregate.groupBy(group),
385385
limit: group.limit,
386386
})
@@ -402,7 +402,7 @@ class AggregateManager<T> implements Aggregate<T> {
402402
},
403403
nearImage: async <M extends PropertiesMetrics<T>>(
404404
image: string | Buffer,
405-
opts: AggregateGroupByNearOptions<T, M>
405+
opts: AggregateGroupByNearOptions<T, M, V>
406406
): Promise<AggregateGroupByResult<T, M>[]> => {
407407
const [b64, usesGrpc] = await Promise.all([await toBase64FromMedia(image), await this.grpcChecker]);
408408
if (usesGrpc) {
@@ -430,7 +430,7 @@ class AggregateManager<T> implements Aggregate<T> {
430430
},
431431
nearObject: async <M extends PropertiesMetrics<T>>(
432432
id: string,
433-
opts: AggregateGroupByNearOptions<T, M>
433+
opts: AggregateGroupByNearOptions<T, M, V>
434434
): Promise<AggregateGroupByResult<T, M>[]> => {
435435
if (await this.grpcChecker) {
436436
const group = typeof opts.groupBy === 'string' ? { property: opts.groupBy } : opts.groupBy;
@@ -457,7 +457,7 @@ class AggregateManager<T> implements Aggregate<T> {
457457
},
458458
nearText: async <M extends PropertiesMetrics<T>>(
459459
query: string | string[],
460-
opts: AggregateGroupByNearOptions<T, M>
460+
opts: AggregateGroupByNearOptions<T, M, V>
461461
): Promise<AggregateGroupByResult<T, M>[]> => {
462462
if (await this.grpcChecker) {
463463
const group = typeof opts.groupBy === 'string' ? { property: opts.groupBy } : opts.groupBy;
@@ -484,14 +484,14 @@ class AggregateManager<T> implements Aggregate<T> {
484484
},
485485
nearVector: async <M extends PropertiesMetrics<T>>(
486486
vector: number[],
487-
opts: AggregateGroupByNearOptions<T, M>
487+
opts: AggregateGroupByNearOptions<T, M, V>
488488
): Promise<AggregateGroupByResult<T, M>[]> => {
489489
if (await this.grpcChecker) {
490490
const group = typeof opts.groupBy === 'string' ? { property: opts.groupBy } : opts.groupBy;
491491
return this.grpc()
492-
.then((aggregate) =>
492+
.then(async (aggregate) =>
493493
aggregate.withNearVector({
494-
...Serialize.aggregate.nearVector(vector, opts),
494+
...(await Serialize.aggregate.nearVector(vector, opts)),
495495
groupBy: Serialize.aggregate.groupBy(group),
496496
limit: group.limit,
497497
})
@@ -593,23 +593,23 @@ class AggregateManager<T> implements Aggregate<T> {
593593
return `${propertyName} { ${body} }`;
594594
}
595595

596-
static use<T>(
596+
static use<T, V>(
597597
connection: Connection,
598598
name: string,
599599
dbVersionSupport: DbVersionSupport,
600600
consistencyLevel?: ConsistencyLevel,
601601
tenant?: string
602-
): AggregateManager<T> {
603-
return new AggregateManager<T>(connection, name, dbVersionSupport, consistencyLevel, tenant);
602+
): AggregateManager<T, V> {
603+
return new AggregateManager<T, V>(connection, name, dbVersionSupport, consistencyLevel, tenant);
604604
}
605605

606606
async hybrid<M extends PropertiesMetrics<T>>(
607607
query: string,
608-
opts?: AggregateHybridOptions<T, M>
608+
opts?: AggregateHybridOptions<T, M, V>
609609
): Promise<AggregateResult<T, M>> {
610610
if (await this.grpcChecker) {
611611
return this.grpc()
612-
.then((aggregate) => aggregate.withHybrid(Serialize.aggregate.hybrid(query, opts)))
612+
.then(async (aggregate) => aggregate.withHybrid(await Serialize.aggregate.hybrid(query, opts)))
613613
.then((reply) => Deserialize.aggregate(reply));
614614
}
615615
let builder = this.base(opts?.returnMetrics, opts?.filters).withHybrid({
@@ -628,7 +628,7 @@ class AggregateManager<T> implements Aggregate<T> {
628628

629629
async nearImage<M extends PropertiesMetrics<T>>(
630630
image: string | Buffer,
631-
opts?: AggregateNearOptions<M>
631+
opts?: AggregateNearOptions<M, V>
632632
): Promise<AggregateResult<T, M>> {
633633
const [b64, usesGrpc] = await Promise.all([await toBase64FromMedia(image), await this.grpcChecker]);
634634
if (usesGrpc) {
@@ -650,7 +650,7 @@ class AggregateManager<T> implements Aggregate<T> {
650650

651651
async nearObject<M extends PropertiesMetrics<T>>(
652652
id: string,
653-
opts?: AggregateNearOptions<M>
653+
opts?: AggregateNearOptions<M, V>
654654
): Promise<AggregateResult<T, M>> {
655655
if (await this.grpcChecker) {
656656
return this.grpc()
@@ -671,7 +671,7 @@ class AggregateManager<T> implements Aggregate<T> {
671671

672672
async nearText<M extends PropertiesMetrics<T>>(
673673
query: string | string[],
674-
opts?: AggregateNearOptions<M>
674+
opts?: AggregateNearOptions<M, V>
675675
): Promise<AggregateResult<T, M>> {
676676
if (await this.grpcChecker) {
677677
return this.grpc()
@@ -692,14 +692,16 @@ class AggregateManager<T> implements Aggregate<T> {
692692

693693
async nearVector<M extends PropertiesMetrics<T>>(
694694
vector: NearVectorInputType,
695-
opts?: AggregateNearOptions<M>
695+
opts?: AggregateNearOptions<M, V>
696696
): Promise<AggregateResult<T, M>> {
697697
if (await this.grpcChecker) {
698698
return this.grpc()
699-
.then((aggregate) => aggregate.withNearVector(Serialize.aggregate.nearVector(vector, opts)))
699+
.then(async (aggregate) =>
700+
aggregate.withNearVector(await Serialize.aggregate.nearVector(vector, opts))
701+
)
700702
.then((reply) => Deserialize.aggregate(reply));
701703
}
702-
if (!NearVectorInputGuards.is1DArray(vector)) {
704+
if (!NearVectorInputGuards.is1D(vector)) {
703705
throw new WeaviateInvalidInputError(
704706
'Vector can only be a 1D array of numbers when using `nearVector` with <1.29 Weaviate versions.'
705707
);
@@ -768,9 +770,9 @@ class AggregateManager<T> implements Aggregate<T> {
768770
};
769771
}
770772

771-
export interface Aggregate<T> {
773+
export interface Aggregate<T, V> {
772774
/** This namespace contains methods perform a group by search while aggregating metrics. */
773-
groupBy: AggregateGroupBy<T>;
775+
groupBy: AggregateGroupBy<T, V>;
774776
/**
775777
* Aggregate metrics over the objects returned by a hybrid search on this collection.
776778
*
@@ -782,7 +784,7 @@ export interface Aggregate<T> {
782784
*/
783785
hybrid<M extends PropertiesMetrics<T>>(
784786
query: string,
785-
opts?: AggregateHybridOptions<T, M>
787+
opts?: AggregateHybridOptions<T, M, V>
786788
): Promise<AggregateResult<T, M>>;
787789
/**
788790
* Aggregate metrics over the objects returned by a near image vector search on this collection.
@@ -797,7 +799,7 @@ export interface Aggregate<T> {
797799
*/
798800
nearImage<M extends PropertiesMetrics<T>>(
799801
image: string | Buffer,
800-
opts?: AggregateNearOptions<M>
802+
opts?: AggregateNearOptions<M, V>
801803
): Promise<AggregateResult<T, M>>;
802804
/**
803805
* Aggregate metrics over the objects returned by a near object search on this collection.
@@ -812,7 +814,7 @@ export interface Aggregate<T> {
812814
*/
813815
nearObject<M extends PropertiesMetrics<T>>(
814816
id: string,
815-
opts?: AggregateNearOptions<M>
817+
opts?: AggregateNearOptions<M, V>
816818
): Promise<AggregateResult<T, M>>;
817819
/**
818820
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -827,7 +829,7 @@ export interface Aggregate<T> {
827829
*/
828830
nearText<M extends PropertiesMetrics<T>>(
829831
query: string | string[],
830-
opts?: AggregateNearOptions<M>
832+
opts?: AggregateNearOptions<M, V>
831833
): Promise<AggregateResult<T, M>>;
832834
/**
833835
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -842,7 +844,7 @@ export interface Aggregate<T> {
842844
*/
843845
nearVector<M extends PropertiesMetrics<T>>(
844846
vector: number[],
845-
opts?: AggregateNearOptions<M>
847+
opts?: AggregateNearOptions<M, V>
846848
): Promise<AggregateResult<T, M>>;
847849
/**
848850
* Aggregate metrics over all the objects in this collection without any vector search.
@@ -853,7 +855,7 @@ export interface Aggregate<T> {
853855
overAll<M extends PropertiesMetrics<T>>(opts?: AggregateOverAllOptions<M>): Promise<AggregateResult<T, M>>;
854856
}
855857

856-
export interface AggregateGroupBy<T> {
858+
export interface AggregateGroupBy<T, V> {
857859
/**
858860
* Aggregate metrics over the objects grouped by a specified property and returned by a hybrid search on this collection.
859861
*
@@ -865,7 +867,7 @@ export interface AggregateGroupBy<T> {
865867
*/
866868
hybrid<M extends PropertiesMetrics<T>>(
867869
query: string,
868-
opts: AggregateGroupByHybridOptions<T, M>
870+
opts: AggregateGroupByHybridOptions<T, M, V>
869871
): Promise<AggregateGroupByResult<T, M>[]>;
870872
/**
871873
* Aggregate metrics over the objects grouped by a specified property and returned by a near image vector search on this collection.
@@ -880,7 +882,7 @@ export interface AggregateGroupBy<T> {
880882
*/
881883
nearImage<M extends PropertiesMetrics<T>>(
882884
image: string | Buffer,
883-
opts: AggregateGroupByNearOptions<T, M>
885+
opts: AggregateGroupByNearOptions<T, M, V>
884886
): Promise<AggregateGroupByResult<T, M>[]>;
885887
/**
886888
* Aggregate metrics over the objects grouped by a specified property and returned by a near object search on this collection.
@@ -895,7 +897,7 @@ export interface AggregateGroupBy<T> {
895897
*/
896898
nearObject<M extends PropertiesMetrics<T>>(
897899
id: string,
898-
opts: AggregateGroupByNearOptions<T, M>
900+
opts: AggregateGroupByNearOptions<T, M, V>
899901
): Promise<AggregateGroupByResult<T, M>[]>;
900902
/**
901903
* Aggregate metrics over the objects grouped by a specified property and returned by a near text vector search on this collection.
@@ -910,7 +912,7 @@ export interface AggregateGroupBy<T> {
910912
*/
911913
nearText<M extends PropertiesMetrics<T>>(
912914
query: string | string[],
913-
opts: AggregateGroupByNearOptions<T, M>
915+
opts: AggregateGroupByNearOptions<T, M, V>
914916
): Promise<AggregateGroupByResult<T, M>[]>;
915917
/**
916918
* Aggregate metrics over the objects grouped by a specified property and returned by a near vector search on this collection.
@@ -925,7 +927,7 @@ export interface AggregateGroupBy<T> {
925927
*/
926928
nearVector<M extends PropertiesMetrics<T>>(
927929
vector: number[],
928-
opts: AggregateGroupByNearOptions<T, M>
930+
opts: AggregateGroupByNearOptions<T, M, V>
929931
): Promise<AggregateGroupByResult<T, M>[]>;
930932
/**
931933
* Aggregate metrics over all the objects in this collection grouped by a specified property without any vector search.

src/collections/aggregate/integration.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('Testing of the collection.aggregate methods', () => {
8989
// dataType: [collectionName],
9090
// },
9191
],
92-
vectorizers: weaviate.configure.vectorizer.text2VecContextionary({
92+
vectorizers: weaviate.configure.vectors.text2VecContextionary({
9393
vectorizeCollectionName: false,
9494
vectorIndexConfig: weaviate.configure.vectorIndex.hnsw({ maxConnections: 64 }),
9595
}),
@@ -318,7 +318,7 @@ describe('Testing of the collection.aggregate methods with named vectors', () =>
318318
},
319319
],
320320
vectorizers: [
321-
weaviate.configure.vectorizer.text2VecContextionary({
321+
weaviate.configure.vectors.text2VecContextionary({
322322
name: 'text',
323323
sourceProperties: ['text'],
324324
vectorIndexConfig: weaviate.configure.vectorIndex.hnsw(),
@@ -417,7 +417,7 @@ describe('Testing of collection.aggregate search methods', () => {
417417
dataType: 'text',
418418
},
419419
],
420-
vectorizers: weaviate.configure.vectorizer.text2VecContextionary(),
420+
vectorizers: weaviate.configure.vectors.text2VecContextionary(),
421421
})
422422
.then(() => {
423423
const data: Array<any> = [];
@@ -485,7 +485,7 @@ describe('Testing of collection.aggregate search methods', () => {
485485

486486
it('should return an aggregation on a nearVector search', async () => {
487487
const obj = await collection.query.fetchObjectById(uuid, { includeVector: true });
488-
const result = await collection.aggregate.nearVector(obj?.vectors.default!, {
488+
const result = await collection.aggregate.nearVector(obj?.vectors.default as number[], {
489489
objectLimit: 1000,
490490
returnMetrics: collection.metrics.aggregate('text').text(['count']),
491491
});
@@ -494,7 +494,7 @@ describe('Testing of collection.aggregate search methods', () => {
494494

495495
it('should return a grouped aggregation on a nearVector search', async () => {
496496
const obj = await collection.query.fetchObjectById(uuid, { includeVector: true });
497-
const result = await collection.aggregate.groupBy.nearVector(obj?.vectors.default!, {
497+
const result = await collection.aggregate.groupBy.nearVector(obj?.vectors.default as number[], {
498498
objectLimit: 1000,
499499
groupBy: 'text',
500500
returnMetrics: collection.metrics.aggregate('text').text(['count']),

0 commit comments

Comments
 (0)