-
Notifications
You must be signed in to change notification settings - Fork 100
Improve Settings
#1864
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
Open
flevi29
wants to merge
30
commits into
meilisearch:main
Choose a base branch
from
flevi29:improve-settings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve Settings
#1864
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
2fcafc0
Improve settings
flevi29 9692533
Fix formatting
flevi29 ab6b24b
Merge branch 'main' into improve-settings
flevi29 80b6db7
Merge branch 'main' into improve-settings
flevi29 4c85a6f
Merge branch 'main' into improve-settings
flevi29 d21ecfd
Merge with main
flevi29 9a82d5e
Merge with main
flevi29 83a1b09
Merge with main
flevi29 d845050
Fix lint issue
flevi29 12d5c37
Merge with main
flevi29 b851425
Make adjustments, fixes
flevi29 86a8f89
Remove unnecessary type params
flevi29 3095a19
Shorten code
flevi29 d35cc36
Adjust documentation, fix test
flevi29 beb41ea
Merge branch 'main' into improve-settings
flevi29 65fb90e
Documentation
flevi29 0dfc39f
Merge with main
flevi29 a8b99d1
Progress
flevi29 f6dbc99
Refactor settings tests
flevi29 9e9fd85
Minor changes
flevi29 7b83644
Improve tests
flevi29 b523bca
Merge branch 'main' into improve-settings
flevi29 4dee0f7
Merge with main
flevi29 9a95477
Use randomUUID instead of fixed UUID
flevi29 c52f078
Merge with main, and add vector store experimental feature
flevi29 4bda5ad
Fix type issue, temporarily fix test error
flevi29 32d171c
Fix experimental settings test
flevi29 5966914
Fix test
flevi29 ceb2db6
Adjustments, docs
flevi29 77b0797
Adjustments
flevi29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import type { HttpRequests } from "./http-requests.js"; | ||
| import type { HttpRequestsWithEnqueuedTaskPromise } from "./task.js"; | ||
| import type { | ||
| EnqueuedTaskPromise, | ||
| SingleUpdatableSettings, | ||
| RecordAny, | ||
| } from "./types/index.js"; | ||
|
|
||
| /** Each setting property mapped to their REST method required for updates. */ | ||
| type MakeSettingsRecord = { | ||
| [TKey in keyof SingleUpdatableSettings]: "put" | "patch"; | ||
| }; | ||
|
|
||
| /** Each setting property mapped to its get, update and reset functions. */ | ||
| export type SettingFns = { | ||
| [TKey in keyof SingleUpdatableSettings as `get${Capitalize<TKey>}`]: () => Promise< | ||
| SingleUpdatableSettings[TKey] | ||
| >; | ||
| } & { | ||
| [TKey in keyof SingleUpdatableSettings as `update${Capitalize<TKey>}`]: ( | ||
| body: SingleUpdatableSettings[TKey], | ||
| ) => EnqueuedTaskPromise; | ||
| } & { | ||
| [TKey in keyof SingleUpdatableSettings as `reset${Capitalize<TKey>}`]: () => EnqueuedTaskPromise; | ||
| }; | ||
|
|
||
| function capitalize(str: string): string { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| } | ||
|
|
||
| function camelToKebabCase(str: string): string { | ||
| return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`); | ||
| } | ||
|
|
||
| /** Returns an object containing all the setting functions. */ | ||
| export function makeSettingFns( | ||
| httpRequest: HttpRequests, | ||
| httpRequestsWithTask: HttpRequestsWithEnqueuedTaskPromise, | ||
| basePath: string, | ||
| opts: MakeSettingsRecord, | ||
| ): SettingFns { | ||
| const settingFns = {} as RecordAny; | ||
|
|
||
| for (const [name, method] of Object.entries(opts)) { | ||
| const uppercaseName = capitalize(name); | ||
| const path = `${basePath}/${camelToKebabCase(name)}`; | ||
|
|
||
| settingFns[`get${uppercaseName}`] = async function (): Promise< | ||
| SingleUpdatableSettings[keyof typeof opts] | ||
| > { | ||
| return await httpRequest.get({ path }); | ||
| }; | ||
|
|
||
| settingFns[`update${uppercaseName}`] = function ( | ||
| body: SingleUpdatableSettings[keyof typeof opts], | ||
| ): EnqueuedTaskPromise { | ||
| return httpRequestsWithTask[method]({ path, body }); | ||
| }; | ||
|
|
||
| settingFns[`reset${uppercaseName}`] = function (): EnqueuedTaskPromise { | ||
| return httpRequestsWithTask.delete({ path }); | ||
| }; | ||
| } | ||
|
|
||
| return settingFns as SettingFns; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/experimental_features#experimental-features-object} | ||
| * | ||
| * @see `meilisearch::routes::features::RuntimeTogglableFeatures` | ||
| */ | ||
| export type RuntimeTogglableFeatures = { | ||
| metrics?: boolean | null; | ||
| logsRoute?: boolean | null; | ||
| editDocumentsByFunction?: boolean | null; | ||
| containsFilter?: boolean | null; | ||
| network?: boolean | null; | ||
| getTaskDocumentsRoute?: boolean | null; | ||
| compositeEmbedders?: boolean | null; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| export * from "./experimental-features.js"; | ||
| export * from "./settings.js"; | ||
| export * from "./task_and_batch.js"; | ||
| export * from "./token.js"; | ||
| export * from "./types.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| import type { PascalToCamelCase } from "./shared.js"; | ||
|
|
||
| /** @see `milli::filterable_attributes_rules::FilterFeatures` */ | ||
| export type FilterFeatures = { | ||
| equality?: boolean; | ||
| comparison?: boolean; | ||
| }; | ||
|
|
||
| /** @see `milli::filterable_attributes_rules::FilterableAttributesFeatures` */ | ||
| export type FilterableAttributesFeatures = { | ||
| facetSearch?: boolean; | ||
| filter?: FilterFeatures; | ||
| }; | ||
|
|
||
| /** @see `milli::filterable_attributes_rules::FilterableAttributesPatterns` */ | ||
| export type FilterableAttributesPatterns = { | ||
| attributePatterns: string[]; | ||
| features?: FilterableAttributesFeatures; | ||
| }; | ||
|
|
||
| /** @see `milli::filterable_attributes_rules::FilterableAttributesRule` */ | ||
| export type FilterableAttributesRule = string | FilterableAttributesPatterns; | ||
|
|
||
| /** Deeply map every property of a record to itself excluding null. */ | ||
| type NonNullableDeepRecordValues<T> = { | ||
| [TKey in keyof T]: Exclude<NonNullableDeepRecordValues<T[TKey]>, null>; | ||
| }; | ||
flevi29 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** Map properties of a record to be optional and nullable. */ | ||
| type PartialAndNullable<T> = { [P in keyof T]?: T[P] | null }; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#proximity-precision} | ||
| * | ||
| * @see `meilisearch_types::settings::ProximityPrecisionView` | ||
| */ | ||
| export type ProximityPrecisionView = PascalToCamelCase< | ||
| "ByWord" | "ByAttribute" | ||
| >; | ||
|
|
||
| /** | ||
| * @see `minWordSizeForTypos` at {@link https://www.meilisearch.com/docs/reference/api/settings#typo-tolerance} | ||
| * | ||
| * @see `meilisearch_types::settings::MinWordSizeTyposSetting` | ||
| */ | ||
| export type MinWordSizeTyposSetting = PartialAndNullable<{ | ||
| oneTypo: number; | ||
| twoTypos: number; | ||
| }>; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#typo-tolerance} | ||
| * | ||
| * @see `meilisearch_types::settings::TypoSettings` | ||
| */ | ||
| export type TypoSettings = PartialAndNullable<{ | ||
| enabled: boolean; | ||
| minWordSizeForTypos: MinWordSizeTyposSetting; | ||
| disableOnWords: string[]; | ||
| disableOnAttributes: string[]; | ||
| }>; | ||
|
|
||
| /** | ||
| * @see `sortFacetValuesBy` at {@link https://www.meilisearch.com/docs/reference/api/settings#faceting} | ||
| * @see `meilisearch_types::facet_values_sort::FacetValuesSort` | ||
| */ | ||
| export type FacetValuesSort = PascalToCamelCase<"Alpha" | "Count">; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#faceting} | ||
| * | ||
| * @see `meilisearch_types::settings::FacetingSettings` | ||
| */ | ||
| export type FacetingSettings = PartialAndNullable<{ | ||
| maxValuesPerFacet: number; | ||
| sortFacetValuesBy: Record<string, FacetValuesSort>; | ||
| }>; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#pagination} | ||
| * | ||
| * @see `meilisearch_types::settings::PaginationSettings` | ||
| */ | ||
| export type PaginationSettings = PartialAndNullable<{ maxTotalHits: number }>; | ||
|
|
||
| /** | ||
| * `distribution` at | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#embedders} | ||
| * | ||
| * @see `milli::vector::DistributionShift` | ||
| */ | ||
| export type DistributionShift = { | ||
| mean: number; | ||
| sigma: number; | ||
| }; | ||
|
|
||
| /** | ||
| * `source` at | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#embedders} | ||
| * | ||
| * @see `milli::vector::settings::EmbedderSource` | ||
| */ | ||
| export type EmbedderSource = PascalToCamelCase< | ||
| "OpenAi" | "HuggingFace" | "Ollama" | "UserProvided" | "Rest" | "Composite" | ||
| >; | ||
|
|
||
| /** @see `milli::vector::hf::OverridePooling` */ | ||
| export type OverridePooling = PascalToCamelCase< | ||
| "UseModel" | "ForceCls" | "ForceMean" | ||
| >; | ||
|
|
||
| /** @see `milli::vector::settings::SubEmbeddingSettings` */ | ||
| export type SubEmbeddingSettings = PartialAndNullable<{ | ||
| source: EmbedderSource; | ||
| model: string; | ||
| revision: string; | ||
| pooling: OverridePooling; | ||
| apiKey: string; | ||
| dimensions: number; | ||
| documentTemplate: string; | ||
| documentTemplateMaxBytes: number; | ||
| url: string; | ||
| request: unknown; | ||
| response: unknown; | ||
| headers: Record<string, string>; | ||
| }>; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#embedders} | ||
| * | ||
| * @see `milli::vector::settings::EmbeddingSettings` | ||
| */ | ||
| export type EmbeddingSettings = PartialAndNullable<{ | ||
| distribution: DistributionShift; | ||
| binaryQuantized: boolean; | ||
| searchEmbedder: SubEmbeddingSettings; | ||
| indexingEmbedder: SubEmbeddingSettings; | ||
| }> & | ||
| SubEmbeddingSettings; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#localized-attributes} | ||
| * | ||
| * @see `meilisearch_types::locales::LocalizedAttributesRuleView` | ||
| */ | ||
| export type LocalizedAttributesRuleView = { | ||
| /** @see `milli::attribute_patterns::AttributePatterns` */ | ||
| attributePatterns: string[]; | ||
| /** @see `meilisearch_types::locales::Locale` */ | ||
| locales: string[]; | ||
| }; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#prefix-search} | ||
| * | ||
| * @see `meilisearch_types::settings::PrefixSearchSettings` | ||
| */ | ||
| export type PrefixSearchSettings = PascalToCamelCase< | ||
| "IndexingTime" | "Disabled" | ||
| >; | ||
|
|
||
| /** @see `meilisearch_types::settings::RankingRuleView` */ | ||
| export type RankingRuleView = | ||
| | PascalToCamelCase< | ||
| "Words" | "Typo" | "Proximity" | "Attribute" | "Sort" | "Exactness" | ||
| > | ||
| | `${string}:${"asc" | "desc"}`; | ||
|
|
||
| /** A version of {@link Settings} that can be used to update the settings. */ | ||
| export type UpdatableSettings = PartialAndNullable<{ | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#displayed-attributes} */ | ||
| displayedAttributes: string[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#searchable-attributes} */ | ||
| searchableAttributes: string[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#filterable-attributes} */ | ||
| filterableAttributes: FilterableAttributesRule[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#sortable-attributes} */ | ||
| sortableAttributes: string[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#ranking-rules} */ | ||
| rankingRules: RankingRuleView[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#stop-words} */ | ||
| stopWords: string[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens} */ | ||
| nonSeparatorTokens: string[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#separator-tokens} */ | ||
| separatorTokens: string[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#dictionary} */ | ||
| dictionary: string[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#synonyms} */ | ||
| synonyms: Record<string, string[]>; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#distinct-attribute} */ | ||
| distinctAttribute: string; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#proximity-precision} */ | ||
| proximityPrecision: ProximityPrecisionView; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#typo-tolerance} */ | ||
| typoTolerance: TypoSettings; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#faceting} */ | ||
| faceting: FacetingSettings; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#pagination} */ | ||
| pagination: PaginationSettings; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#embedders} */ | ||
| embedders: PartialAndNullable<Record<string, EmbeddingSettings>>; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#search-cutoff} */ | ||
| searchCutoffMs: number; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#localized-attributes} */ | ||
| localizedAttributes: LocalizedAttributesRuleView[]; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#facet-search} */ | ||
| facetSearch: boolean; | ||
| /** {@link https://www.meilisearch.com/docs/reference/api/settings#prefix-search} */ | ||
| prefixSearch: PrefixSearchSettings; | ||
| }>; | ||
|
|
||
| /** | ||
| * A version of {@link UpdatableSettings}, the first layer of properties of which | ||
| * is used to update or get individual settings. | ||
| */ | ||
| export type SingleUpdatableSettings = Required<UpdatableSettings>; | ||
|
|
||
| /** | ||
| * {@link https://www.meilisearch.com/docs/reference/api/settings#body} | ||
| * | ||
| * @see `meilisearch_types::settings::Settings` | ||
| */ | ||
| export type Settings = NonNullableDeepRecordValues<UpdatableSettings>; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.