Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/collections/config/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ export type MultiTenancyConfig = {
enabled: boolean;
};

export type ReplicationDeletionStrategy = 'DeleteOnConflict' | 'NoAutomatedResolution';

export type ReplicationConfig = {
asyncEnabled: boolean;
deletionStrategy: ReplicationDeletionStrategy;
factor: number;
};

Expand Down
1 change: 1 addition & 0 deletions src/collections/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class ConfigMapping {
return {
factor: v.factor,
asyncEnabled: v.asyncEnabled ? v.asyncEnabled : false,
deletionStrategy: v.deletionStrategy ? v.deletionStrategy : 'NoAutomatedResolution',
};
}
static sharding(v?: WeaviateShardingConfig): ShardingConfig {
Expand Down
28 changes: 24 additions & 4 deletions src/collections/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
InvertedIndexConfigUpdate,
MultiTenancyConfigCreate,
ReplicationConfigCreate,
ReplicationConfigUpdate,
ReplicationDeletionStrategy,
ShardingConfigCreate,
VectorConfigUpdate,
VectorIndexType,
Expand Down Expand Up @@ -131,10 +133,19 @@ const configure = {
* See [the docs](https://weaviate.io/developers/weaviate/concepts/replication-architecture#replication-vs-sharding) for more details.
*
* @param {boolean} [options.asyncEnabled] Whether asynchronous replication is enabled. Default is false.
* @param {ReplicationDeletionStrategy} [options.deletionStrategy] The deletion strategy when replication conflicts are detected between deletes and reads.
* @param {number} [options.factor] The replication factor. Default is 1.
*/
replication: (options: { asyncEnabled?: boolean; factor?: number }): ReplicationConfigCreate => {
return { asyncEnabled: options.asyncEnabled, factor: options.factor };
replication: (options: {
asyncEnabled?: boolean;
deletionStrategy?: ReplicationDeletionStrategy;
factor?: number;
}): ReplicationConfigCreate => {
return {
asyncEnabled: options.asyncEnabled,
deletionStrategy: options.deletionStrategy,
factor: options.factor,
};
},
/**
* Create a `ShardingConfigCreate` object to be used when defining the sharding configuration of your collection.
Expand Down Expand Up @@ -217,10 +228,19 @@ const reconfigure = {
* See [the docs](https://weaviate.io/developers/weaviate/concepts/replication-architecture#replication-vs-sharding) for more details.
*
* @param {boolean} [options.asyncEnabled] Whether asynchronous replication is enabled.
* @param {ReplicationDeletionStrategy} [options.deletionStrategy] The deletion strategy when replication conflicts are detected between deletes and reads.
* @param {number} [options.factor] The replication factor.
*/
replication: (options: { asyncEnabled?: boolean; factor?: number }): ReplicationConfigCreate => {
return { asyncEnabled: options.asyncEnabled, factor: options.factor };
replication: (options: {
asyncEnabled?: boolean;
deletionStrategy?: ReplicationDeletionStrategy;
factor?: number;
}): ReplicationConfigUpdate => {
return {
asyncEnabled: options.asyncEnabled,
deletionStrategy: options.deletionStrategy,
factor: options.factor,
};
},
};

Expand Down
16 changes: 12 additions & 4 deletions src/collections/configure/types/base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { WeaviateNestedProperty, WeaviateProperty } from '../../../openapi/types.js';
import { InvertedIndexConfig, MultiTenancyConfig, ReplicationConfig } from '../../config/types/index.js';
import {
InvertedIndexConfig,
MultiTenancyConfig,
ReplicationConfig,
ReplicationDeletionStrategy,
} from '../../config/types/index.js';
import { DataType } from '../../types/index.js';
import { NonRefKeys, RefKeys } from '../../types/internal.js';

export type RecursivePartial<T> = {
[P in keyof T]?: RecursivePartial<T[P]>;
};
export type RecursivePartial<T> = T extends object
? {
[P in keyof T]?: RecursivePartial<T[P]>;
}
: T;

export type InvertedIndexConfigCreate = RecursivePartial<InvertedIndexConfig>;

Expand Down Expand Up @@ -133,6 +140,7 @@ export type ReplicationConfigCreate = RecursivePartial<ReplicationConfig>;

export type ReplicationConfigUpdate = {
asyncEnabled?: boolean;
deletionStrategy?: ReplicationDeletionStrategy;
factor?: number;
};

Expand Down
22 changes: 19 additions & 3 deletions src/collections/configure/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ import {
ModuleConfig,
VectorConfigCreate,
} from '../types/index.js';
import { configure } from './index.js';
import { configure, reconfigure } from './index.js';
import {
InvertedIndexConfigCreate,
MultiTenancyConfigCreate,
ReplicationConfigCreate,
ReplicationConfigUpdate,
ShardingConfigCreate,
VectorIndexConfigFlatCreate,
VectorIndexConfigHNSWCreate,
} from './types/index.js';

describe('Unit testing of the configure factory class', () => {
describe('Unit testing of the configure & reconfigure factory classes', () => {
it('should create the correct InvertedIndexConfig type with all values', () => {
const config = configure.invertedIndex({
bm25b: 0.5,
Expand Down Expand Up @@ -76,13 +77,28 @@ describe('Unit testing of the configure factory class', () => {
});
});

it('should create the correct ReplicationConfig type with all values', () => {
it('should create the correct ReplicationConfigCreate type with all values', () => {
const config = configure.replication({
asyncEnabled: true,
deletionStrategy: 'DeleteOnConflict',
factor: 2,
});
expect(config).toEqual<ReplicationConfigCreate>({
asyncEnabled: true,
deletionStrategy: 'DeleteOnConflict',
factor: 2,
});
});

it('should create the correct ReplicationConfigUpdate type with all values', () => {
const config = reconfigure.replication({
asyncEnabled: true,
deletionStrategy: 'DeleteOnConflict',
factor: 2,
});
expect(config).toEqual<ReplicationConfigUpdate>({
asyncEnabled: true,
deletionStrategy: 'DeleteOnConflict',
factor: 2,
});
});
Expand Down
5 changes: 5 additions & 0 deletions src/collections/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PQConfig,
PhoneNumber,
PropertyConfig,
ReplicationDeletionStrategy,
Text2VecContextionaryConfig,
Text2VecOpenAIConfig,
VectorIndexConfigHNSW,
Expand Down Expand Up @@ -578,6 +579,10 @@ describe('Testing of the collections.create method', () => {

expect(response.multiTenancy.enabled).toEqual(true);

expect(response.replication.asyncEnabled).toEqual(false);
expect(response.replication.deletionStrategy).toEqual<ReplicationDeletionStrategy>(
'NoAutomatedResolution'
);
expect(response.replication.factor).toEqual(2);

const indexConfig = response.vectorizers.default.indexConfig as VectorIndexConfigHNSW;
Expand Down
1 change: 1 addition & 0 deletions src/collections/journey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe('Journey testing of the client using a WCD cluster', () => {
references: [],
replication: {
asyncEnabled: false,
deletionStrategy: 'NoAutomatedResolution',
factor: 1,
},
reranker: {
Expand Down
Loading