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

[Bug] v1 Index<T>.query throwing TypeError: Cannot read properties of undefined (reading 'text') during migration

Open mattgraphlan opened this issue 2 years ago • 16 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

I'm migrating to v1 as described in https://github.com/pinecone-io/pinecone-ts-client/blob/main/v1-migration.md#query

I can upsert after migrating just fine, but I can't query. My code is as follows:

    const namespace = ""
    const topK = 10
    const queryRequest = {
      vector: embeddings,
      topK,
      includeMetadata: true,
      includeValues: true,
    } as QueryByVectorValues;
    try {
      // Query the index with the defined request
      const ns = index.namespace(namespace);
      const queryResult = await ns.query(queryRequest);
      return queryResult.matches || [];
    } catch (e) {
      console.error("Error querying embeddings: ", e, (e as Error).stack);
      throw new Error(`Error querying embeddings: ${e}`);
    }

I have verified that there are actually embeddings (RecordValues).

The stack trace is a bit unhelpful:

TypeError: Cannot read properties of undefined (reading 'text')
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:136:40)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:107:23)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:48:20)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:26:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:8:12)
    at extractMessage (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:129:12)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:178:76)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:48:20)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:26:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:8:12)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:171:36)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:151:25)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)

Any ideas?

Expected Behavior

No error to be thrown by ns.query, or, a helpful error message or stack trace.

Steps To Reproduce

See current behavior code.

Relevant log output

No response

Environment

- **OS**: Mac OS 13.5.2 (22G91)
- **Language version**: TypeScript, Nextjs 13
- **Pinecone client version**: 1.0.1

Additional Context

No response

mattgraphlan avatar Sep 19 '23 17:09 mattgraphlan

FWIW, this works in place of ns.query above:

    const url = `https://${process.env.PINECONE_HOST!}/query`;

    const res = await fetch(url, {
      method: "POST",
      headers: {
        accept: "application/json",
        "Content-Type": "application/json",
        "Api-Key": process.env.PINECONE_API_KEY || "unknown",
      },
      body: JSON.stringify({
        includeValues: false,
        includeMetadata: true,
        topK: topK,
        vector: embeddings,
      }),
    });
    const resJson = await res.json();
    return resJson;

mattgraphlan avatar Sep 19 '23 21:09 mattgraphlan

getting the same error? the above solution didn't work for me.

vishwajeetraj11 avatar Sep 20 '23 20:09 vishwajeetraj11

I'm getting the same error as well. Using the config laid out from the read me

gbertb avatar Sep 21 '23 05:09 gbertb

Sorry all for the trouble. Looking into it now.

jhamon avatar Sep 21 '23 16:09 jhamon

@jhamon any luck here?

adelowo avatar Sep 23 '23 20:09 adelowo

        const url = `${process.env.PINECONE_HOST!}/query`;

        const res = await fetch(url, {
            method: "POST",
            headers: {
                accept: "application/json",
                "Content-Type": "application/json",
                "Api-Key": process.env.PINECONE_API_KEY || "unknown",
            },
            body: JSON.stringify({
                includeValues: false,
                includeMetadata: true,
                topK: <topK>,
                vector: embeddings,
                namespace: <namespace>,
            }),
        });
        const resJson = await res.json() as QueryResponse<RecordMetadata>;

This worked for me.

vishwajeetraj11 avatar Sep 25 '23 00:09 vishwajeetraj11

Is anyone seeing this error outside of a next.js context? My working theory is that the fetch implementation is missing/non-functional due to next.js stubbing out the cross-fetch polyfill we rely on. But if people are also seeing this outside the context of a next.js app, we might be dealing with multiple unrelated issues that result in similar errors.

jhamon avatar Sep 26 '23 19:09 jhamon

I think I've solved this issue in the v1.1.0 release. Please upgrade and let us know if you're still having a problem with this.

jhamon avatar Sep 28 '23 11:09 jhamon

I think I've solved this issue in the v1.1.0 release. Please upgrade and let us know if you're still having a problem with this.

Updated the package but still facing the issue image

error querying embeddings [TypeError: Cannot read properties of undefined (reading 'text')] ⨯ node_modules\next\dist\esm\server\future\route-modules\app-route\module.js (200:34) @ eval ⨯ No response is returned from route handler 'C:\Users\nipun\Documents\pdfchat\pdfchat\src\app\api\chat\route.ts'. Ensure you return a Responseor aNextResponse in all branches of your handler. null

Nipunwalia08 avatar Oct 02 '23 20:10 Nipunwalia08

@Nipunwalia08 From that stacktrace alone I'm not sure that this is a Pinecone error. Can you open a fresh issue in this repo (just to focus the discussion around your situation) and include some additional info about what you have in your src/app/api/chat/route.ts file, your next.js version, etc?

jhamon avatar Oct 02 '23 20:10 jhamon

@jhamon thanks for taking a look and fixing the issue in a new release!

Interestingly enough, I am getting this issue (with the same stack trace as OP) when upserting. I created a simple PDF from which to debug to see if any of the created vectors contained undefined metadata that would cause the reading of the text property to error out.

Just to start the conversation, would there be any resemblance between the ns.query() and the ns.upsert()'s implementation of the cross-fetch polyfill that pinecone relies on? Let me know if anything jumps out at first glance; otherwise, I will open a fresh issue with further details.

mario-oliver avatar Oct 05 '23 18:10 mario-oliver

@jhamon thanks for taking a look and fixing the issue in a new release!

Interestingly enough, I am getting this issue (with the same stack trace as OP) when upserting. I created a simple PDF from which to debug to see if any of the created vectors contained undefined metadata that would cause the reading of the text property to error out.

Just to start the conversation, would there be any resemblance between the ns.query() and the ns.upsert()'s implementation of the cross-fetch polyfill that pinecone relies on? Let me know if anything jumps out at first glance; otherwise, I will open a fresh issue with further details.

I'm wondering if there is something happening that is tied to a specific version of nextjs, since I did a lot of hands-on testing with our pinecone-vercel-starter (see the upgrade/troubleshooting saga here) where I was able to repro the issue with 1.0.1 and see it resolved in 1.1.0 after adding in some additional logic about when to use cross-fetch. That's why I closed this issue, since the original filers have not chimed in to say the problem was ongoing and I had confidence from my own testing.

The missing text() error is not related to metadata. It happens when calling extractMessage in this handleApiError error handler function. There are a couple of different error callbacks involved here, but by the time this function is executing 1) an error occurred 2) handleFetchError already checked whether the error is a FetchError (occurs when a fetch is made but no server response comes back, either due to a misconfiguration, a Pinecone outage, or other network problem affecting the request) and so 3) we expect any errors left over are ResponseError (i.e. non-200 HTTP responses). .text() is expected on ResponseError objects, but whatever is being thrown here is evidently something else that does not have this method.

It seems like there is at least one other error case not covered here (i.e. FetchError and ResponseError are not the only things that can occur). I should check rather than casting here to avoid masking the real issue.

jhamon avatar Oct 06 '23 01:10 jhamon

I just shipped a v1.1.1 release that I don't think will completely fix the problem but will hopefully result in a more useful error message than Cannot read properties of undefined (reading 'text')

If anyone experiencing this problem can share full details about your environment and dependencies (ideally a minimum reproduction case), that would be very helpful. So far I have not been able to reproduce the issue in our sample projects and integration tests.

Specifically it would help me to know:

  • Where are you running this when you see the error? On local, in Vercel edge runtime, or elsewhere (please specify: AWS lambda, etc)?
  • What dependencies does your project have in project.json?

I appreciate everyone's patience as we work through this.

jhamon avatar Oct 10 '23 16:10 jhamon

@jhamon Hello again,

I'm using Sveltekit so the problem is very likely NodeJS/Vercel related, not NextJS.

Pre v1.1.1 the titled error is thrown when using Vercel Serverless or Edge; both fail.

Once updated to v1.1.1 the new error is as follows:

error code: 525 Status: 525. (Probably a failed SSL Handshake)

error:  PineconeUnmappedHttpError: An unexpected error occured while calling the https://rs-6d43a5d.svc.northamerica-northeast1-gcp.pinecone.io/query endpoint.  error code: 525 Status: 525.
    at (../../../../node_modules/.pnpm/@[email protected]/node_modules/@pinecone-database/pinecone/src/errors/http.ts:162:12)
    at (../../../../node_modules/.pnpm/@[email protected]/node_modules/@pinecone-database/pinecone/src/errors/handling.ts:22:30)
    at (../../../../node_modules/.pnpm/@[email protected]/node_modules/@pinecone-database/pinecone/src/errors/utils.ts:4:27)
    at (../../../../node_modules/.pnpm/@[email protected]/node_modules/@pinecone-database/pinecone/src/errors/utils.ts:4:27)
    at (../../../../node_modules/.pnpm/@[email protected]/node_modules/@pinecone-database/pinecone/src/errors/utils.ts:4:27) {
  name: 'PineconeUnmappedHttpError',
  cause: undefined
}

Thank you and let me know if theres anything I can test to help resolve this.

RickRyan26 avatar Nov 20 '23 02:11 RickRyan26

@jhamon Any update/thoughts on this? Not being able to use Vercel is a critical hit

RickRyan26 avatar Nov 27 '23 19:11 RickRyan26

Can we please have a progress update here? I need to know if there's anything I can do to help or if Pinecone is abandoning vercel. If so I'll need to sprint to pgvector to meet my teams release date because currently every single npm version of pincone is erroring out. Thank you

RickRyan26 avatar Nov 30 '23 03:11 RickRyan26

As this issue is almost a year old, I'll go ahead and close this as stale. However please feel free to reopen or file a new issue if you're still having trouble here - thank you!

anawishnoff avatar Aug 09 '24 14:08 anawishnoff