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
    • Support renaming an index via the update method; also enabled swapping two indexes with an optional rename.
    • Search responses may include a queryVector field when relevant.
    • Index options now accept an optional uid field, simplifying index configuration and renaming flows.
  • Documentation
    • Added a code sample demonstrating how to rename an index.

@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?

Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Adds index renaming support and related examples/tests: updateIndex now accepts indexUid for renaming, swap-indexes supports rename operations, types gain optional uid in IndexOptions and queryVector in SearchResponse, tests cover rename flows, wait timeouts are configured in utils, and test runner timeouts are increased.

Changes

Cohort / File(s) Summary
Code samples
\.code-samples.meilisearch.yaml
Adds rename_an_index_1 example showing updateIndex with new indexUid to rename an index.
Types
src/types/types.ts
Adds optional uid to IndexOptions; adds optional queryVector to SearchResponse.
Tests — rename behavior
tests/index.test.ts, tests/client.test.ts
New tests for renaming via updateIndex and via swap-indexes with rename: true; asserts task type and swap details.
Tests — search and misc
tests/get_search.test.ts
Removes a non-functional comment; no logic change.
Test utilities and config
tests/utils/meilisearch-test-utils.ts, package.json
Sets defaultWaitOptions timeout (60s); increases Vitest hook/test timeouts to 120s.

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 (type: indexUpdate/rename)
  SDK-->>App: Task info
  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 (type: indexSwap)
  SDK-->>App: Task info
  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

Possibly related PRs

  • Fix index swaps types #2000 — Adds rename flag to IndexSwap type and updates tests; aligns with this PR’s swap-indexes rename support.

Suggested labels

maintenance

Suggested reviewers

  • curquiza
  • flevi29

Poem

In burrows of code, I twitch my nose,
Rename an index—watch how it goes.
Swap or patch, the tasks align,
queryVector hums, results look fine.
With longer waits and tests that gleam,
I thump approval—ship this dream! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The implemented changes cover index renaming in both update and swap methods, add a code sample for renaming, and modify types to include queryVector, but there is no evidence of search response logic or tests to actually return or validate the queryVector field as required by issue #2013. Please implement and test the search response handling of the queryVector field when retrieveVectors is used, including adding a test case to validate that responses include this field as specified in linked issue #2013.
Out of Scope Changes Check ⚠️ Warning Several modifications such as removing a comment in tests/get_search.test.ts, updating Vitest timeouts in package.json, and adding default timeout settings in test utilities do not relate to the objectives of supporting queryVector or index renaming and appear outside the scope of linked issue #2013. Consider separating test framework configuration changes and comment cleanups into a dedicated pull request or clearly justify their necessity in this feature update to keep this PR focused on the v1.18.0 support objectives.
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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title succinctly describes the addition of Meilisearch v1.18.0 support and highlights both the introduction of the queryVector field and index renaming features, matching the main changes in the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 608
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!

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 (4f7c885) to head (c708d5c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2020   +/-   ##
=======================================
  Coverage   98.83%   98.83%           
=======================================
  Files          18       18           
  Lines        1549     1549           
  Branches      334      334           
=======================================
  Hits         1531     1531           
  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.

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