pinecone-ts-client icon indicating copy to clipboard operation
pinecone-ts-client copied to clipboard

[Bug] Breaking change for Bun runtime between v1.0.1 and v1.1.1

Open erhant opened this issue 2 years ago • 9 comments

Is this a new bug?

  • [X] I believe this is a new bug
  • [X] I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

Consider the following code:

const { Pinecone } = require("@pinecone-database/pinecone");
const apiKey = "your-api-key";
const environment = "your-env";
const indexName = "your-index";

async function main() {
  const pinecone = new Pinecone({
    apiKey,
    environment,
  });
  await pinecone.describeIndex(indexName);
  const index = pinecone.index(indexName);

  // some random query vector
  const arr = Array.from({ length: 1536 }, () => Math.random());

  await index.query({
    vector: arr,
    topK: 50,
    includeValues: true, // it is important that this is `true`!
    includeMetadata: true,
  });
}

main().then(() => process.exit(0));

When we run this script with node index.js we have no problems. However, when we run it with bun index.js it throws an error:

❯ bun index.js
499 |             var _a;
500 |             return __generator(this, function (_b) {
501 |                 switch (_b.label) {
502 |                     case 0:
503 |                         _a = this.transformer;
504 |                         return [4 /*yield*/, this.raw.json()];
                                                 ^
SyntaxError: Unexpected end of JSON input
      at /Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/runtime.js:504:45
      at step (/Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/runtime.js:72:17)
      at /Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/runtime.js:53:52
      at /Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/runtime.js:47:8
      at new Promise (:1:20)
      at /Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/runtime.js:43:11
      at /Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/runtime.js:498:15
      at /Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/apis/VectorOperationsApi.js:405:45
      at step (/Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/apis/VectorOperationsApi.js:84:17)

Expected Behavior

It should not throw an error when working with Bun.

To go further, I have edited the code at the point of error to see exactly what is going on. Beginning at line 502 I have modified it as:

case 0:
  const t = this.raw.text();
  _a = this.transformer;
  return [4 /*yield*/, t
    .then(t => JSON.parse(t))
    .catch(e => {
      t.then(t => console.log({obj: t, type: typeof t}))
      throw e
    })
  ];

which should do the same thing as this.raw.json() but allow us to see the body before throwing an error. This way, we see that with Bun we print the following within the catch function:

❯ bun index.js
{
  obj: "",
  type: "string"
}
502 |                     case 0:
503 |                         const t = this.raw.text();
504 |                         _a = this.transformer;
505 |                         return [4 /*yield*/, t
506 |                           .then(t => JSON.parse(t))
507 |                           .catch(e => {
                                          ^
SyntaxError: JSON Parse error: Unexpected EOF
      at /Users/erhant/fb/tmp/pinecone-bug/node_modules/@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/runtime.js:507:38

In other words, something causes the body to be empty string, which of course can't be parsed to JSON.

This issue does not exist for pinecone client v.1.0.1.

Steps To Reproduce

  1. Install pinecone package (v.1.1.x) and create a file with the snippet given above.
  2. Run it with node and confirm it works.
  3. Run it with bun and confirm it throws an error.
  4. Optionally, install pinecone package (v.1.0.x) and see that it works for both.

It seems to be important that includeValues is set to be true.

Relevant log output

No response

Environment

- **OS**: macOS Ventura 13.0
- **Language version**: Bun: 1.0.4 and Node: 20.5.0
- **Pinecone client version**: 1.1.1

Additional Context

Here is a shortcut to Bun issues page: https://github.com/oven-sh/bun/issues

They have quite a lot of issues, but if we can pinpoint what causes the issue with Pinecone we can link to a relevant issue within Bun. Perhaps a different method was used to parse the request body between v1.0.1 ~ v.1.1.1 and Bun does not support the latter?

Mentioning my teammate @anilaltuner to also notify him & for his help on finding the bug.

erhant avatar Oct 17 '23 10:10 erhant

Thank you for the detailed bug report. I will try to look at this soon and add some bun integration tests so this doesn't happen again.

jhamon avatar Oct 19 '23 18:10 jhamon

Hello, are there any updates on this?

erhant avatar Nov 30 '23 06:11 erhant

any updates on this?

knajjars avatar Jan 06 '24 18:01 knajjars

Still broken :'(

noahgsolomon avatar Jun 12 '24 12:06 noahgsolomon

Confirming this is still broken here as well.

jimmyceroneii avatar Aug 05 '24 00:08 jimmyceroneii

gg still broken on 1.1.18

andrewdoro avatar Aug 19 '24 13:08 andrewdoro

+1

ryanleecode avatar Sep 07 '24 05:09 ryanleecode

Still broken

Any updates or workarounds?

ansh avatar Nov 30 '24 00:11 ansh

Still broken

Any updates or workarounds?

My workaround for the time being is to use Cohere (or Elastic Search): https://cohere.com

jimmyceroneii avatar Dec 01 '24 02:12 jimmyceroneii