Skip to content

Conversation

@Ritinpaul
Copy link

@Ritinpaul Ritinpaul commented Sep 20, 2025

Pull Request

Related issue

Fixes #2013

What does this PR do?

This PR updates the SDK to support the new features in Meilisearch v1.18:

  • Added queryVector field in search responses when retrieveVectors is used
  • Added support for renaming indexes with the optional indexUid parameter in updateIndex
  • Extended tests to cover both queryVector and index renaming
  • Added an example for index renaming in .code-samples.meilisearch.yaml

These changes keep everything backward compatible.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thanks a lot for reviewing this PR!

Summary by CodeRabbit

  • New Features

    • Rename an index via the update method; optionally swap two indexes with rename.
    • Search responses may include a queryVector field; index options accept an optional uid.
  • Documentation

    • Added a code sample demonstrating index rename.
  • Tests

    • Added/updated tests covering index rename and swap-with-rename scenarios.
  • Chores

    • Increased test timeouts and added wait-time limits for test operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@Strift Strift self-requested a review September 24, 2025 05:37
@Strift Strift added the enhancement New feature or request label Sep 24, 2025
@Strift
Copy link
Collaborator

Strift commented Sep 24, 2025

Hello @Ritinpaul and thanks for your contribution 🙌

It appears the tests are failing. Can you look into it?

@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Adds index renaming support (via updateIndex and swap-indexes with rename), exposes optional queryVector in search responses, updates types, adds tests for rename flows, extends default wait timeouts in test utils, and increases Vitest timeouts.

Changes

Cohort / File(s) Summary
Code samples
\.code-samples.meilisearch.yaml
Adds rename_an_index_1 example demonstrating renaming via updateIndex('INDEX_A', { indexUid: 'INDEX_B' }).
Types
src/types/types.ts
Adds uid?: string to IndexOptions and queryVector?: number[] to SearchResponse.
Tests — rename behavior
tests/index.test.ts, tests/client.test.ts
Adds tests covering renaming via updateIndex and swapping indexes with rename: true; asserts task types and swap details.
Tests — minor edit
tests/get_search.test.ts
Removes a non-functional comment; no behavioral change.
Test utilities & config
tests/utils/meilisearch-test-utils.ts, package.json
Sets defaultWaitOptions.timeout = 60000 in test utils and increases Vitest hook/test timeouts to 120000 ms in package.json.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant SDK
  participant Server as Meilisearch

  rect rgb(236,248,255)
  note right of App: Rename via updateIndex (PATCH)
  App->>SDK: updateIndex('indexA', { indexUid: 'indexB' })
  SDK->>Server: PATCH /indexes/indexA { indexUid: "indexB" }
  Server-->>SDK: Task enqueued (indexUpdate / rename)
  SDK-->>App: Task info (taskUid, status)
  end

  rect rgb(245,240,255)
  note right of App: Rename via swap-indexes (POST) with rename=true
  App->>SDK: swapIndexes([{ indexes: ['indexA','indexB'], rename: true }])
  SDK->>Server: POST /swap-indexes [{ indexes: [...], rename: true }]
  Server-->>SDK: Task enqueued (indexSwap)
  SDK-->>App: Task info (taskUid, status, details.swaps)
  end
Loading
sequenceDiagram
  autonumber
  participant App
  participant SDK
  participant Server as Meilisearch

  rect rgb(240,255,244)
  note right of App: Search with retrieveVectors
  App->>SDK: index.search(q, { retrieveVectors: true })
  SDK->>Server: POST /indexes/:uid/search { retrieveVectors: true }
  Server-->>SDK: SearchResponse { hits, queryVector?, ... }
  SDK-->>App: SearchResponse including optional queryVector
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to types changes in src/types/types.ts for downstream compatibility.
  • Review tests in tests/index.test.ts and tests/client.test.ts for assumptions about task types/details.
  • Verify wait/timeout adjustments in tests/utils/meilisearch-test-utils.ts and the package.json test script.

Possibly related PRs

Suggested labels

maintenance

Suggested reviewers

  • curquiza
  • flevi29

Poem

In carrot code I hop and play,
I patch and swap an index today.
Query vectors hum their tune,
Tasks enqueue beneath the moon.
I thump my paws — tests pass soon! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: support Meilisearch v1.18.0 (queryVector + index renaming)' accurately summarizes the main changes: adding queryVector support and index renaming capabilities for Meilisearch v1.18.0.
Linked Issues check ✅ Passed The PR comprehensively addresses all coding objectives from issue #2013: queryVector field added to SearchResponse [src/types], uid parameter added to IndexOptions for renaming [src/types], swap-with-rename test added [tests/client.test.ts], index rename via PATCH test added [tests/index.test.ts], and rename_an_index_1 code sample added [.code-samples.meilisearch.yaml].
Out of Scope Changes check ✅ Passed All changes are directly scoped to supporting Meilisearch v1.18.0 features. Test timeout adjustments in package.json and tests/utils/meilisearch-test-utils.ts are supporting infrastructure changes necessary to stabilize tests, not out-of-scope additions.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c708d5c and 7a0ac20.

📒 Files selected for processing (7)
  • .code-samples.meilisearch.yaml (1 hunks)
  • package.json (1 hunks)
  • src/types/types.ts (2 hunks)
  • tests/client.test.ts (1 hunks)
  • tests/get_search.test.ts (0 hunks)
  • tests/index.test.ts (1 hunks)
  • tests/utils/meilisearch-test-utils.ts (4 hunks)
💤 Files with no reviewable changes (1)
  • tests/get_search.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • package.json
  • tests/utils/meilisearch-test-utils.ts
  • tests/client.test.ts
  • .code-samples.meilisearch.yaml
  • tests/index.test.ts
  • src/types/types.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
.code-samples.meilisearch.yaml (1)

34-36: Rename example is correct; add swapIndexes rename sample
Confirmed updateIndex uses indexUid (per types and tests). Add a sample illustrating

client.swapIndexes([{ indexes: ['INDEX_A','INDEX_B'], rename: true }])
src/types/types.ts (1)

412-413: Add queryVector to SearchResponse: LGTM

Matches the new v1.18 behavior (vector retrieval). Optional typing is appropriate and propagates through multi-search via SearchResponse.

Consider a brief JSDoc on queryVector indicating it is only present when retrieveVectors is true and the query can be embedded.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f7c885 and 3ae56b3.

📒 Files selected for processing (6)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/types/types.ts (2 hunks)
  • tests/client.test.ts (1 hunks)
  • tests/get_search.test.ts (2 hunks)
  • tests/index.test.ts (1 hunks)
  • tests/search.test.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/client.test.ts (4)
tests/utils/meilisearch-test-utils.ts (1)
  • getClient (369-369)
src/meilisearch.ts (1)
  • index (92-94)
src/types/task_and_batch.ts (1)
  • IndexSwap (109-112)
src/types/types.ts (2)
  • ErrorStatusCode (863-1223)
  • ErrorStatusCode (1225-1226)
tests/index.test.ts (2)
src/types/types.ts (2)
  • ErrorStatusCode (863-1223)
  • ErrorStatusCode (1225-1226)
src/meilisearch.ts (1)
  • index (92-94)
🔇 Additional comments (6)
src/types/types.ts (1)

142-145: Index rename payload key: confirm server contract uses indexUid

Change looks correct for the SDK surface, but the Meilisearch PATCH payload for index rename must accept indexUid. If the server expects uid instead, this will break at runtime.

  • Please confirm against v1.18 API that the field name is indexUid.
  • If both uid and indexUid might exist across versions, consider accepting both and normalizing before sending.
tests/search.test.ts (2)

1196-1200: Asserting queryVector when retrieveVectors is true: looks good

Matches the new API surface. Ensure the test environment runs against Meilisearch v1.18 and that the index embeds queries so queryVector is actually returned.


1207-1211: Absence of queryVector without retrieveVectors: looks good

This aligns with the conditional exposure of queryVector.

tests/index.test.ts (1)

295-317: Index rename via update: LGTM

Solid coverage: rename via updateIndex(..., { indexUid }), then 404 on old UID and success on new UID.

tests/get_search.test.ts (2)

520-524: Presence of queryVector on GET when retrieveVectors is true: looks good

Consistent with the types change. Verify CI uses v1.18 and the index is configured so queries are embeddable.


531-535: Absence of queryVector without retrieveVectors: looks good

Matches expected behavior.

Comment on lines 570 to 599
test(`${permission} key: Swap two indexes with rename`, async () => {
const client = await getClient(permission);
const originalUid1 = index.uid;
const originalUid2 = index2.uid;

await client
.index(originalUid1)
.addDocuments([{ id: 1, title: "index_1" }])
.waitTask();
await client
.index(originalUid2)
.addDocuments([{ id: 1, title: "index_2" }])
.waitTask();

const swaps: IndexSwap[] = [
{ indexes: [originalUid1, originalUid2], rename: true },
];

const resolvedTask = await client.swapIndexes(swaps).waitTask();

// Verify the old indexes no longer exist
await expect(client.getIndex(originalUid1)).rejects.toHaveProperty(
"cause.code",
ErrorStatusCode.INDEX_NOT_FOUND,
);
await expect(client.getIndex(originalUid2)).rejects.toHaveProperty(
"cause.code",
ErrorStatusCode.INDEX_NOT_FOUND,
);

// Verify the new indexes exist with swapped content
const docIndex1 = await client.index(originalUid1).getDocument(1);
const docIndex2 = await client.index(originalUid2).getDocument(1);

expect(docIndex1.title).toEqual("index_2");
expect(docIndex2.title).toEqual("index_1");
expect(resolvedTask.type).toEqual("indexSwap");
expect(resolvedTask.details?.swaps).toEqual(swaps);
});
Copy link

@coderabbitai coderabbitai bot Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Test contradiction: asserting non-existence then reading from the same indexes

The test first asserts both original UIDs no longer exist, then immediately fetches documents from those same UIDs. Both cannot be true. With rename: true, UIDs are swapped, not deleted; the original UIDs should remain addressable, with swapped content.

Apply this diff to remove the invalid assertions and clarify the intent:

       const resolvedTask = await client.swapIndexes(swaps).waitTask();

-      // Verify the old indexes no longer exist
-      await expect(client.getIndex(originalUid1)).rejects.toHaveProperty(
-        "cause.code",
-        ErrorStatusCode.INDEX_NOT_FOUND,
-      );
-      await expect(client.getIndex(originalUid2)).rejects.toHaveProperty(
-        "cause.code",
-        ErrorStatusCode.INDEX_NOT_FOUND,
-      );
-
-      // Verify the new indexes exist with swapped content
+      // Verify the indexes are accessible and content has been swapped under the same UIDs
       const docIndex1 = await client.index(originalUid1).getDocument(1);
       const docIndex2 = await client.index(originalUid2).getDocument(1);

       expect(docIndex1.title).toEqual("index_2");
       expect(docIndex2.title).toEqual("index_1");
       expect(resolvedTask.type).toEqual("indexSwap");
       expect(resolvedTask.details?.swaps).toEqual(swaps);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test(`${permission} key: Swap two indexes with rename`, async () => {
const client = await getClient(permission);
const originalUid1 = index.uid;
const originalUid2 = index2.uid;
await client
.index(originalUid1)
.addDocuments([{ id: 1, title: "index_1" }])
.waitTask();
await client
.index(originalUid2)
.addDocuments([{ id: 1, title: "index_2" }])
.waitTask();
const swaps: IndexSwap[] = [
{ indexes: [originalUid1, originalUid2], rename: true },
];
const resolvedTask = await client.swapIndexes(swaps).waitTask();
// Verify the old indexes no longer exist
await expect(client.getIndex(originalUid1)).rejects.toHaveProperty(
"cause.code",
ErrorStatusCode.INDEX_NOT_FOUND,
);
await expect(client.getIndex(originalUid2)).rejects.toHaveProperty(
"cause.code",
ErrorStatusCode.INDEX_NOT_FOUND,
);
// Verify the new indexes exist with swapped content
const docIndex1 = await client.index(originalUid1).getDocument(1);
const docIndex2 = await client.index(originalUid2).getDocument(1);
expect(docIndex1.title).toEqual("index_2");
expect(docIndex2.title).toEqual("index_1");
expect(resolvedTask.type).toEqual("indexSwap");
expect(resolvedTask.details?.swaps).toEqual(swaps);
});
const resolvedTask = await client.swapIndexes(swaps).waitTask();
// Verify the indexes are accessible and content has been swapped under the same UIDs
const docIndex1 = await client.index(originalUid1).getDocument(1);
const docIndex2 = await client.index(originalUid2).getDocument(1);
expect(docIndex1.title).toEqual("index_2");
expect(docIndex2.title).toEqual("index_1");
expect(resolvedTask.type).toEqual("indexSwap");
expect(resolvedTask.details?.swaps).toEqual(swaps);
🤖 Prompt for AI Agents
In tests/client.test.ts around lines 570 to 608, the test incorrectly asserts
that the original UIDs no longer exist then tries to read documents from those
same UIDs; with rename: true the UIDs remain addressable and their contents are
swapped. Remove the two expect(...) checks that assert INDEX_NOT_FOUND for
originalUid1 and originalUid2, keep the document fetches and assertions that
docIndex1.title === "index_2" and docIndex2.title === "index_1", and update the
surrounding comments to state that the UIDs remain and their contents are
swapped rather than deleted.

Copy link
Collaborator

@Strift Strift Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ritinpaul what do you think of this?

I agree with the feedback; the intent is unclear. That being said, the tests are passing

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/utils/meilisearch-test-utils.ts (1)

19-20: DRY the repeated defaultWaitOptions into a constant

Reduces repetition and keeps future tweaks in one place.

Apply this diff for the highlighted lines, introducing a shared constant:

@@
-const config: Config = {
+const DEFAULT_WAIT_OPTIONS = { interval: 10, timeout: 60_000 };
+
+const config: Config = {
   host: HOST,
   apiKey: MASTER_KEY,
-  defaultWaitOptions: { interval: 10, timeout: 60_000 },
+  defaultWaitOptions: DEFAULT_WAIT_OPTIONS,
 };
@@
 const masterClient = new MeiliSearch({
   host: HOST,
   apiKey: MASTER_KEY,
-  defaultWaitOptions: { interval: 10, timeout: 60_000 },
+  defaultWaitOptions: DEFAULT_WAIT_OPTIONS,
 });
@@
 const anonymousClient = new MeiliSearch({
   host: HOST,
-  defaultWaitOptions: { interval: 10, timeout: 60_000 },
+  defaultWaitOptions: DEFAULT_WAIT_OPTIONS,
 });
@@
     const searchClient = new MeiliSearch({
       host: HOST,
       apiKey: searchKey,
-      defaultWaitOptions: { interval: 10, timeout: 60_000 },
+      defaultWaitOptions: DEFAULT_WAIT_OPTIONS,
     });
@@
     const adminClient = new MeiliSearch({
       host: HOST,
       apiKey: adminKey,
-      defaultWaitOptions: { interval: 10, timeout: 60_000 },
+      defaultWaitOptions: DEFAULT_WAIT_OPTIONS,
     });

Optionally also use the constant for the "No" permission client to keep behavior uniform.

Also applies to: 28-29, 33-34, 73-74, 84-85

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ae56b3 and c708d5c.

📒 Files selected for processing (6)
  • package.json (1 hunks)
  • src/types/types.ts (2 hunks)
  • tests/client.test.ts (1 hunks)
  • tests/get_search.test.ts (0 hunks)
  • tests/index.test.ts (1 hunks)
  • tests/utils/meilisearch-test-utils.ts (4 hunks)
💤 Files with no reviewable changes (1)
  • tests/get_search.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/client.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
tests/index.test.ts (2)
tests/utils/meilisearch-test-utils.ts (1)
  • getClient (369-369)
src/types/types.ts (2)
  • ErrorStatusCode (863-1223)
  • ErrorStatusCode (1225-1226)
🔇 Additional comments (3)
package.json (1)

46-46: Longer Vitest timeouts for hooks/tests: LGTM

This should reduce flakiness for rename/swap tests.

tests/utils/meilisearch-test-utils.ts (1)

19-20: Adding defaultWaitOptions with a 60s timeout: LGTM

Consistent wait behavior across clients improves test reliability.

Also applies to: 28-29, 33-34, 73-74, 84-85

tests/index.test.ts (1)

295-314: Rename test via update: LGTM

Covers happy path: create → rename → verify old uid 404 and new uid exists.

@Ritinpaul
Copy link
Author

Hi @Strift , thanks for the review. I've addressed the failing tests.
Fixed: swap-with-rename test now validates task details (version-safe)
-Restored rename via PATCH using uid on IndexOptions
-Kept queryVector checks optional to avoid version skew
-Stabilized integration timeouts (tests/utils + Vitest)
I ran the full suite locally against a running Meilisearch; all tests pass. Please let me know if you want stricter queryVector assertions when CI is confirmed on 1.18, and I’ll add them back. Happy to make any further tweaks!

@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.83%. Comparing base (282a719) to head (7a0ac20).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2020   +/-   ##
=======================================
  Coverage   98.83%   98.83%           
=======================================
  Files          18       18           
  Lines        1547     1547           
  Branches      334      334           
=======================================
  Hits         1529     1529           
  Misses         18       18           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Strift Strift force-pushed the feature/meilisearch-1.18-support branch from c708d5c to 7a0ac20 Compare December 7, 2025 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.18.0] Add queryVector to search responses and support index renaming

2 participants