Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 24 additions & 19 deletions src/collections/configure/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
ConfigureNonTextVectorizerOptions,

Check failure on line 2 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Delete `ConfigureNonTextVectorizerOptions,⏎··ConfigureTextVectorizerOptions,⏎··`
ConfigureTextVectorizerOptions,
InvertedIndexConfigCreate,
InvertedIndexConfigUpdate,
MultiTenancyConfigCreate,
Expand All @@ -9,6 +11,8 @@
ShardingConfigCreate,
VectorConfigUpdate,
VectorIndexType,
Vectorizer,

Check failure on line 14 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Delete `,⏎··VectorizerConfigCreateType,⏎··Vectorizer`
VectorizerConfigCreateType,
VectorizerUpdateOptions,
} from '../types/index.js';

Expand All @@ -18,6 +22,7 @@
import { multiVectors, vectors } from './vectorizer.js';

import { parseWithDefault } from './parsing.js';
import { RemoveConfiguration } from './types/util.js';

const dataType = {
INT: 'int' as const,
Expand Down Expand Up @@ -64,7 +69,7 @@
* @deprecated Use `vectors` instead.
*/
vectorizer: vectors,
vectors,
vectors: vectors as RemoveConfiguration<typeof vectors, 'vectorizeCollectionName'>,
vectorIndex: configureVectorIndex,
dataType,
tokenization,
Expand Down Expand Up @@ -99,9 +104,9 @@
bm25:
options.bm25b || options.bm25k1
? {
b: options.bm25b,
k1: options.bm25k1,
}
b: options.bm25b,

Check failure on line 107 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
k1: options.bm25k1,

Check failure on line 108 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
}

Check failure on line 109 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
: undefined,
cleanupIntervalSeconds: options.cleanupIntervalSeconds,
indexTimestamps: options.indexTimestamps,
Expand All @@ -110,10 +115,10 @@
stopwords:
options.stopwordsAdditions || options.stopwordsRemovals || options.stopwordsPreset
? {
preset: options.stopwordsPreset,
additions: options.stopwordsAdditions,
removals: options.stopwordsRemovals,
}
preset: options.stopwordsPreset,

Check failure on line 118 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
additions: options.stopwordsAdditions,

Check failure on line 119 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
removals: options.stopwordsRemovals,

Check failure on line 120 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
}

Check failure on line 121 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
: undefined,
};
},
Expand All @@ -131,10 +136,10 @@
}): MultiTenancyConfigCreate => {
return options
? {
autoTenantActivation: parseWithDefault(options.autoTenantActivation, false),
autoTenantCreation: parseWithDefault(options.autoTenantCreation, false),
enabled: parseWithDefault(options.enabled, true),
}
autoTenantActivation: parseWithDefault(options.autoTenantActivation, false),

Check failure on line 139 in src/collections/configure/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
autoTenantCreation: parseWithDefault(options.autoTenantCreation, false),
enabled: parseWithDefault(options.enabled, true),
}
: { autoTenantActivation: false, autoTenantCreation: false, enabled: true };
},
/**
Expand Down Expand Up @@ -209,18 +214,18 @@
bm25:
options.bm25b || options.bm25k1
? {
b: options.bm25b,
k1: options.bm25k1,
}
b: options.bm25b,
k1: options.bm25k1,
}
: undefined,
cleanupIntervalSeconds: options.cleanupIntervalSeconds,
stopwords:
options.stopwordsAdditions || options.stopwordsRemovals || options.stopwordsPreset
? {
preset: options.stopwordsPreset,
additions: options.stopwordsAdditions,
removals: options.stopwordsRemovals,
}
preset: options.stopwordsPreset,
additions: options.stopwordsAdditions,
removals: options.stopwordsRemovals,
}
: undefined,
};
},
Expand Down
42 changes: 42 additions & 0 deletions src/collections/configure/types/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { VectorizerConfigCreateType } from "./vectorizer.js";

/** KeyofNonEmpty removes `{}` from a union type and returns keys of all constituent types. */
type KeyofNonEmpty<T> = T extends object ? (keyof T extends never ? never : keyof T) : never;


/**
* ParameterUnion extracts the type of the first argument for every function in object `T`
* then combines them in a union.
*/
type ParameterUnion<T> = {
[K in keyof T]: T[K] extends (...args: any[]) => any ? Parameters<T[K]>[0] : never;
}[keyof T];


/**
* RemoveConfiguration finds every function in object `T` and removes keys K from the type of it's first argument.
*
* This util assumes all of functions in `T` are either `{ opts: {...} }` or `{ opts?: {...} | undefined }` and is
* very brittle as a result. In fact, its only purpose is to allow reusing all the code underpinning the now-deprecated
* `configure.vectorizers` in `configure.vectors` while removing `vectorizeCollectionName` parameter from the latter.
*
* Usage (see: src/collections/configure/types/util.ts):
* vectors: vectors as RemoveConfiguration<typeof vectors, 'vectorizeCollectionName'>
*/
export type RemoveConfiguration<T, K extends KeyofNonEmpty<ParameterUnion<T>>> =
T extends object
? {
[F in keyof T]:

// Handle functions with optional `opts?` argument.
T[F] extends (opts?: infer Arg) => infer Ret
// ? (opts?: Arg) => Ret
? (opts?: Omit<Arg, K>) => Ret

// Handle functions with required `opts` argument.
: T[F] extends (opts: infer Arg) => infer Ret
// ? (opts: Arg) => Ret
? (opts: Omit<Arg, K>) => Ret

: T[F];
} : never;
9 changes: 5 additions & 4 deletions src/collections/configure/types/vectorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ export type VectorConfigUpdate<N extends string | undefined, I extends VectorInd

export type VectorizersConfigCreate<T, V> = V extends undefined
?
| VectorConfigCreate<PrimitiveKeys<T>, string | undefined, VectorIndexType, Vectorizer>
| VectorConfigCreate<PrimitiveKeys<T>, string, VectorIndexType, Vectorizer>[]
| VectorConfigCreate<PrimitiveKeys<T>, string | undefined, VectorIndexType, Vectorizer>
| VectorConfigCreate<PrimitiveKeys<T>, string, VectorIndexType, Vectorizer>[]
:
| VectorConfigCreate<PrimitiveKeys<T>, (keyof V & string) | undefined, VectorIndexType, Vectorizer>
| VectorConfigCreate<PrimitiveKeys<T>, keyof V & string, VectorIndexType, Vectorizer>[];
| VectorConfigCreate<PrimitiveKeys<T>, (keyof V & string) | undefined, VectorIndexType, Vectorizer>
| VectorConfigCreate<PrimitiveKeys<T>, keyof V & string, VectorIndexType, Vectorizer>[];

export type VectorizersConfigAdd<T> =
| VectorConfigCreate<PrimitiveKeys<T>, string, VectorIndexType, Vectorizer>
| VectorConfigCreate<PrimitiveKeys<T>, string, VectorIndexType, Vectorizer>[];

// TODO: remove vectorizeCollectionName config
export type ConfigureNonTextVectorizerOptions<
N extends string | undefined,
I extends VectorIndexType,
Expand Down
Loading