Skip to content

Commit

Permalink
Merge branch 'bump-meilisearch-v1.10.0' into feature-update-documents…
Browse files Browse the repository at this point in the history
…-by-fn
  • Loading branch information
flevi29 authored Aug 21, 2024
2 parents 178805c + a2d46d5 commit 53644ad
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 15 deletions.
26 changes: 26 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,29 @@ distinct_attribute_guide_filterable_1: |-
client.index('products').updateFilterableAttributes(['product_id', 'sku', 'url'])
distinct_attribute_guide_distinct_parameter_1: |-
client.index('products').search('white shirt', { distinct: 'sku' })
multi_search_federated_1: |-
client.multiSearch({
federation: {},
queries: [
{
indexUid: 'movies',
q: 'batman',
limit: 5,
},
{
indexUid: 'comics',
q: 'batman',
limit: 5,
},
]
})
search_parameter_reference_locales_1: |-
client.index('INDEX_NAME').search('進撃の巨人', { locales: ['jpn'] })
get_localized_attribute_settings_1: |-
client.index('INDEX_NAME').getLocalizedAttributes()
update_localized_attribute_settings_1: |-
client.index('INDEX_NAME').updateLocalizedAttributes([
{ attributePatterns: ['jpn'], locales: ['*_ja'] },
];)
reset_localized_attribute_settings_1: |-
client.index('INDEX_NAME').resetLocalizedAttributes()
42 changes: 42 additions & 0 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
Embedders,
SearchCutoffMs,
SearchSimilarDocumentsParams,
LocalizedAttributes,
UpdateDocumentsByFunctionOptions,
} from './types';
import { removeUndefinedFromObject } from './utils';
Expand Down Expand Up @@ -1415,6 +1416,47 @@ class Index<T extends Record<string, any> = Record<string, any>> {

return new EnqueuedTask(task);
}

///
/// LOCALIZED ATTRIBUTES SETTINGS
///

/**
* Get the localized attributes settings.
*
* @returns Promise containing object of localized attributes settings
*/
async getLocalizedAttributes(): Promise<LocalizedAttributes> {
const url = `indexes/${this.uid}/settings/localized-attributes`;
return await this.httpRequest.get<LocalizedAttributes>(url);
}

/**
* Update the localized attributes settings.
*
* @param localizedAttributes - Localized attributes object
* @returns Promise containing an EnqueuedTask
*/
async updateLocalizedAttributes(
localizedAttributes: LocalizedAttributes,
): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/localized-attributes`;
const task = await this.httpRequest.put(url, localizedAttributes);

return new EnqueuedTask(task);
}

/**
* Reset the localized attributes settings.
*
* @returns Promise containing an EnqueuedTask
*/
async resetLocalizedAttributes(): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/localized-attributes`;
const task = await this.httpRequest.delete(url);

return new EnqueuedTask(task);
}
}

export { Index };
31 changes: 24 additions & 7 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export type HybridSearch = {
semanticRatio?: number;
};

// https://www.meilisearch.com/docs/reference/api/settings#localized-attributes
export type Locale = string;

export type SearchParams = Query &
Pagination &
Highlight &
Expand All @@ -130,6 +133,7 @@ export type SearchParams = Query &
hybrid?: HybridSearch;
distinct?: string;
retrieveVectors?: boolean;
locales?: Locale[];
};

// Search parameters for searches made with the GET method
Expand All @@ -152,6 +156,7 @@ export type SearchRequestGET = Pagination &
rankingScoreThreshold?: number;
distinct?: string;
retrieveVectors?: boolean;
locales?: Locale[];
};

export type MultiSearchQuery = SearchParams & { indexUid: string };
Expand Down Expand Up @@ -372,6 +377,7 @@ export type OpenAiEmbedder = {
documentTemplate?: string;
dimensions?: number;
distribution?: Distribution;
url?: string;
};

export type HuggingFaceEmbedder = {
Expand All @@ -394,12 +400,10 @@ export type RestEmbedder = {
apiKey?: string;
dimensions?: number;
documentTemplate?: string;
inputField?: string[] | null;
inputType?: 'text' | 'textArray';
query?: Record<string, any> | null;
pathToEmbeddings?: string[] | null;
embeddingObject?: string[] | null;
distribution?: Distribution;
request: Record<string, any>;
response: Record<string, any>;
headers?: Record<string, string>;
};

export type OllamaEmbedder = {
Expand All @@ -409,6 +413,7 @@ export type OllamaEmbedder = {
model?: string;
documentTemplate?: string;
distribution?: Distribution;
dimensions?: number;
};

export type Embedder =
Expand All @@ -434,6 +439,13 @@ export type PaginationSettings = {

export type SearchCutoffMs = number | null;

export type LocalizedAttribute = {
attributePatterns: string[];
locales: Locale[];
};

export type LocalizedAttributes = LocalizedAttribute[] | null;

export type Settings = {
filterableAttributes?: FilterableAttributes;
distinctAttribute?: DistinctAttribute;
Expand All @@ -452,6 +464,7 @@ export type Settings = {
proximityPrecision?: ProximityPrecision;
embedders?: Embedders;
searchCutoffMs?: SearchCutoffMs;
localizedAttributes?: LocalizedAttributes;
};

/*
Expand Down Expand Up @@ -683,9 +696,9 @@ export interface FetchError extends Error {

export type MeiliSearchErrorResponse = {
message: string;
// @TODO: Could be typed, but will it be kept updated? https://www.meilisearch.com/docs/reference/errors/error_codes
// https://www.meilisearch.com/docs/reference/errors/error_codes
code: string;
// @TODO: Could be typed https://www.meilisearch.com/docs/reference/errors/overview#errors
// https://www.meilisearch.com/docs/reference/errors/overview#errors
type: string;
link: string;
};
Expand Down Expand Up @@ -998,6 +1011,10 @@ export const ErrorStatusCode = {
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */
INVALID_SETTINGS_SEARCH_CUTOFF_MS: 'invalid_settings_search_cutoff_ms',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */
INVALID_SETTINGS_LOCALIZED_ATTRIBUTES:
'invalid_settings_localized_attributes',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_before_enqueued_at */
INVALID_TASK_BEFORE_ENQUEUED_AT: 'invalid_task_before_enqueued_at',

Expand Down
26 changes: 18 additions & 8 deletions tests/embedders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
mean: 0.7,
sigma: 0.3,
},
url: 'https://api.openai.com/v1/embeddings',
},
};
const task: EnqueuedTask = await client
Expand Down Expand Up @@ -169,17 +170,25 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
dimensions: 1536,
documentTemplate:
"A movie titled '{{doc.title}}' whose description starts with {{doc.overview|truncatewords: 20}}",
inputField: ['input'],
inputType: 'textArray',
query: {
model: 'text-embedding-ada-002',
},
pathToEmbeddings: ['data'],
embeddingObject: ['embedding'],
distribution: {
mean: 0.7,
sigma: 0.3,
},
request: {
model: 'text-embedding-3-small',
input: ['{{text}}', '{{..}}'],
},
response: {
data: [
{
embedding: '{{embedding}}',
},
'{{..}}',
],
},
headers: {
'Custom-Header': 'CustomValue',
},
},
};
const task: EnqueuedTask = await client
Expand All @@ -197,7 +206,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
});
});

test.skip(`${permission} key: Update embedders with 'ollama' source`, async () => {
test(`${permission} key: Update embedders with 'ollama' source`, async () => {
const client = await getClient(permission);
const newEmbedder: Embedders = {
default: {
Expand All @@ -210,6 +219,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
mean: 0.7,
sigma: 0.3,
},
dimensions: 512,
},
};
const task: EnqueuedTask = await client
Expand Down
Loading

0 comments on commit 53644ad

Please sign in to comment.