Skip to content

Fix bug in configure.invertedIndex where undefined b and k1 were sent to the server #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2025
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
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;
Loading