pinecone-io / pinecone-ts-client

The official TypeScript/Node client for the Pinecone vector database
https://www.pinecone.io
Apache License 2.0
188 stars 37 forks source link

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

Closed mattgraphlan closed 3 months ago

mattgraphlan commented 1 year ago

Is this a new 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 commented 1 year ago

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;
vishwajeetraj11 commented 1 year ago

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

gbertb commented 1 year ago

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

jhamon commented 1 year ago

Sorry all for the trouble. Looking into it now.

adelowo commented 1 year ago

@jhamon any luck here?

vishwajeetraj11 commented 1 year ago
        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.

jhamon commented 1 year ago

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 commented 1 year ago

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.

Nipunwalia08 commented 1 year ago

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 aResponseor aNextResponsein all branches of your handler. null

jhamon commented 1 year ago

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

mario-oliver commented 1 year ago

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

jhamon commented 1 year ago

@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 commented 1 year ago

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:

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

RickRyan26 commented 12 months ago

@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/@pinecone-database+pinecone@1.1.1/node_modules/@pinecone-database/pinecone/src/errors/http.ts:162:12)
    at (../../../../node_modules/.pnpm/@pinecone-database+pinecone@1.1.1/node_modules/@pinecone-database/pinecone/src/errors/handling.ts:22:30)
    at (../../../../node_modules/.pnpm/@pinecone-database+pinecone@1.1.1/node_modules/@pinecone-database/pinecone/src/errors/utils.ts:4:27)
    at (../../../../node_modules/.pnpm/@pinecone-database+pinecone@1.1.1/node_modules/@pinecone-database/pinecone/src/errors/utils.ts:4:27)
    at (../../../../node_modules/.pnpm/@pinecone-database+pinecone@1.1.1/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 commented 11 months ago

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

RickRyan26 commented 11 months ago

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

anawishnoff commented 3 months ago

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!