diff --git a/mem0-ts/src/client/mem0.ts b/mem0-ts/src/client/mem0.ts index a9b6cd15e..915ef64d6 100644 --- a/mem0-ts/src/client/mem0.ts +++ b/mem0-ts/src/client/mem0.ts @@ -280,7 +280,7 @@ export default class MemoryClient { async search( query: string, options?: SearchMemoryOptions, - ): Promise> { + ): Promise<{ results: Array }> { if (this.telemetryId === "") await this.ping(); const payloadKeys = Object.keys(options || {}); this._captureEvent("search", [payloadKeys]); @@ -298,8 +298,7 @@ export default class MemoryClient { body: JSON.stringify(payload), }, ); - // Unwrap v1.1 format: { results: [...] } → [...] - return Array.isArray(response) ? response : (response?.results ?? response); + return response; } async delete(memoryId: string): Promise<{ message: string }> { diff --git a/mem0-ts/src/client/tests/integration/helpers.ts b/mem0-ts/src/client/tests/integration/helpers.ts index e873b66b6..8afd9df8d 100644 --- a/mem0-ts/src/client/tests/integration/helpers.ts +++ b/mem0-ts/src/client/tests/integration/helpers.ts @@ -92,7 +92,8 @@ export async function waitForSearchResults( maxRetries = 4, ): Promise { for (let attempt = 1; attempt <= maxRetries; attempt++) { - const results = await withRetry(() => client.search(query, options)); + const response = await withRetry(() => client.search(query, options)); + const results = response?.results ?? []; if (results.length > 0) { return results; } diff --git a/mem0-ts/src/client/tests/integration/search.test.ts b/mem0-ts/src/client/tests/integration/search.test.ts index 1f3e9cf89..3e5f3f3b7 100644 --- a/mem0-ts/src/client/tests/integration/search.test.ts +++ b/mem0-ts/src/client/tests/integration/search.test.ts @@ -108,16 +108,16 @@ describeIntegration("MemoryClient Integration — Search & History", () => { // ─── Edge cases ───────────────────────────────────────── describe("edge cases", () => { test("search for non-existent user returns empty results", async () => { - const results = await client.search("anything", { + const response = await client.search("anything", { filters: { userId: `nonexistent-user-${randomUUID()}` }, }); - expect(Array.isArray(results)).toBe(true); - expect(results.length).toBe(0); + expect(response).toHaveProperty("results"); + expect(response.results).toHaveLength(0); }); test("search with top_k param does not throw", async () => { - const results = await client.search( + const response = await client.search( "Tell me about integration test user", { filters: { userId: TEST_USER_ID }, @@ -125,7 +125,7 @@ describeIntegration("MemoryClient Integration — Search & History", () => { }, ); - expect(Array.isArray(results)).toBe(true); + expect(response).toHaveProperty("results"); }); }); });