Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: this.agent.request is not a function #28

Open
mrturck opened this issue Sep 9, 2024 · 4 comments
Open

Error: this.agent.request is not a function #28

mrturck opened this issue Sep 9, 2024 · 4 comments

Comments

@mrturck
Copy link

mrturck commented Sep 9, 2024

Hello I am getting this error when using the Typescript SDK, full error below

Error processing source: 174 |     }
175 | }
176 | /** An error class for errors returned by the turbopuffer API. */
177 | class TurbopufferError extends Error {
178 |     constructor(error, { status, cause }) {
179 |         super(error, { cause: cause });
              ^
error: fetch failed: this.agent.request is not a function. (In 'this.agent.request({
            origin: this.origin,
            path,
            method,
            headers,
            body: requestBody
          })', 'this.agent.request' is undefined)
      at new TurbopufferError (/Users/mturck/wxr/worker/node_modules/@turbopuffer/turbopuffer/dist/httpClient.js:179:9)
      at /Users/mturck/wxr/worker/node_modules/@turbopuffer/turbopuffer/dist/httpClient.js:109:33

86 |         let response_start;
87 |         for (let attempt = 0; attempt < maxAttempts; attempt++) {
88 |             error = null;
89 |             request_start = performance.now();
90 |             try {
91 |                 response = await this.agent.request({

Details:

  • Running on local machine in Node/express environment
  • Following the code on https://turbopuffer.com/docs/quickstart with my own embeddings
  • Embeddings created with OpenAI (256 dims), a few small attributes for each embedding)
@pushrax
Copy link
Member

pushrax commented Sep 9, 2024

Can you check your package.lock file to see which version of the undici dependency was installed? As far as I know this isn't a new API in undici, but good to double check that.

@mrturck
Copy link
Author

mrturck commented Sep 9, 2024

Using bun, but here's what bun.lockb has:

"@turbopuffer/turbopuffer@^0.5.10": 
  version "0.5.10"
  resolved "https://registry.npmjs.org/@turbopuffer/turbopuffer/-/turbopuffer-0.5.10.tgz"
  integrity sha512-tQgouaKZPEMSf1y1p6lksmgRZ+Toj248AkPxiCdsZNoHVDWVTZgXHLet9cie4cz4oAaaVE0NWkoMyO0KafFuRA==
  dependencies: 
    pako "^2.1.0"
    undici "^6.19.8"

@pushrax
Copy link
Member

pushrax commented Sep 9, 2024

Got it. The SDK definitely works in node, but I was able to reproduce the issue in bun.

It looks like bun is trying to polyfill undici in their environment, but it only has partial support. For example, they implemented undici.request in oven-sh/bun#2136 but only on the module level, not on the Agent/Dispatcher.

The reason we use undici.Agent.request is that this allows fine tuned configuration of the connection pool and request options, and in our customer's large scale node deployments we've been able to achieve a significant performance improvement over both node's built in fetch and undici.fetch

I'm guessing that bun's fetch implementation is just a lot better than node's. This issue boils down to just using fetch in non-node environments #20

@pushrax
Copy link
Member

pushrax commented Sep 9, 2024

By the way, the official stance of bun is to be compatible directly with node https://twitter.com/jarredsumner/status/1700497869160268155

It looks like other libraries are using undici.Pool.request, which is also unimplemented NomicFoundation/hardhat#4383 oven-sh/bun#7920, and it's an open issue to fix in bun.

But we will work around it in the turbopuffer client anyway, as we want to support all JS environments, not just node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants