Skip to content

Commit

Permalink
Merge pull request #255 from weaviate/fix-configure-inverted-index
Browse files Browse the repository at this point in the history
Fix bug in `configure.invertedIndex` where undefined `b` and `k1` were sent to the server
  • Loading branch information
tsmith023 authored Jan 15, 2025
2 parents c545685 + b24859d commit 7a7c806
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
48 changes: 30 additions & 18 deletions src/collections/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,25 @@ const configure = {
stopwordsRemovals?: string[];
}): InvertedIndexConfigCreate => {
return {
bm25: {
b: options.bm25b,
k1: options.bm25k1,
},
bm25:
options.bm25b || options.bm25k1
? {
b: options.bm25b,
k1: options.bm25k1,
}
: undefined,
cleanupIntervalSeconds: options.cleanupIntervalSeconds,
indexTimestamps: options.indexTimestamps,
indexPropertyLength: options.indexPropertyLength,
indexNullState: options.indexNullState,
stopwords: {
preset: options.stopwordsPreset,
additions: options.stopwordsAdditions,
removals: options.stopwordsRemovals,
},
stopwords:
options.stopwordsAdditions || options.stopwordsRemovals || options.stopwordsPreset
? {
preset: options.stopwordsPreset,
additions: options.stopwordsAdditions,
removals: options.stopwordsRemovals,
}
: undefined,
};
},
/**
Expand Down Expand Up @@ -195,16 +201,22 @@ const reconfigure = {
stopwordsRemovals?: string[];
}): InvertedIndexConfigUpdate => {
return {
bm25: {
b: options.bm25b,
k1: options.bm25k1,
},
bm25:
options.bm25b || options.bm25k1
? {
b: options.bm25b,
k1: options.bm25k1,
}
: undefined,
cleanupIntervalSeconds: options.cleanupIntervalSeconds,
stopwords: {
preset: options.stopwordsPreset,
additions: options.stopwordsAdditions,
removals: options.stopwordsRemovals,
},
stopwords:
options.stopwordsAdditions || options.stopwordsRemovals || options.stopwordsPreset
? {
preset: options.stopwordsPreset,
additions: options.stopwordsAdditions,
removals: options.stopwordsRemovals,
}
: undefined,
};
},
vectorizer: {
Expand Down
9 changes: 7 additions & 2 deletions src/collections/configure/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ModuleConfig,
VectorConfigCreate,
} from '../types/index.js';
import { configure, reconfigure } from './index.js';
import { configure } from './index.js';
import {
InvertedIndexConfigCreate,
MultiTenancyConfigCreate,
Expand All @@ -25,6 +25,11 @@ import {
} from './types/index.js';

describe('Unit testing of the configure & reconfigure factory classes', () => {
it('should create the correct InvertedIndexConfig type with defaults', () => {
const config = configure.invertedIndex({});
expect(config).toEqual<InvertedIndexConfigCreate>({});
});

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

it('should create the correct ReplicationConfigUpdate type with all values', () => {
const config = reconfigure.replication({
const config = configure.replication({
asyncEnabled: true,
deletionStrategy: 'DeleteOnConflict',
factor: 2,
Expand Down
6 changes: 6 additions & 0 deletions src/collections/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ export type NonReferenceInputs<Obj> = Obj extends undefined
};

export type MapPhoneNumberType<T> = T extends PhoneNumber ? PhoneNumberInput : T;

type AtLeastOne<T> = {
[K in keyof T]: Pick<T, K>;
}[keyof T];

export type NonEmpty<T> = keyof T extends never ? never : T;

0 comments on commit 7a7c806

Please sign in to comment.