Skip to content

Commit 7a7c806

Browse files
authored
Merge pull request #255 from weaviate/fix-configure-inverted-index
Fix bug in `configure.invertedIndex` where undefined `b` and `k1` were sent to the server
2 parents c545685 + b24859d commit 7a7c806

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

src/collections/configure/index.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,25 @@ const configure = {
9191
stopwordsRemovals?: string[];
9292
}): InvertedIndexConfigCreate => {
9393
return {
94-
bm25: {
95-
b: options.bm25b,
96-
k1: options.bm25k1,
97-
},
94+
bm25:
95+
options.bm25b || options.bm25k1
96+
? {
97+
b: options.bm25b,
98+
k1: options.bm25k1,
99+
}
100+
: undefined,
98101
cleanupIntervalSeconds: options.cleanupIntervalSeconds,
99102
indexTimestamps: options.indexTimestamps,
100103
indexPropertyLength: options.indexPropertyLength,
101104
indexNullState: options.indexNullState,
102-
stopwords: {
103-
preset: options.stopwordsPreset,
104-
additions: options.stopwordsAdditions,
105-
removals: options.stopwordsRemovals,
106-
},
105+
stopwords:
106+
options.stopwordsAdditions || options.stopwordsRemovals || options.stopwordsPreset
107+
? {
108+
preset: options.stopwordsPreset,
109+
additions: options.stopwordsAdditions,
110+
removals: options.stopwordsRemovals,
111+
}
112+
: undefined,
107113
};
108114
},
109115
/**
@@ -195,16 +201,22 @@ const reconfigure = {
195201
stopwordsRemovals?: string[];
196202
}): InvertedIndexConfigUpdate => {
197203
return {
198-
bm25: {
199-
b: options.bm25b,
200-
k1: options.bm25k1,
201-
},
204+
bm25:
205+
options.bm25b || options.bm25k1
206+
? {
207+
b: options.bm25b,
208+
k1: options.bm25k1,
209+
}
210+
: undefined,
202211
cleanupIntervalSeconds: options.cleanupIntervalSeconds,
203-
stopwords: {
204-
preset: options.stopwordsPreset,
205-
additions: options.stopwordsAdditions,
206-
removals: options.stopwordsRemovals,
207-
},
212+
stopwords:
213+
options.stopwordsAdditions || options.stopwordsRemovals || options.stopwordsPreset
214+
? {
215+
preset: options.stopwordsPreset,
216+
additions: options.stopwordsAdditions,
217+
removals: options.stopwordsRemovals,
218+
}
219+
: undefined,
208220
};
209221
},
210222
vectorizer: {

src/collections/configure/unit.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ModuleConfig,
1414
VectorConfigCreate,
1515
} from '../types/index.js';
16-
import { configure, reconfigure } from './index.js';
16+
import { configure } from './index.js';
1717
import {
1818
InvertedIndexConfigCreate,
1919
MultiTenancyConfigCreate,
@@ -25,6 +25,11 @@ import {
2525
} from './types/index.js';
2626

2727
describe('Unit testing of the configure & reconfigure factory classes', () => {
28+
it('should create the correct InvertedIndexConfig type with defaults', () => {
29+
const config = configure.invertedIndex({});
30+
expect(config).toEqual<InvertedIndexConfigCreate>({});
31+
});
32+
2833
it('should create the correct InvertedIndexConfig type with all values', () => {
2934
const config = configure.invertedIndex({
3035
bm25b: 0.5,
@@ -90,7 +95,7 @@ describe('Unit testing of the configure & reconfigure factory classes', () => {
9095
});
9196

9297
it('should create the correct ReplicationConfigUpdate type with all values', () => {
93-
const config = reconfigure.replication({
98+
const config = configure.replication({
9499
asyncEnabled: true,
95100
deletionStrategy: 'DeleteOnConflict',
96101
factor: 2,

src/collections/types/internal.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,9 @@ export type NonReferenceInputs<Obj> = Obj extends undefined
124124
};
125125

126126
export type MapPhoneNumberType<T> = T extends PhoneNumber ? PhoneNumberInput : T;
127+
128+
type AtLeastOne<T> = {
129+
[K in keyof T]: Pick<T, K>;
130+
}[keyof T];
131+
132+
export type NonEmpty<T> = keyof T extends never ? never : T;

0 commit comments

Comments
 (0)